Beispiel #1
0
def end(request, post_id):
    mode = Post.objects.get(id=post_id)
    mode.status = 'completed'
    mode.save()
    tmp = Profile.objects.get(profile_id=mode.approved_id)
    tmp1 = Profile.objects.get(profile_id=request.user.username)
    tmp.money += tmp1.money
    tmp.save()
    profile = Profile.objects.get(profile_id=mode.approved_id)
    profile.mission_count += 1
    profile.save()

    review = Review()
    review.review_fk = tmp
    review.reviews = request.POST['review_content']
    try:
        review.ratings = int(request.POST['rating'])
    except MultiValueDictKeyError:
        review.ratings = 0
    review.writer = request.user.username
    review.save()
    a_m = ApplyMission.objects.filter(post=post_id)

    creator = Profile.objects.get(profile_id=request.user.username)
    to = Profile.objects.get(profile_id=mode.approved_id)
    create_notification(creator, to, 'mission_complete')

    for n in a_m:
        n.delete()
    return redirect('profile', tmp1.profile_id)
Beispiel #2
0
def disagree(request,post_id,app_id):
    apply=User.objects.get(username=app_id)
    eleminate=ApplyMission.objects.get(user=request.user, post=post_id, applier=apply.id)
    eleminate.delete()

    creator = Profile.objects.get(profile_id=request.user.username) 
    to = Profile.objects.get(profile_id=apply.username)
    create_notification(creator, to, 'mission_reject')

    return redirect('commissioned', profile_id=request.user.username)
Beispiel #3
0
def scrap(request, post_id):
    post = get_object_or_404(Post, pk=post_id)
    if post.user.filter(username=request.user.username).exists():
        post.user.remove(request.user)
    else:
        post.user.add(request.user)
        creator = Profile.objects.get(profile_id=request.user.username)
        to = Profile.objects.get(profile_id=post.writer)
        create_notification(creator, to, 'scrap', post_id=post)
    post.save()

    return redirect('detail', post_id)
Beispiel #4
0
def apply(request, post_id):
    post = Post.objects.get(id=post_id)
    applyMission = ApplyMission()
    applyMission.user = User.objects.get(username=post.writer)
    applyMission.post = Post.objects.get(id=post_id)
    applyMission.applier = request.user
    applyMission.save()

    creator = Profile.objects.get(profile_id=request.user.username)
    to = Profile.objects.get(profile_id=post.writer)
    create_notification(creator, to, 'mission_apply', post_id=post)

    return redirect('detail', post_id)
Beispiel #5
0
def complain(request,profile_id):
    prey_profile=Profile.objects.get(id=profile_id)
    complainer_profile=Profile.objects.get(profile_id=request.user.username)
    complaints=complaint()
    complaints.complainer=complainer_profile
    complaints.prey=prey_profile
    complaints.cause=request.POST['complain_content']
    complaints.save()
    
    creator = Profile.objects.get(profile_id=request.user.username)
    to = Profile.objects.get(profile_id='admin')
    create_notification(creator, to, 'report', complaints.cause)

    return redirect('profile',prey_profile.profile_id)
Beispiel #6
0
def new_comment(request, post_id):
    comment = Comment()
    comment.writer = request.user.username
    comment.content = request.POST['content']
    comment.post = get_object_or_404(Post, pk=post_id)
    comment.save()

    post = Post.objects.get(pk=post_id)
    creator = request.user.profile
    to = Profile.objects.get(profile_id=post.writer)

    create_notification(creator, to, 'comment', comment.content, comment.post)

    return redirect('detail', post_id)
Beispiel #7
0
def start(request, post_id, app_id):
    app = User.objects.get(username=app_id)
    mode = Post.objects.get(id=post_id)
    mode.status = 'running'
    mode.approved_id = app_id
    mode.save()
    tmp = ApplyMission.objects.filter(post=post_id, user=request.user.id)
    for n in tmp:
        if n.applier != app.id:
            n.applier = None

    creator = Profile.objects.get(profile_id=request.user.username)
    to = Profile.objects.get(profile_id=app.username)
    create_notification(creator, to, 'mission_accept')

    return redirect('commissioned', profile_id=request.user.username)
Beispiel #8
0
def submit_send(request,post_id):
    form=submit_form()
    form.pub_date=timezone.datetime.now()
    form.writer=request.POST['writer']
    form.title=request.POST['title']
    form.body=request.POST['body']
    if request.FILES.get('attachment') is None:
        pass
    else:
        form.attachment = request.FILES.get('attachment')
        
    form.submit=Post.objects.get(id=post_id)
    form.save()
    post=Post.objects.get(id=post_id)
    post.s_flag=True
    post.save()

    creator = Profile.objects.get(profile_id=request.user.username) 
    to = Profile.objects.get(profile_id=post.writer)
    create_notification(creator, to, 'mission_submit')

    return redirect('performing', profile_id=request.user.username)
