示例#1
0
    def update(self, request, *args, **kwargs):
        self.object = self.get_object()
        serializer = self.get_serializer(data=request.data)
        if serializer.is_valid():
            # Check old password
            if not self.object.check_password(
                    serializer.data.get("old_password")):
                return Response({"old_password": ["Wrong password."]},
                                status=status.HTTP_400_BAD_REQUEST)
            # set_password also hashes the password that the user will get
            self.object.set_password(serializer.data.get("new_password"))
            self.object.save()
            title = 'password changed'
            body = 'your password has been changed succesfully'
            channel = 'users'
            event = 'chgpass'
            sendNotification(self.object, title, body, channel, event)
            response = {
                'status': 'success',
                'code': status.HTTP_200_OK,
                'message': 'Password updated successfully',
                'data': []
            }

            return Response(response)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
示例#2
0
    def post(self, request):
        student = StudentProfile.objects.get(user=request.user)
        if student.have_group == False:
            leader = StudentProfile.objects.get(user=request.user)
            leader.have_group = True
            serializer = GSereializer(data=request.data)
            if serializer.is_valid(raise_exception=True):
                leader = StudentProfile.objects.get(user=request.user)
                serializer.save(leader=leader)
                serializer.save()
                student = StudentProfile.objects.get(user=request.user)
                grp = Group.objects.get(leader=student)
                grp.my_promo()
                grp.save()
                leader.my_group = grp
                leader.have_group = True
                leader.save()
                title = grp.groupName + " created"
                body = grp.groupName + " has been created succesfully"

                sendNotification(request.user, title, body)
                return JsonResponse(
                    {
                        "note": "Group Succesfuly Created",
                        "status": "succes"
                    },
                    status=status.HTTP_200_OK)
            else:
                return JsonResponse(serializer.errors,
                                    status=status.HTTP_400_BAD_REQUEST)
        else:
            return JsonResponse({"note": "you are already member in group"})
示例#3
0
def create(request):
    permission_classes = (IsAuthenticated,) #DepotDeProjet
    authentication_class = JSONWebTokenAuthentication
    if request.method =="POST":
        if request.user.is_teacher==True:
            serializer=PostSerializer(data=request.data)
            if serializer.is_valid(raise_exception=True):
                    teacher=TeacherProfile.objects.get(user=request.user)
                    title=serializer.data["title"]
                    promo=serializer.data["promo"]
                    tags=serializer.data["tags"]
                    introduction=serializer.data["introduction"]
                    tools=serializer.data["tools"]
                    details=serializer.data["details"]
                    post=Post(title=title,promo=promo,tags=tags,introduction=introduction,tools=tools,details=details,user=teacher)
                    post.save()
                    title = 'project added' 
                    body = "your project has been submitted to the administration for revision"
                    
                    
                    sendNotification(request.user,title,body)
                    return JsonResponse({"note":"Post Succesfuly Created",
                            "status":"succes"},status=status.HTTP_200_OK)
            else:
                    return JsonResponse(serializer.errors,status=status.HTTP_400_BAD_REQUEST)
        else: return JsonResponse({"note":"Students can't Create posts"})
    else: return  JsonResponse({"note":"Only POST method allowed"})
示例#4
0
def PostUpdate(request,pk):
    permission_classes = (IsAuthenticated,) #DepotDeProjet
    authentication_class = JSONWebTokenAuthentication
    if request.method=="PUT": 
        if request.user.is_teacher==True:
            q=Post.objects.get(id=pk)
            if q.approved==False:
                if q.user.user==request.user:
                    serializer=PostSerializer(q,data=request.data)
                    if serializer.is_valid():
                        serializer.save(creating_date=timezone.now())
                        serializer.save()
                        title = q.__str__()
                        body = q.__str__() +" has been updated succesfully"
                        
                        
                        sendNotification(request.user,title,body)
                        return JsonResponse({"note":"Post Succesfuly UPDATED",
                                "note":"Post Succesfuly UPDATED"},status=status.HTTP_200_OK)
                    else:
                        return JsonResponse(serializer.errors,status=status.HTTP_400_BAD_REQUEST)
                else:
                    return JsonResponse({'note':'This post does not belong to you'},status=status.HTTP_404_NOT_FOUND)
            else: return JsonResponse({"note":"can't edit approved post"},status=status.HTTP_404_NOT_FOUND)
        else: return JsonResponse({"note":"Students can't update posts"})
    else: return  JsonResponse({"note":"Only PUT method allowed"})
