Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
(#15) Integrar cambios necesarios para el CAS
Browse files Browse the repository at this point in the history
  • Loading branch information
xiwire committed Dec 13, 2017
1 parent fddf938 commit 9254c53
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
25 changes: 25 additions & 0 deletions gestion/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from django.db import models
from django.utils import timezone
from django.utils.translation import ugettext as _
from django.dispatch import receiver
from django.db.models.signals import post_save
from django.contrib.auth.models import User, Group

from gespai import validation

Expand Down Expand Up @@ -267,3 +270,25 @@ def clean(self):

def __str__(self):
return "(0.dni_becario) - {fecha}".format(self, fecha=self.fecha_asignacion.strftime("%d/%m/%Y"))

@receiver(post_save, sender=User)
def populate_data(sender, instance, created, **kwargs):
if not created:
return
user = instance
if "alu" not in user.username:
return

correo = user.username + "@ull.edu.es"
try:
becario = Becario.objects.get(email=correo)
except Becario.DoesNotExist as e:
return
user.email = correo
user.first_name = becario.nombre
user.last_name = becario.apellido1 + " " + becario.apellido2

grupo_alumnado = Group.objects.get(name="alumnado")
user.groups.add(grupo_alumnado)

user.save()
6 changes: 3 additions & 3 deletions personal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from . import forms

def group_check_all(user):
return user.groups.filter(name="alu").exists()
return user.groups.filter(name="alumnado").exists()

@method_decorator(user_passes_test(group_check_all), name='dispatch')
class IndexView(generic.TemplateView):
Expand All @@ -22,11 +22,11 @@ class IndexView(generic.TemplateView):
@method_decorator(user_passes_test(group_check_all), name='dispatch')
class InfoView(generic.ListView):
template_name = 'personal/info.html'
queryset = models.Becario.objects.filter(dni="78633820V")
queryset = models.Becario.objects.all()

def get_context_data(self, **kwargs):
context = super(InfoView, self).get_context_data(**kwargs)
context["becario"] = models.Becario.objects.get(dni="78633820V")
context["becario"] = models.Becario.objects.get(email=self.request.user.email)
return context

# TODO:jeplasenciap:2017-11-20T1140:(#17):
Expand Down

0 comments on commit 9254c53

Please sign in to comment.