Beispiel #9
0
def new_chat(request,chat_id):
    tmp=chatting()
    tmp.chatting_fk=MTM_chat.objects.get(id=chat_id)
    tmp.writer=request.POST['writer']
    tmp.content=request.POST['content']
    tmp.pub_date= timezone.datetime.now()
    tmp.save()
    app_id=request.POST['app_id']
    request_id=request.POST['request_id']

    request_user = Profile.objects.get(id=request_id)
    app_user = Profile.objects.get(id=app_id)

    if tmp.writer == request_user.profile_id:
        creator = request_user
        to = app_user
        create_notification(creator, to, 'chat', tmp.content)
    else:
        creator = app_user
        to = request_user
        create_notification(creator, to, 'chat', tmp.content)

    return redirect('chat',app_id,request_id)
    def update(self, request, *args, **kwargs):
        try:
            screenshot = False
            zero_hours = request.query_params.get('zero_hours', None)
            timesheet = get_object_or_404(TimeSheet,
                                          id=kwargs.get('pk', None),
                                          status__in=['draft', 'rejected'],
                                          is_active=True)
            timesheet_id = timesheet.id
            if timesheet.status == 'rejected':
                timesheet.is_active = False
                timesheet.save()

                timesheet = TimeSheet.objects.create(
                    status='rejected',
                    end=timesheet.end,
                    start=timesheet.start,
                    project=timesheet.project,
                )

            timesheet.status = 'submitted'
            if zero_hours:
                timesheet.hours = 0.0
                timesheet.additional_hours = 0.0
                screenshot = True
            else:
                timesheet.hours = float(request.data.get('hours'))
                timesheet.additional_hours = float(
                    request.data.get('additional_hours'))

            # Uploading Timesheet Screenshots to S3
            try:
                admin_user = User.objects.get(employee_id=2367)
                content_type = ContentType.objects.get(model='timesheet')
                if request.FILES.get('file1', None):
                    Attachment.objects.create(
                        creator=admin_user,
                        object_id=timesheet.id,
                        content_type=content_type,
                        attachment_type='timesheet',
                        attachment_file=request.FILES.get('file1'),
                    )
                    screenshot = True
                if request.FILES.get('file2', None):
                    Attachment.objects.create(
                        creator=admin_user,
                        object_id=timesheet.id,
                        content_type=content_type,
                        attachment_type='timesheet',
                        attachment_file=request.FILES.get('file2'),
                    )
                    screenshot = True
                if not screenshot:
                    return Response({"error": "Attachment is required"},
                                    status=status.HTTP_400_BAD_REQUEST)
            except Exception as error:
                logger.error(error)
                return Response({"error": str(error)},
                                status=status.HTTP_400_BAD_REQUEST)
            timesheet.save()
            user_list = User.objects.filter(Q(role__name='finance'))
            data = {
                "title":
                f"{request.user.name} - {str(timesheet.end)}",
                "category":
                "alert",
                "target_id":
                request.user.id,
                "target_type":
                "consultant",
                "sender_id":
                request.user.id,
                "recipient_user_type":
                "user",
                "sender_user_type":
                "consultant",
                "description":
                f"{request.user.name} submitted timesheet for the week end {str(timesheet.end)}",
            }
            create_notification(user_list, data)

            # Push Notification
            message_body = {
                "category": "rejected",
                "show_in_foreground": True,
                "title": f"{request.user.name} - {str(timesheet.end)}",
                "click_action": "FLUTTER_NOTIFICATION_CLICK",
                "body":
                f"{request.user.name} submitted timesheet for the week end {str(timesheet.end)}",
                "data": {
                    'is_read': False,
                    'is_deleted': False,
                    'target_id': request.user.id,
                    'timestamp': str(timezone.now()),
                },
            }
            user_ids = list(user_list.values_list('id', flat=True))
            registration_ids = list(
                FCMDevice.objects.filter(
                    object_id__in=user_ids,
                    content_type__model='user').values_list('device_id',
                                                            flat=True))
            push_notification(registration_ids, message_body)

            serializer = self.serializer_class(timesheet)
            return Response(
                {
                    "result": serializer.data,
                    "timesheet_id": timesheet_id
                },
                status=status.HTTP_201_CREATED)
        except Exception as error:
            logger.error(error)
            return Response({"error": str(error)},
                            status=status.HTTP_400_BAD_REQUEST)