示例#5
0
 def setChoices(self, request):
     query = request.POST['setMax']
     settings.MAXCHOICES = query
     title = 'Max choices in fiche de voeux changed'
     body = 'the Max choices in fiche de voeux changed changed to ' + str(
         query)
     channel = 'Groups'
     event = 'MaxChoices'
     sendNotification(request.user, title, body, channel, event)
     return HttpResponseRedirect("../")
示例#6
0
 def setGroupMembers(self, request):
     query = request.POST['setMax']
     settings.MAXMEMBERS = query
     print(settings.MAXMEMBERS)
     title = 'Group max member limit changed'
     body = 'the group max members limit changed to ' + str(query)
     channel = 'Groups'
     event = 'MaxMembers'
     sendNotification(request.user, title, body, channel, event)
     return HttpResponseRedirect("../")
示例#7
0
    def setGroupMembers(self, request):
        query = request.POST['setMax']
        obj = Max.objects.get(id=1)
        obj.maxMembers = query
        obj.save()

        title = 'Group max member limit changed'
        body = 'the group max members limit changed to ' + str(query)

        sendNotification(request.user, title, body)
        return HttpResponseRedirect("../")
示例#8
0
    def setChoices(self, request):
        query = request.POST['setMax']

        obj = Max.objects.get(id=1)
        obj.maxChoices = query
        obj.save()
        title = 'Max choices in fiche de voeux changed'
        body = 'the Max choices in fiche de voeux changed changed to ' + str(
            query)

        sendNotification(request.user, title, body)
        return HttpResponseRedirect("../")
示例#9
0
    def delete(self, request):
        leader = StudentProfile.objects.get(user=request.user)
        grp = Group.objects.get(leader=leader)
        members = grp.all_members()
        grp.delete()
        title = 'your group was deleted succesfuly'
        body = 'your group was deleted by ' + leader.__str__()

        for member in members:
            member.have_group = False
            sendNotification(member, title, body)
        return JsonResponse({"Note": "Group Deleted"}, status=200, safe=False)
示例#10
0
 def delete(self,request,pk):
    
             if request.user.is_student==True:
                 q=Post.objects.get(id=pk)
                 student = StudentProfile.objects.get(user=request.user)
                 if (q.Student==student):
                     q.delete()
                     title = 'project deleted'
                     body = "your project has been deleted succesfully"
                     
                     
                     sendNotification(request.user,title,body)
                     return JsonResponse({'success': 'True',
                             'Note':'Post succesfully deleted !'}, status = status.HTTP_200_OK)
                 else: return JsonResponse({'note':'This post does not belong to you'},status=status.HTTP_404_NOT_FOUND)
             else: return JsonResponse({"note":"teachers can't Delete posts"})
示例#11
0
    def post(self, request):
        student = StudentProfile.objects.get(user=request.user)
        if student.have_group == True:
            return JsonResponse({"Note": "you already have a group"})
        else:
            serializer = handleInvite(data=request.data)
            if serializer.is_valid():
                groupName = serializer.data["grp"]
                accepted = serializer.data["accepted"]
                grp = Group.objects.get(groupName=groupName)
                invite = Invite.objects.filter(grp=grp).first()
                invite.accepted = accepted
                invite.save()
                number_of_members = grp.member_count()
                obj = Max.objects.get(id=1)
                max = obj.maxMembers
                if number_of_members >= max:
                    if invite.accepted == True:
                        invite.accepted = null
                        invite.save()
                    return JsonResponse({"Note": "Group Is Full"})
                else:
                    if invite.accepted == True:
                        student.have_group = True
                        student.save()
                        student.my_group = grp
                        student.save()
                        Invitations = Invite.objects.filter(member=student,
                                                            grp=grp)
                        Invitations.delete()
                        title = grp.groupName
                        body = 'you have been added to ' + grp.groupName

                        sendNotification(student.user, title, body)
                        return JsonResponse({"note": "Member added"},
                                            status=200,
                                            safe=False)
                    else:
                        Invitations = Invite.objects.filter(member=student,
                                                            grp=grp)
                        Invitations.delete()
                        return JsonResponse({"note": "invitation refused"})
            else:
                return JsonResponse({'error': 'bad request'}, status=400)
