mirror of https://github.com/interlegis/sigi.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
3.6 KiB
94 lines
3.6 KiB
# -*- coding: utf-8 -*-
|
|
#
|
|
# sigi.apps.eventos.admin
|
|
#
|
|
# Copyright (C) 2015 Interlegis
|
|
#
|
|
# This program is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU General Public License
|
|
# as published by the Free Software Foundation; either version 2
|
|
# of the License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program; if not, write to the Free Software
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
from django import forms
|
|
from django.contrib import admin
|
|
from django.db import models
|
|
from django.http import HttpResponseRedirect
|
|
from django.utils.translation import ugettext as _
|
|
from sigi.apps.eventos.models import (ModeloDeclaracao, Modulo, TipoEvento,
|
|
Funcao, Evento, Equipe, Convite, Anexo)
|
|
from sigi.apps.eventos.views import adicionar_eventos_carrinho
|
|
from sigi.apps.eventos.forms import EventoAdminForm
|
|
|
|
@admin.register(TipoEvento)
|
|
class TipoEventAdmin(admin.ModelAdmin):
|
|
search_fields = ('nome',)
|
|
|
|
@admin.register(Funcao)
|
|
class FuncaoAdmin(admin.ModelAdmin):
|
|
list_display = ('nome', 'descricao',)
|
|
search_fields = ('nome', 'descricao',)
|
|
|
|
@admin.register(ModeloDeclaracao)
|
|
class ModeloDeclaracaoAdmin(admin.ModelAdmin):
|
|
list_display = ('nome', 'formato')
|
|
|
|
class EquipeInline(admin.TabularInline):
|
|
model = Equipe
|
|
|
|
class ConviteInline(admin.TabularInline):
|
|
model = Convite
|
|
raw_id_fields = ('casa',)
|
|
|
|
class ModuloInline(admin.TabularInline):
|
|
model = Modulo
|
|
|
|
class AnexoInline(admin.TabularInline):
|
|
model = Anexo
|
|
exclude = ('data_pub',)
|
|
|
|
@admin.register(Evento)
|
|
class EventoAdmin(admin.ModelAdmin):
|
|
form = EventoAdminForm
|
|
date_hierarchy = 'data_inicio'
|
|
list_display = ('nome', 'tipo_evento', 'status', 'data_inicio',
|
|
'data_termino', 'municipio', 'solicitante',
|
|
'total_participantes',)
|
|
list_filter = ('status', 'tipo_evento', 'tipo_evento__categoria', 'virtual',
|
|
'municipio__uf', 'solicitante')
|
|
raw_id_fields = ('casa_anfitria', 'municipio',)
|
|
search_fields = ('nome', 'tipo_evento__nome', 'casa_anfitria__search_text',
|
|
'municipio__search_text', 'solicitante')
|
|
inlines = (EquipeInline, ConviteInline, ModuloInline, AnexoInline)
|
|
actions = ['adicionar_eventos', ]
|
|
|
|
def adicionar_eventos(self, request, queryset):
|
|
if 'carrinho_eventos' in request.session:
|
|
q1 = len(request.session['carrinho_eventos'])
|
|
else:
|
|
q1 = 0
|
|
response = adicionar_eventos_carrinho(request, queryset=queryset)
|
|
q2 = len(request.session['carrinho_eventos'])
|
|
quant = q2 - q1
|
|
if quant:
|
|
self.message_user(request, str(q2 - q1) + " " +
|
|
_(u"Eventos adicionados no carrinho"))
|
|
else:
|
|
self.message_user(request, _(u"Os Eventos selecionados "
|
|
u"já foram adicionados anteriormente"))
|
|
return HttpResponseRedirect('.')
|
|
adicionar_eventos.short_description = _(u"Armazenar eventos no carrinho "
|
|
u"para exportar")
|
|
|
|
def lookup_allowed(self, lookup, value):
|
|
return (super(EventoAdmin, self).lookup_allowed(lookup, value) or
|
|
lookup in ['tipo_evento__nome__exact',
|
|
'tipo_evento__nome__contains'])
|
|
|