Esempio n. 1
0
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)
Esempio n. 2
0
File: views.py Progetto: xnx99/enjaz
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)
Esempio n. 3
0
File: views.py Progetto: xnx99/enjaz
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})
Esempio n. 4
0
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})
Esempio n. 5
0
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})
Esempio n. 6
0
File: views.py Progetto: xnx99/enjaz
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})
Esempio n. 7
0
File: views.py Progetto: xnx99/enjaz
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}
Esempio n. 8
0
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})
Esempio n. 9
0
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}
Esempio n. 10
0
File: views.py Progetto: xnx99/enjaz
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
    })
Esempio n. 11
0
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}
Esempio n. 12
0
File: views.py Progetto: xnx99/enjaz
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}
Esempio n. 13
0
File: views.py Progetto: xnx99/enjaz
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)
Esempio n. 14
0
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)
Esempio n. 15
0
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)
Esempio n. 16
0
File: views.py Progetto: xnx99/enjaz
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)
Esempio n. 17
0
def can_edit_guide(user, guide):
    return utils.can_edit_guide(user, guide)
Esempio n. 18
0
def can_edit_guide(user, guide):
    return utils.can_edit_guide(user, guide)