示例#12
0
    def post(self, request):
        student = StudentProfile.objects.get(user=request.user)
        #if student.have_group==False:
        leader = StudentProfile.objects.get(user=request.user)
        grp = Group.objects.get(leader=leader)
        serializer = availaible_students(data=request.data)
        if serializer.is_valid():
            first_name = serializer.data["first_name"]
            last_name = serializer.data["last_name"]
            try:
                student = StudentProfile.objects.get(first_name=first_name,
                                                     last_name=last_name)
            except StudentProfile.DoesNotExist:
                student = None
            MyGroupmembers = grp.all_members()
            if student:
                if student == leader:
                    grp.delete()
                    student.have_group = False
                    student.save()
                    student.my_group = None
                    student.save()

                elif student in MyGroupmembers:
                    student.have_group = False
                    student.save()
                    student.my_group = None
                    student.save()
                    title = grp.groupName
                    body = 'you have been kicked from ' + grp.groupName

                    sendNotification(student.user, title, body)
                    return JsonResponse({"note": "Student Deleted"},
                                        status=200,
                                        safe=False)
                else:
                    return JsonResponse(
                        {"note": "This student is not in your group"})
            else:
                return JsonResponse({"note": "This student does not exist"})
        else:
            return JsonResponse(serializer.errors, status=400)
示例#13
0
def PostDelete(request,pk):
    permission_classes = (IsAuthenticated,) #DepotDeProjet
    authentication_class = JSONWebTokenAuthentication
    if request.method =="DELETE":
            if request.user.is_teacher==True:
                q=Post.objects.get(id=pk)
                teacher = TeacherProfile.objects.get(user=request.user)
                if (q.user==teacher):
                    q.delete()
                    title = 'project deleted'
                    body = "your project has been deleted succesfully"
                    
                    
                    sendNotification(request.user,title,body)
                    return JsonResponse({'success': 'True',
                            'Note':'Post succesfully deleted !'}, status = status.HTTP_200_OK)
                else: return JsonResponse({'note':'This post does not belong to you'},status=status.HTTP_404_NOT_FOUND)
            else: return JsonResponse({"note":"Students can't Delete posts"})
    else: 
            return JsonResponse({"method":"not allowed"},status=status.HTTP_406_NOT_ACCEPTABLE)
示例#14
0
 def put(self,request,pk):
         if request.user.is_student==True:
             q=Post.objects.get(id=pk)
             if q.approved==False:
                 if q.Student.user==request.user:
                     serializer=PostSerializer(q,data=request.data)
                     if serializer.is_valid():
                         serializer.save(creating_date=timezone.now())
                         serializer.save()
                         title = q.__str__()
                         body = q.__str__() +" has been updated succesfully"
                         
                         
                         sendNotification(request.user,title,body)
                         return JsonResponse({"note":"Post Succesfuly UPDATED",
                                 "note":"Post Succesfuly UPDATED"},status=status.HTTP_200_OK)
                     else:
                         return JsonResponse(serializer.errors,status=status.HTTP_400_BAD_REQUEST)
                 else:
                     return JsonResponse({'note':'This post does not belong to you'},status=status.HTTP_404_NOT_FOUND)
             else: return JsonResponse({"note":"can't edit approved post"},status=status.HTTP_404_NOT_FOUND)
         else: return JsonResponse({"note":"teachers can't update posts"})
示例#15
0
    def save(self):
        if self.pk is not None:
            orig = Post.objects.get(pk=self.pk)
            if (orig.approved == False) and (self.approved == True):
                title = 'project approuved'
                body = "your project " + self.title + " has been approuved by the administration"
                if self.Student != None:
                    grp = self.Student.my_group
                    fiche = groups.models.FicheDeVoeux.objects.get(
                        groupfiche=grp)
                    fiche.selected_project = self
                    fiche.save()
                    p = Post.objects.filter(Student=self.Student).exclude(
                        title=self.title).delete()
                if self.user != None:
                    sendNotification(self.user.user, title, body)
                elif self.Student != None:
                    sendNotification(self.Student.user, title, body)

                else:
                    return

        super(Post, self).save()
示例#16
0
    def post(self, request):
        leader = StudentProfile.objects.get(user=request.user)
        grp = Group.objects.get(leader=leader)
        number_of_members = grp.member_count()
        obj = Max.objects.get(id=1)
        max = obj.maxMembers
        if number_of_members >= max:
            return JsonResponse({"Note": "Group Is Full"})
        else:
            serializer = availaible_students(data=request.data)
            if serializer.is_valid():
                first_name = serializer.data["first_name"]
                last_name = serializer.data["last_name"]
                try:
                    student = StudentProfile.objects.get(first_name=first_name,
                                                         last_name=last_name)
                except StudentProfile.DoesNotExist:
                    student = None
                if student:
                    i = Invite()
                    i.grp = grp
                    i.member = student
                    i.save()
                    title = grp.groupName
                    body = leader.__str__(
                    ) + 'invited you to join his groupe ' + grp.groupName

                    sendNotification(student.user, title, body)
                    return JsonResponse({"note": "invitation sent"},
                                        status=200,
                                        safe=False)
                else:
                    return JsonResponse(
                        {"note": "This student is not availaible"})
            else:
                return JsonResponse({'error': 'bad request'}, status=400)