X-Git-Url: https://git.llucax.com/z.facultad/75.52/sercom.git/blobdiff_plain/d47dd9949d44d12944f557b0efd80459b857ce74..a0674923171dc6dc48da9b5259b3a71f18e92f8b:/sercom/controllers.py?ds=sidebyside diff --git a/sercom/controllers.py b/sercom/controllers.py index 714869a..9f82838 100644 --- a/sercom/controllers.py +++ b/sercom/controllers.py @@ -1,10 +1,13 @@ -# vim: set et sw=4 sts=4 encoding=utf-8 : +# vim: set et sw=4 sts=4 encoding=utf-8 foldmethod=marker : -from turbogears import controllers, expose, view -from turbogears import widgets as w, validators +from turbogears import controllers, expose, view, url +from turbogears import widgets as W, validators as V from turbogears import identity, redirect from cherrypy import request, response -from model import * +from turbogears.toolbox.catwalk import CatWalk +import model +from model import InstanciaDeEntrega, Correccion, AND, DateTimeCol, Entrega, Grupo, AlumnoInscripto +from sqlobject import * # from sercom import json from subcontrollers import * @@ -12,14 +15,54 @@ from subcontrollers import * import logging log = logging.getLogger("sercom.controllers") +class LoginForm(W.TableForm): + class Fields(W.WidgetsList): + login_user = W.TextField(label=_(u'Usuario'), + validator=V.NotEmpty()) + login_password = W.PasswordField(label=_(u'Contraseña'), + validator=V.NotEmpty()) + fields = Fields() + javascript = [W.JSSource("MochiKit.DOM.focusOnLoad('form_login_user');")] + submit = W.SubmitButton(name='login_submit') + submit_text = _(u'Ingresar') + class Root(controllers.RootController): - @expose(template='.templates.welcome') - @identity.require(identity.has_permission('entregar')) + @expose() def index(self): - import time - log.debug('Happy TurboGears Controller Responding For Duty') - return dict(now=time.ctime()) + raise redirect(url('/dashboard')) + + @expose(template='.templates.welcome') + @identity.require(identity.not_anonymous()) + def dashboard(self): + now = DateTimeCol.now() + if 'admin' in identity.current.permissions: + # TODO : Fijar el curso !! + correcciones = Correccion.selectBy(corrector=identity.current.user, + corregido=None).count() + instancias = list(InstanciaDeEntrega.select( + AND(InstanciaDeEntrega.q.inicio <= now, + InstanciaDeEntrega.q.fin > now)) + .orderBy(InstanciaDeEntrega.q.fin)) + return dict(a_corregir=correcciones, + instancias_activas=instancias, now=now) + + if 'entregar' in identity.current.permissions: + # Proximas instancias de entrega + instancias = list(InstanciaDeEntrega.select( + AND(InstanciaDeEntrega.q.inicio <= now, + InstanciaDeEntrega.q.fin > now)).orderBy(InstanciaDeEntrega.q.fin)) + # Ultimas N entregas realizadas + # Grupos en los que el usuario formo parte + m = [i.grupo.id for i in Grupo.selectByAlumno(identity.current.user)] + try: + entregador = AlumnoInscripto.selectByAlumno(identity.current.user) + m.append(entregador.id) + except: + pass + entregas = list(Entrega.select(IN(Entrega.q.entregadorID, m))[:5]) + return dict(instancias_activas=instancias, now=now, entregas=entregas) + return dict() @expose(template='.templates.login') def login(self, forward_url=None, previous_url=None, tg_errors=None, *args, @@ -46,24 +89,13 @@ class Root(controllers.RootController): msg = _(u'Por favor ingrese.') forward_url = request.headers.get('Referer', '/') - fields = [ - w.TextField(name='login_user', label=_(u'Usuario'), - validator=validators.NotEmpty()), - w.PasswordField(name='login_password', label=_(u'Contraseña'), - validator=validators.NotEmpty()) - ] + fields = list(LoginForm.fields) if forward_url: - fields.append(w.HiddenField(name='forward_url')) - fields.extend([w.HiddenField(name=name) for name in request.params + fields.append(W.HiddenField(name='forward_url')) + fields.extend([W.HiddenField(name=name) for name in request.params if name not in ('login_user', 'login_password', 'login_submit', 'forward_url')]) - - submit = w.SubmitButton(name='login_submit') - - login_form = w.TableForm(fields=fields, action=previous_url, - submit_text=_(u'Ingresar'), submit=submit) - login_form.javascript.append( - w.JSSource("MochiKit.DOM.focusOnLoad('form_login_user');")) + login_form = LoginForm(fields=fields, action=previous_url) values = dict(forward_url=forward_url) values.update(request.params) @@ -75,14 +107,36 @@ class Root(controllers.RootController): @expose() def logout(self): identity.current.logout() - raise redirect('/') + raise redirect(url('/')) docente = DocenteController() + grupo = GrupoController() + + alumno = AlumnoController() + enunciado = EnunciadoController() + ejercicio = EjercicioController() + caso_de_prueba = CasoDePruebaController() + curso = CursoController() + + docente_inscripto = DocenteInscriptoController() + + alumno_inscripto = AlumnoInscriptoController() + + correccion = CorreccionController() + + admin = identity.SecureObject(CatWalk(model), identity.has_permission('admin')) + + mis_entregas = MisEntregasController() + + mis_correcciones = MisCorreccionesController() + + grupo_admin = GrupoAdminController() + #{{{ Agrega summarize a namespace tg de KID def summarize(text, size, concat=True, continuation='...'): """Summarize a string if it's length is greater than a specified size. This @@ -112,8 +166,13 @@ def summarize(text, size, concat=True, continuation='...'): text = text[:size-len(continuation)] + continuation return text +def strbool(bool): + if bool: + return _(u'Sí') + return _(u'No') + def add_custom_stdvars(vars): - return vars.update(dict(summarize=summarize)) + return vars.update(dict(summarize=summarize, strbool=strbool)) view.variable_providers.append(add_custom_stdvars) #}}}