Exemplo n.º 1
0
 def post(self, request, **kwargs):
     if not (request.user.is_superuser or request.user == self.get_object().created_by):
         raise PermissionDenied
     try:
         user = User.objects.get(id=int(request.POST.get('user_id')))
         StudentResponsibility.objects.get(responsibility=self.get_object(), user=user)
     except StudentResponsibility.DoesNotExist:
         try:
             user = User.objects.get(id=int(request.POST.get('user_id')))
             StudentResponsibility(responsibility=self.get_object(), user=user).save()
         except User.DoesNotExist:
             redirect('error')
     return redirect('responsibility_detail', self.get_object().pk)
Exemplo n.º 2
0
 def form_valid(self, form):
     form.instance.created_by = self.request.user
     response = super(ResponsibilityCreateView, self).form_valid(form)
     StudentResponsibility(responsibility=self.object, user=self.request.user).save()
     return response