def clean_user(self): """ Makes sure the user is in LDAP, and creates the user in the system if it doesn't exist already The user is submitted as something like "Matt Johnson (mdj2)", so we have to parse out the "mdj2" part """ user = self.cleaned_data['user'].strip() # if the user isn't filled out, so be it if user == "": return "" matches = re.search(r"\((.+)\)$", user) if not matches: raise forms.ValidationError("user must be of the form 'name (odin)'") user = matches.group(1) if not is_ldap_user(user): raise forms.ValidationError("Not a valid ODIN username") # create the user in the system if it doesn't exist email = User.username_to_email(user) try: user = User.objects.get(email=email) except User.DoesNotExist: user = User(email=email, is_active=False) user.save() return user
def user(request): """ Return the recent Requests for this user. """ # TODO show loans too? email = User.username_to_email(request.GET.get("username", "")) requests = Request.objects.filter(reservation__user__email=email).filter( end__lte=now()+timedelta(hours=10000), # TODO change this to something reasonable according to the client end__gte=now() ).select_related( "reservation", "reservation__bib", "reservation__user", ) return render(request, "requests/_user.html", { "requests": requests, })