Beispiel #1
0
def view_report(request, display_name, year, month):
    """View report view."""
    month_number = utils.month2number(month)
    report = get_object_or_404(Report,
                               user__userprofile__display_name=display_name,
                               month__year=int(year),
                               month__month=month_number)

    if request.method == 'POST':
        if not request.user.is_authenticated():
            messages.error(request, 'Permission denied.')
            return redirect('main')

        report_comment = ReportComment(report=report, user=request.user)
        report_comment_form = forms.ReportCommentForm(request.POST,
                                                      instance=report_comment)
        if report_comment_form.is_valid():
            report_comment_form.save()
            messages.success(request, 'Comment saved.')

            # provide a new clean form
            report_comment_form = forms.ReportCommentForm()
    else:
        report_comment_form = forms.ReportCommentForm()

    report_url = reverse('reports_view_report',
                         kwargs={
                             'display_name': display_name,
                             'year': year,
                             'month': month
                         })

    if (request.user.groups.filter(name='Admin').exists()
            or (request.user == report.user)
            or (request.user.is_authenticated()
                and report.user in request.user.mentees.all())):
        editable = True
    else:
        editable = False

    q = Q(name='Admin') | Q(name='Council') | Q(name='Mentor')
    if (request.user.groups.filter(q).exists() or request.user == report.user):
        view_status = True
    else:
        view_status = False

    return render(
        request, 'view_report.html', {
            'pageuser': report.user,
            'user_profile': report.user.userprofile,
            'editable': editable,
            'view_status': view_status,
            'report': report,
            'month': month,
            'year': year,
            'comments': report.reportcomment_set.all(),
            'report_comment_form_url': report_url,
            'report_comment_form': report_comment_form
        })
Beispiel #2
0
 def setUp(self):
     self.date = datetime.datetime.now()
     self.user = User.objects.get(username='******')
     self.user_profile = self.user.userprofile
     self.report = Report.objects.get(pk=1)
     self.commenter = self.user.userprofile.mentor
     self.new_comment = ReportComment(user=self.commenter,
                                      created_on=self.date,
                                      report=self.report)