def add_report(request, guide_pk): guide = get_object_or_404(GuideProfile, pk=guide_pk) if not utils.can_edit_guide(request.user, guide): raise Exception(u"لا تستطيع رفع تقرير") if request.method == 'POST': current_year = StudentClubYear.objects.get_current() instance = Report(guide=guide) form = ReportForm(request.POST, request.FILES, instance=instance) if form.is_valid(): report = form.save() show_report_url = reverse('studentguide:show_report', args=(guide.pk, report.pk)) full_url = request.build_absolute_uri(show_report_url) if guide.assessor: email_context = {'assessor': guide.assessor, 'guide': guide, 'full_url': full_url} mail.send([guide.assessor.email], template="report_submitted_to_assessor", context=email_context) return {"message": "success", "show_url": full_url} elif request.method == 'GET': form = ReportForm() context = {'form': form, 'guide': guide} return render(request, 'studentguide/edit_report_form.html', context)
def add_report(request, guide_pk): guide = get_object_or_404(GuideProfile, pk=guide_pk) if not utils.can_edit_guide(request.user, guide): raise Exception(u"لا تستطيع رفع تقرير") if request.method == 'POST': current_year = StudentClubYear.objects.get_current() instance = Report(guide=guide) form = ReportForm(request.POST, request.FILES, instance=instance) if form.is_valid(): report = form.save() show_report_url = reverse('studentguide:show_report', args=(guide.pk, report.pk)) full_url = request.build_absolute_uri(show_report_url) if guide.assessor: email_context = { 'assessor': guide.assessor, 'guide': guide, 'full_url': full_url } mail.send([guide.assessor.email], template="report_submitted_to_assessor", context=email_context) return {"message": "success", "show_url": full_url} elif request.method == 'GET': form = ReportForm() context = {'form': form, 'guide': guide} return render(request, 'studentguide/edit_report_form.html', context)
def list_guide_requests(request, guide_pk): guide = get_object_or_404(GuideProfile, pk=guide_pk, is_deleted=False) if not utils.can_edit_guide(request.user, guide): raise PermissionDenied return render(request, "studentguide/list_guide_requests.html", {'guide': guide})
def show_report(request, guide_pk, report_pk): report = get_object_or_404(Report, guide__pk=guide_pk, pk=report_pk, is_deleted=False) if not utils.can_edit_guide(request.user, report.guide): raise PermissionDenied return render(request, "studentguide/show_report.html", {'report': report})
def delete_guide(request, guide_pk): guide = get_object_or_404(GuideProfile, pk=guide_pk, is_deleted=False) if not utils.can_edit_guide(request.user, guide): raise Exception(u"لا تستطيع حذف المرشد") guide.is_deleted = True guide.save() list_guides_url = reverse('studentguide:list_guides') full_url = request.build_absolute_uri(list_guides_url) return {"message": "success", "list_url": full_url}
def list_reports(request, guide_pk): guide = get_object_or_404(GuideProfile, pk=guide_pk, is_deleted=False) if not utils.can_edit_guide(request.user, guide): raise PermissionDenied reports = Report.objects.filter(guide=guide, is_deleted=False) return render(request, 'studentguide/list_reports.html', {'reports': reports, 'guide': guide})
def list_reports(request, guide_pk): guide = get_object_or_404(GuideProfile, pk=guide_pk, is_deleted=False) if not utils.can_edit_guide(request.user, guide): raise PermissionDenied reports = Report.objects.filter(guide=guide, is_deleted=False) return render(request, 'studentguide/list_reports.html', { 'reports': reports, 'guide': guide })
def delete_report(request, guide_pk, report_pk): report = get_object_or_404(Report, guide__pk=guide_pk, pk=report_pk, is_deleted=False) if not utils.can_edit_guide(request.user, report.guide): raise Exception(u"لا تستطيع حذف المرشد") report.is_deleted = True report.save() list_reports_url = reverse('studentguide:list_reports', args=(report.guide.pk,)) full_url = request.build_absolute_uri(list_reports_url) return {"message": "success", "list_url": full_url}
def delete_report(request, guide_pk, report_pk): report = get_object_or_404(Report, guide__pk=guide_pk, pk=report_pk, is_deleted=False) if not utils.can_edit_guide(request.user, report.guide): raise Exception(u"لا تستطيع حذف المرشد") report.is_deleted = True report.save() list_reports_url = reverse('studentguide:list_reports', args=(report.guide.pk, )) full_url = request.build_absolute_uri(list_reports_url) return {"message": "success", "list_url": full_url}
def edit_guide(request, guide_pk): guide = get_object_or_404(GuideProfile, pk=guide_pk, is_deleted=False) if not utils.can_edit_guide(request.user, guide): raise Exception(u"لا تستطيع تعديل الكتاب") context = {'guide': guide} if request.method == 'POST': form = GuideForm(request.POST, request.FILES, instance=guide) if form.is_valid(): guide = form.save() show_guide_url = reverse('studentguide:show_guide', args=(guide.pk, )) full_url = request.build_absolute_uri(show_guide_url) return {"message": "success", "show_url": full_url} elif request.method == 'GET': form = GuideForm(instance=guide) context['form'] = form return render(request, 'studentguide/edit_guide_form.html', context)
def edit_guide(request, guide_pk): guide = get_object_or_404(GuideProfile, pk=guide_pk, is_deleted=False) if not utils.can_edit_guide(request.user, guide): raise Exception(u"لا تستطيع تعديل الكتاب") context = {'guide': guide} if request.method == 'POST': form = GuideForm(request.POST, request.FILES, instance=guide) if form.is_valid(): guide = form.save() show_guide_url = reverse('studentguide:show_guide', args=(guide.pk,)) full_url = request.build_absolute_uri(show_guide_url) return {"message": "success", "show_url": full_url} elif request.method == 'GET': form = GuideForm(instance=guide) context['form'] = form return render(request, 'studentguide/edit_guide_form.html', context)
def edit_report(request, guide_pk, report_pk): report = get_object_or_404(Report, guide__pk=guide_pk, pk=report_pk, is_deleted=False) if not utils.can_edit_guide(request.user, report.guide): raise Exception(u"لا تستطيع رفع تقرير") context = {'report': report} if request.method == 'POST': form = ReportForm(request.POST, request.FILES, instance=report) if form.is_valid(): report = form.save() show_report_url = reverse('studentguide:show_report', args=(report.guide.pk, report.pk)) full_url = request.build_absolute_uri(show_report_url) return {"message": "success", "show_url": full_url} elif request.method == 'GET': form = ReportForm(instance=report) context['form'] = form return render(request, 'studentguide/edit_report_form.html', context)
def can_edit_guide(user, guide): return utils.can_edit_guide(user, guide)