Browse Source

Put moodle_course choices in Evento model instead of admin form

stable/2.1
Sesostris Vieira 9 years ago
parent
commit
a5a5cf60d6
  1. 17
      sigi/apps/eventos/admin.py
  2. 20
      sigi/apps/eventos/migrations/0002_auto_20151016_1449.py
  3. 29
      sigi/apps/eventos/models.py

17
sigi/apps/eventos/admin.py

@ -22,18 +22,6 @@ from django.contrib import admin
from django import forms
from django.utils.translation import ugettext as _
from sigi.apps.eventos.models import TipoEvento, Funcao, Evento, Equipe, Convite
from sigi.apps.utils.moodle_ws_api import get_courses
def get_course_choices():
result = [(None, u'---------')]
try:
courses = get_courses(sort_order='categorysortorder', idnumber__startswith='evento')
result = result + [(c['id'], c['fullname']) for c in courses]
except Exception as e:
result.append((None, _(u"Erro ao acessar o saberes: '%s'" % (e.message,))))
return result
class EventoAdminForm(forms.ModelForm):
class Meta:
@ -43,11 +31,6 @@ class EventoAdminForm(forms.ModelForm):
'data_cancelamento', 'motivo_cancelamento', 'curso_moodle_id',
)
def __init__(self, *args, **kwargs):
super(EventoAdminForm, self).__init__(*args, **kwargs)
self.fields['curso_moodle_id'] = forms.ChoiceField(choices=get_course_choices(),
label=_(u"Curso Saberes"))
def clean(self):
cleaned_data = super(EventoAdminForm, self).clean()
data_inicio = cleaned_data.get("data_inicio")

20
sigi/apps/eventos/migrations/0002_auto_20151016_1449.py

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('eventos', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='evento',
name='curso_moodle_id',
field=models.IntegerField(blank=True, null=True, verbose_name='Curso saberes', choices=[(None, '---------'), (None, "Erro ao acessar o saberes: 'invalidtoken (moodle_exception): Token inv\xe1lido - token n\xe3o encontrado'")]),
preserve_default=True,
),
]

29
sigi/apps/eventos/models.py

@ -19,12 +19,12 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
from django.db import models
from django.db.models import Q
from django.utils.functional import lazy
from django.utils.translation import ugettext as _
from sigi.apps.casas.models import CasaLegislativa
from sigi.apps.contatos.models import Municipio
from sigi.apps.servidores.models import Servidor
from sigi.apps.mdl.models import Course
from sigi.apps.utils.moodle_ws_api import get_courses
from django.core.exceptions import ValidationError
class TipoEvento(models.Model):
@ -46,20 +46,34 @@ class Evento(models.Model):
('C', _(u"Cancelado"))
)
def get_course_choices():
result = [(None, u'---------')]
try:
courses = get_courses(sort_order='categorysortorder', idnumber__startswith='evento')
result = result + [(c['id'], c['fullname']) for c in courses]
except Exception as e:
result.append((None, _(u"Erro ao acessar o saberes: '%s'" % (e.message,))))
return result
tipo_evento = models.ForeignKey(TipoEvento)
nome = models.CharField(_(u"Nome do evento"), max_length=100)
descricao = models.TextField(_(u"Descrição do evento"))
solicitante = models.CharField(_(u"Solicitante"), max_length=100)
data_inicio = models.DateField(_(u"Data de início"))
data_termino = models.DateField(_(u"Data de término"))
casa_anfitria = models.ForeignKey(CasaLegislativa, verbose_name=_(u"Casa anfitriã"), blank=True, null=True)
casa_anfitria = models.ForeignKey(CasaLegislativa, verbose_name=_(u"Casa anfitriã"), blank=True,
null=True)
municipio = models.ForeignKey(Municipio)
local = models.TextField(_(u"Local do evento"), blank=True)
publico_alvo = models.TextField(_(u"Público alvo"), blank=True)
status = models.CharField(_(u"Status"), max_length=1, choices=STATUS_CHOICES)
data_cancelamento = models.DateField(_(u"Data de cancelamento"), blank=True, null=True)
motivo_cancelamento = models.TextField(_(u"Motivo do cancelamento"), blank=True)
curso_moodle_id = models.IntegerField(_(u"Curso saberes"), blank=True, null=True)
curso_moodle_id = models.IntegerField(_(u"Curso saberes"), blank=True, null=True,
choices=lazy(get_course_choices, list)())
class Meta:
ordering = ("-data_inicio",)
@ -80,13 +94,6 @@ class Evento(models.Model):
raise ValidationError(_(u"Data de término deve ser posterior à data de início"))
return super(Evento, self).save(*args, **kwargs)
@property
def curso_moodle(self):
if self.curso_moodle_id:
return Course.objects.get(id=self.curso_moodle_id)
else:
return None
class Funcao(models.Model):
nome = models.CharField(_(u"Função na equipe de evento"), max_length=100)
descricao = models.TextField(_(u"Descrição da função"))

Loading…
Cancel
Save