Beispiel #1
0
    def _handle_review_request(self, project, user_project):
        request = self.request
        user = request.user

        redirect_url = reverse('projects:detail_user',
                               args=[project.slug, project.pk, user.username])
        form = UserProjectReviewRequestForm(request.POST,
                                            instance=user_project)

        if form.is_valid():
            review_requested = form.submit_review()
            if review_requested:
                user_project.add_event(UserProjectEvent.TYPE_REVIEW_REQUEST)
                messages.info(
                    request,
                    "Terima kasih! Proyek kamu akan segera direview team UpKoding.",
                    extra_tags='success')
            else:
                messages.info(request,
                              "Detail proyek berhasil diupdate!",
                              extra_tags='success')
            return HttpResponseRedirect(redirect_url)

        self.object = self.get_object()
        context = self.get_context_data(**self.kwargs)
        context['review_request_form'] = form
        return render(request, self.template_name, context)
Beispiel #2
0
    def get_context_data(self, **kwargs):
        data = super().get_context_data(**kwargs)

        project = data.get('object')
        user = get_object_or_404(User, username=self.kwargs.get('username'))
        user_project = get_object_or_404(UserProject,
                                         user=user,
                                         project=self.object)

        data['project_owner'] = project.user
        data['user_project'] = user_project
        data['user_project_owner'] = user

        user_projects = UserProject.objects \
            .select_related('user') \
            .filter(project=project,
                    status__in=(UserProject.STATUS_IN_PROGRESS,
                                UserProject.STATUS_COMPLETE,
                                UserProject.STATUS_PENDING_REVIEW)) \
            .order_by('-created')[:10]
        data['user_projects'] = user_projects

        # show completion form only when:
        # - requirements completed
        # - current user is the owner
        show_review_request_form = user_project.is_requirements_complete() \
            and (user == self.request.user)
        if show_review_request_form:
            data['review_request_form'] = UserProjectReviewRequestForm(
                instance=user_project)
        return data
Beispiel #3
0
    def __handle_review_request(self, request, project, user_project):
        form = UserProjectReviewRequestForm(
            request.POST, instance=user_project)

        if form.is_valid():
            review_requested = form.submit_review()
            if review_requested:
                user_project.add_event(UserProjectEvent.TYPE_REVIEW_REQUEST)
                messages.info(request,
                              "Great job! Proyek kamu sudah disubmit untuk direview team UpKoding.",
                              extra_tags='success')
            else:
                messages.info(request,
                              "Detail proyek berhasil diupdate!",
                              extra_tags='success')
            return HttpResponse()
        return HttpResponseBadRequest(form.errors.as_json(), content_type='application/json; charset=utf-8')
Beispiel #4
0
    def get_context_data(self, **kwargs):
        user = get_object_or_404(User, username=self.kwargs.get('username'))
        user_project = get_object_or_404(
            UserProject, user=user, project=self.object)

        data = super().get_context_data(**kwargs)
        data['user_project'] = user_project

        # show completion form only when:
        # - requirements completed
        # - url has `?form=1`
        # - current user is the owner
        rev_request = self.request.GET.get('form') == '1'
        show_rr_form = user_project.is_requirements_complete() \
            and rev_request \
            and (user == self.request.user)

        if show_rr_form:
            data['rr_form'] = UserProjectReviewRequestForm(
                instance=user_project)
        return data