|
@ -19,10 +19,21 @@ |
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
|
|
|
|
|
|
|
from django.contrib import admin |
|
|
from django.contrib import admin |
|
|
from django.contrib.admin import register |
|
|
|
|
|
from django import forms |
|
|
from django import forms |
|
|
from django.utils.translation import ugettext as _ |
|
|
from django.utils.translation import ugettext as _ |
|
|
from sigi.apps.eventos.models import TipoEvento, Funcao, Evento, Equipe, Convite |
|
|
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 EventoAdminForm(forms.ModelForm): |
|
|
class Meta: |
|
|
class Meta: |
|
@ -31,6 +42,12 @@ class EventoAdminForm(forms.ModelForm): |
|
|
'casa_anfitria', 'municipio', 'local', 'publico_alvo', 'status', |
|
|
'casa_anfitria', 'municipio', 'local', 'publico_alvo', 'status', |
|
|
'data_cancelamento', 'motivo_cancelamento', 'curso_moodle_id', |
|
|
'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): |
|
|
def clean(self): |
|
|
cleaned_data = super(EventoAdminForm, self).clean() |
|
|
cleaned_data = super(EventoAdminForm, self).clean() |
|
|
data_inicio = cleaned_data.get("data_inicio") |
|
|
data_inicio = cleaned_data.get("data_inicio") |
|
@ -40,11 +57,11 @@ class EventoAdminForm(forms.ModelForm): |
|
|
raise forms.ValidationError(_(u"Data término deve ser posterior à data inicio"), |
|
|
raise forms.ValidationError(_(u"Data término deve ser posterior à data inicio"), |
|
|
code="invalid_period" ) |
|
|
code="invalid_period" ) |
|
|
|
|
|
|
|
|
@register(TipoEvento) |
|
|
@admin.register(TipoEvento) |
|
|
class TipoEventAdmin(admin.ModelAdmin): |
|
|
class TipoEventAdmin(admin.ModelAdmin): |
|
|
search_fields = ('nome',) |
|
|
search_fields = ('nome',) |
|
|
|
|
|
|
|
|
@register(Funcao) |
|
|
@admin.register(Funcao) |
|
|
class FuncaoAdmin(admin.ModelAdmin): |
|
|
class FuncaoAdmin(admin.ModelAdmin): |
|
|
list_display = ('nome', 'descricao',) |
|
|
list_display = ('nome', 'descricao',) |
|
|
search_fields = ('nome', 'descricao',) |
|
|
search_fields = ('nome', 'descricao',) |
|
@ -56,7 +73,7 @@ class ConviteInline(admin.TabularInline): |
|
|
model = Convite |
|
|
model = Convite |
|
|
raw_id_fields = ('casa',) |
|
|
raw_id_fields = ('casa',) |
|
|
|
|
|
|
|
|
@register(Evento) |
|
|
@admin.register(Evento) |
|
|
class EventoAdmin(admin.ModelAdmin): |
|
|
class EventoAdmin(admin.ModelAdmin): |
|
|
form = EventoAdminForm |
|
|
form = EventoAdminForm |
|
|
date_hierarchy = 'data_inicio' |
|
|
date_hierarchy = 'data_inicio' |
|
|