mirror of https://github.com/interlegis/sapl.git
committed by
João Rodrigues
9 changed files with 223 additions and 14 deletions
@ -0,0 +1,6 @@ |
|||||
|
{% load i18n %} |
||||
|
|
||||
|
Videoconferencia: |
||||
|
{% trans 'Videoconferência' %}: |
||||
|
- titulo finalizada |
||||
|
- descricao |
||||
@ -0,0 +1,9 @@ |
|||||
|
{% extends "crud/detail.html" %} |
||||
|
{% load i18n common_tags %} |
||||
|
{% load render_bundle from webpack_loader %} |
||||
|
|
||||
|
|
||||
|
{% block detail_content %} |
||||
|
{{block.super}} |
||||
|
<a href="{% url 'sapl.videoconf:chat-session' object.pk %}"><strong>Link da sessão de vídeo</strong></a> |
||||
|
{% endblock detail_content %} |
||||
@ -0,0 +1,65 @@ |
|||||
|
import logging |
||||
|
|
||||
|
from django.forms import ModelForm |
||||
|
from django.utils.translation import ugettext_lazy as _ |
||||
|
|
||||
|
from sapl.videoconf.models import Videoconferencia |
||||
|
|
||||
|
|
||||
|
class VideoconferenciaForm(ModelForm): |
||||
|
|
||||
|
logger = logging.getLogger(__name__) |
||||
|
|
||||
|
class Meta: |
||||
|
model = Videoconferencia |
||||
|
fields = ['chat_id', 'descricao'] |
||||
|
|
||||
|
|
||||
|
# class AutoriaNormaForm(ModelForm): |
||||
|
# |
||||
|
# tipo_autor = ModelChoiceField(label=_('Tipo Autor'), |
||||
|
# required=False, |
||||
|
# queryset=TipoAutor.objects.all(), |
||||
|
# empty_label=_('Selecione'), ) |
||||
|
# |
||||
|
# data_relativa = forms.DateField( |
||||
|
# widget=forms.HiddenInput(), required=False) |
||||
|
# |
||||
|
# logger = logging.getLogger(__name__) |
||||
|
# |
||||
|
# def __init__(self, *args, **kwargs): |
||||
|
# super(AutoriaNormaForm, self).__init__(*args, **kwargs) |
||||
|
# |
||||
|
# row1 = to_row([('tipo_autor', 4), |
||||
|
# ('autor', 4), |
||||
|
# ('primeiro_autor', 4)]) |
||||
|
# |
||||
|
# self.helper = SaplFormHelper() |
||||
|
# self.helper.layout = Layout( |
||||
|
# Fieldset(_('Autoria'), |
||||
|
# row1, 'data_relativa', form_actions(label='Salvar'))) |
||||
|
# |
||||
|
# if not kwargs['instance']: |
||||
|
# self.fields['autor'].choices = [] |
||||
|
# |
||||
|
# class Meta: |
||||
|
# model = AutoriaNorma |
||||
|
# fields = ['tipo_autor', 'autor', 'primeiro_autor', 'data_relativa'] |
||||
|
# |
||||
|
# def clean(self): |
||||
|
# cd = super(AutoriaNormaForm, self).clean() |
||||
|
# |
||||
|
# if not self.is_valid(): |
||||
|
# return self.cleaned_data |
||||
|
# |
||||
|
# autorias = AutoriaNorma.objects.filter( |
||||
|
# norma=self.instance.norma, autor=cd['autor']) |
||||
|
# pk = self.instance.pk |
||||
|
# |
||||
|
# if ((not pk and autorias.exists()) or |
||||
|
# (pk and autorias.exclude(pk=pk).exists())): |
||||
|
# self.logger.error( |
||||
|
# "Autor ({}) já foi cadastrado.".format(cd['autor'])) |
||||
|
# raise ValidationError(_('Esse Autor já foi cadastrado.')) |
||||
|
# |
||||
|
# return cd |
||||
@ -0,0 +1,38 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# Generated by Django 1.11.29 on 2020-03-31 21:34 |
||||
|
from __future__ import unicode_literals |
||||
|
|
||||
|
from django.conf import settings |
||||
|
from django.db import migrations, models |
||||
|
import django.db.models.deletion |
||||
|
import sapl.videoconf.models |
||||
|
|
||||
|
|
||||
|
class Migration(migrations.Migration): |
||||
|
|
||||
|
initial = True |
||||
|
|
||||
|
dependencies = [ |
||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL), |
||||
|
] |
||||
|
|
||||
|
operations = [ |
||||
|
migrations.CreateModel( |
||||
|
name='Videoconferencia', |
||||
|
fields=[ |
||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
||||
|
('chat_id', models.CharField(default=sapl.videoconf.models.gen_session_id, max_length=100, verbose_name='Chat ID')), |
||||
|
('titulo', models.CharField(max_length=100, verbose_name='Título')), |
||||
|
('descricao', models.CharField(blank=True, max_length=256, verbose_name='Descrição')), |
||||
|
('inicio', models.DateTimeField(auto_now=True, verbose_name='Data e Hora de Início')), |
||||
|
('termino', models.DateTimeField(blank=True, null=True, verbose_name='Data e Hora de Término')), |
||||
|
('finalizada', models.BooleanField(default=False, verbose_name='Finalizada?')), |
||||
|
('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='Criado por')), |
||||
|
], |
||||
|
options={ |
||||
|
'verbose_name': 'Videoconferência', |
||||
|
'verbose_name_plural': 'Videoconferências', |
||||
|
'ordering': ['chat_id', 'descricao'], |
||||
|
}, |
||||
|
), |
||||
|
] |
||||
@ -1,3 +1,41 @@ |
|||||
|
from django.utils import timezone |
||||
|
|
||||
from django.db import models |
from django.db import models |
||||
|
from django.utils.translation import ugettext_lazy as _ |
||||
|
|
||||
|
from sapl.utils import get_settings_auth_user_model |
||||
|
|
||||
|
|
||||
|
def gen_session_id(): |
||||
|
|
||||
|
from random import choice |
||||
|
return ''.join([str(choice(range(10))) for _ in range(25)]) |
||||
|
|
||||
|
|
||||
|
class Videoconferencia(models.Model): |
||||
|
|
||||
|
chat_id = models.CharField(max_length=100, |
||||
|
default=gen_session_id, |
||||
|
verbose_name=_('Chat ID')) |
||||
|
titulo = models.CharField(max_length=100, verbose_name=_('Título')) |
||||
|
descricao = models.CharField(max_length=256, blank=True, |
||||
|
verbose_name=_('Descrição')) |
||||
|
inicio = models.DateTimeField(auto_now=timezone.now, verbose_name=_('Data e Hora de Início')) |
||||
|
|
||||
|
#TODO: preencher quando usuário selecionar a opção 'finalizada' |
||||
|
termino = models.DateTimeField(blank=True, null=True, |
||||
|
verbose_name=_('Data e Hora de Término')) |
||||
|
finalizada = models.BooleanField(default=False, verbose_name=_('Finalizada?')) |
||||
|
|
||||
|
#TODO: obrigatório com preenchimento automatico |
||||
|
created_by = models.ForeignKey(get_settings_auth_user_model(), |
||||
|
blank=True, null=True, |
||||
|
verbose_name=_('Criado por')) |
||||
|
|
||||
|
class Meta: |
||||
|
verbose_name = _('Videoconferência') |
||||
|
verbose_name_plural = _('Videoconferências') |
||||
|
ordering = ['chat_id', 'descricao'] |
||||
|
|
||||
# Create your models here. |
def __str__(self): |
||||
|
return "".format(self.chat_id) |
||||
|
|||||
@ -1,10 +1,13 @@ |
|||||
|
|
||||
from .apps import AppConfig |
from .apps import AppConfig |
||||
from .views import VideoConferenciaView |
from .views import ChatView, VideoConferenciaCrud |
||||
from django.conf.urls import url |
from django.conf.urls import include, url |
||||
|
|
||||
app_name = AppConfig.name |
app_name = AppConfig.name |
||||
|
|
||||
urlpatterns = [ |
urlpatterns = [ |
||||
url(r'^videoconf/$', VideoConferenciaView.as_view(), name='videoconferencia'), |
url(r'^videoconferencia/chat/(?P<pk>[0-9]+)$', |
||||
|
ChatView.as_view(), name='chat-session'), |
||||
|
url(r'^videoconferencia/', |
||||
|
include(VideoConferenciaCrud.get_urls()), name='videoconferencia'), |
||||
] |
] |
||||
|
|||||
@ -1,14 +1,58 @@ |
|||||
from django.shortcuts import render |
import logging |
||||
from django.views.generic import TemplateView |
|
||||
from django.contrib.auth.mixins import PermissionRequiredMixin |
from django.contrib.auth.mixins import PermissionRequiredMixin |
||||
|
from django.contrib.contenttypes.models import ContentType |
||||
|
from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist |
||||
|
from django.core.urlresolvers import reverse, reverse_lazy |
||||
|
from django.views.generic import TemplateView |
||||
|
|
||||
# Create your views here. |
from sapl.base.models import Autor |
||||
|
from sapl.crud.base import CrudAux |
||||
|
from sapl.parlamentares.models import Parlamentar |
||||
|
from sapl.videoconf.models import Videoconferencia |
||||
|
|
||||
|
VideoConferenciaCrud = CrudAux.build(Videoconferencia, 'videoconferencia') |
||||
|
|
||||
class VideoConferenciaView(PermissionRequiredMixin, TemplateView): |
|
||||
|
class ChatView(PermissionRequiredMixin, TemplateView): |
||||
template_name = "videoconf/videoconferencia.html" |
template_name = "videoconf/videoconferencia.html" |
||||
permission_required = ('sessao.add_sessao', ) |
permission_required = ('sessao.add_sessao', ) |
||||
|
logger = logging.getLogger(__name__) |
||||
|
|
||||
def get_context_data(self, **kwargs): |
def get_context_data(self, **kwargs): |
||||
context = super().get_context_data(**kwargs) |
context = super().get_context_data(**kwargs) |
||||
|
try: |
||||
|
context['object'] = Videoconferencia.objects.get(id=kwargs['pk']) |
||||
|
except ObjectDoesNotExist: |
||||
|
pass #TODO: return error |
||||
|
|
||||
|
user = self.request.user |
||||
|
content_type = ContentType.objects.get_for_model(Parlamentar) |
||||
|
try: |
||||
|
autor = user.autor |
||||
|
nome = autor.nome |
||||
|
parlamentar = None |
||||
|
if not autor.object_id or autor.content_type != content_type: |
||||
|
is_parlamentar = False |
||||
|
else: |
||||
|
try: |
||||
|
parlamentar = Parlamentar.objects.get(id=autor.object_id) |
||||
|
nome = parlamentar.nome_parlamentar |
||||
|
is_parlamentar = True |
||||
|
except ObjectDoesNotExist: |
||||
|
is_parlamentar = False |
||||
|
|
||||
|
user_data = { |
||||
|
'nome': nome, |
||||
|
'is_autor': True, |
||||
|
'is_parlamentar': is_parlamentar, |
||||
|
'parlamentar': parlamentar |
||||
|
} |
||||
|
except: |
||||
|
user_data = { |
||||
|
'nome': user.username, |
||||
|
'is_autor': False, |
||||
|
'is_parlamentar': False |
||||
|
} |
||||
|
context.update(user_data) |
||||
return context |
return context |
||||
|
|||||
Loading…
Reference in new issue