コード例 #1
0
    def put(self, request, format=None):
        verify = VerifyHelper.verifyUser(request)

        if verify[0]:
            user = verify[2]
            return Response(
                UserHelper.updateUserSkillsAndProjects(user, request.data))

        else:
            return Response(verify[1])
コード例 #2
0
    def get(self, request, pk, format=None):

        verified, user = VerifyHelper.isUserVerified(request)

        if not verified:
            return Response(user)

        project = NewProject.objects.get(pk=pk)

        return Response(NewProjectSerializer(project).data)
コード例 #3
0
    def get(self, request, pk, format=None):

        verified, user = VerifyHelper.isUserVerified(request)

        if not verified:
            return Response(user)

        user = User.objects.get(pk=pk)

        return Response(UserSerializer(user).data)
コード例 #4
0
    def get(self, request, offset, format=None):

        verified, user = VerifyHelper.isUserVerified(request)

        if not verified:
            return Response(user)

        projects = NewProject.objects.filter(visible=True,
                                             user=user)[offset:offset + 15]

        return Response(NewProjectSerializer(projects, many=True).data)
コード例 #5
0
    def get(self, request, offset, format=None):

        verified, user = VerifyHelper.isUserVerified(request)

        if not verified:
            return Response(user)

        activities = Activities.objects.filter(
            Q(sender=user) | Q(receiver=user))

        return Response(ActivitySerializer(activities, many=True).data)
コード例 #6
0
    def get(self, request, user_id, offset, format=None):

        verified, user = VerifyHelper.isUserVerified(request)

        if not verified:
            return Response(user)

        toUser = User.objects.get(pk=user_id)

        messages = Message.objects.filter(
            Q(sender=user, receiver=toUser)
            | Q(sender=toUser, receiver=user))[offset:offset + 15]

        return Response(MessageSerializer(messages, many=True).data)
コード例 #7
0
    def get(self, request, offset, format=None):

        verified, user = VerifyHelper.isUserVerified(request)

        if not verified:
            return Response(user)

        skills = []

        for skill in user.skills.all():
            skills.append(skill.skill_id)

        projects = NewProject.objects.filter(
            id__in=NewProjectSkill.objects.values('project').filter(
                skill__in=skills)).filter(visible=True).exclude(
                    user=user)[offset:offset + 15]

        return Response(NewProjectSerializer(projects, many=True).data)
コード例 #8
0
    def put(self, request, user_id, offset, format=None):

        verified, user = VerifyHelper.isUserVerified(request)

        if not verified:
            return Response(user)

        receiver = User.objects.get(pk=user_id)
        print(request.data)
        message = request.data['message']
        print(message)

        message = {'message': message}

        formed_message = Message.objects.create(sender=user,
                                                receiver=receiver,
                                                **message)

        return Response(MessageSerializer(formed_message).data)
コード例 #9
0
    def put(self, request, offset, format=None):

        #offset will be useful later

        verified, user = VerifyHelper.isUserVerified(request)
        if not verified:
            return Response(user)

        NewProject.objects.filter(user=user).delete()

        for project in request.data:
            project.pop('id')
            skills = project.pop('skills')
            proj = NewProject.objects.create(user=user, **project)

            for skill in skills:
                skill_fmtd = {'skill': skill}
                NewProjectSkill.objects.create(project=proj, **skill_fmtd)

        return Response({"Success": "Successfully updated"})
コード例 #10
0
    def get(self, request, project_id, offset, format=None):

        verified, user = VerifyHelper.isUserVerified(request)

        if not verified:
            return Response(user)

        project = NewProject.objects.get(pk=project_id)

        skills = []

        for skill in project.skills.all():
            skills.append(skill.skill)

        print(skills)

        users = User.objects.filter(id__in=Skill.objects.values('user').filter(
            skill_id__in=skills)).exclude(pk=user.pk)[offset:offset + 15]

        return Response(BasicUserSkillSerializer(users, many=True).data)
コード例 #11
0
    def get(self, request, format=None):

        verified, user = VerifyHelper.isUserVerified(request)

        if not verified:
            return Response(user)

        diff_users = Message.objects.filter(Q(sender=user) | Q(
            receiver=user)).annotate(other=Case(
                When(sender=user, then=F('receiver')), default=F(
                    'sender'))).values('other').distinct().order_by()

        message_ids = set()
        for other in diff_users:
            message = Message.objects.filter(
                (Q(sender=user) & Q(receiver=other['other']))
                | (Q(receiver=user) & Q(sender=other['other'])))[:1]
            message_ids.add(message[0].pk)

        messages = Message.objects.filter(id__in=message_ids)
        return Response(MessageSerializer(messages, many=True).data)
コード例 #12
0
    def get(self, request, pk, format=None):

        verified, user = VerifyHelper.isUserVerified(request)

        if not verified:
            return Response(user)

        project = NewProject.objects.get(pk=pk)
        toUser = User.objects.get(new_projects=project)

        prevActivity = Activities.objects.filter(project=project, sender=user)

        if (len(prevActivity) > 0):
            return Response({"Error": "Activity Already Done"})

        data = {'activity_type': ACTIVITY_TYPE_REQUEST_JOIN}

        activity = Activities.objects.create(sender=user,
                                             receiver=toUser,
                                             project=project,
                                             **data)

        return Response(ActivitySerializer(activity).data)
コード例 #13
0
    def get(self, request, pk, reply, format=None):

        verified, user = VerifyHelper.isUserVerified(request)

        if not verified:
            return Response(user)

        activity = Activities.objects.get(pk=pk)

        if activity.receiver == user:
            if activity.activity_type == ACTIVITY_TYPE_REQUEST_INVITE:
                if (reply == 100):
                    activity.activity_type = ACTIVITY_TYPE_REQUEST_INVITE_ACCEPTED
                else:
                    activity.activity_type = ACTIVITY_TYPE_REQUEST_INVITE_REJECTED

                activity.timestamp = datetime.datetime.now()

                activity.save()

                return Response(ActivitySerializer(activity).data)

            if activity.activity_type == ACTIVITY_TYPE_REQUEST_JOIN:

                if (reply == 100):
                    activity.activity_type = ACTIVITY_TYPE_REQUEST_JOIN_ACCEPTED
                else:
                    activity.activity_type = ACTIVITY_TYPE_REQUEST_JOIN_REJECTED

                activity.timestamp = datetime.datetime.now()

                activity.save()

                return Response(ActivitySerializer(activity).data)

        return Response("Invalid")
コード例 #14
0
 def get(self, request, format=None):
     return Response(VerifyHelper.verifyUser(request)[1])