Browse Source

Temporarily access moodle by database: performance reasons

stable/2.1
Sesostris Vieira 9 years ago
parent
commit
b8385fde1c
  1. 27
      sigi/apps/eventos/models.py

27
sigi/apps/eventos/models.py

@ -26,6 +26,7 @@ from sigi.apps.contatos.models import Municipio
from sigi.apps.servidores.models import Servidor from sigi.apps.servidores.models import Servidor
from sigi.apps.utils.moodle_ws_api import get_courses from sigi.apps.utils.moodle_ws_api import get_courses
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from sigi.apps.mdl.models import Course
class TipoEvento(models.Model): class TipoEvento(models.Model):
nome = models.CharField(_(u"Nome"), max_length=100) nome = models.CharField(_(u"Nome"), max_length=100)
@ -46,18 +47,26 @@ class Evento(models.Model):
('C', _(u"Cancelado")) ('C', _(u"Cancelado"))
) )
def get_course_choices(): # def get_course_choices():
result = [(None, u'---------')] # result = [(None, u'---------')]
#
try: # try:
courses = get_courses(sort_order='categorysortorder', idnumber__startswith='evento') # courses = get_courses(sort_order='categorysortorder', idnumber__startswith='evento')
result = result + [(c['id'], c['fullname']) for c in courses] # result = result + [(c['id'], c['fullname']) for c in courses]
except Exception as e: # except Exception as e:
result.append((None, _(u"Erro ao acessar o saberes: '%s'" % (e.message,)))) # result.append((None, _(u"Erro ao acessar o saberes: '%s'" % (e.message,))))
#
# return result
def get_course_choices():
from django.apps import apps
if apps.models_ready:
courses = Course.objects.filter(idnumber__startswith='evento')
else:
courses = []
result = [(None, u'---------')] + [(c.id, c.fullname) for c in courses]
return result return result
tipo_evento = models.ForeignKey(TipoEvento) tipo_evento = models.ForeignKey(TipoEvento)
nome = models.CharField(_(u"Nome do evento"), max_length=100) nome = models.CharField(_(u"Nome do evento"), max_length=100)
descricao = models.TextField(_(u"Descrição do evento")) descricao = models.TextField(_(u"Descrição do evento"))

Loading…
Cancel
Save