Exemplo n.º 1
0
def course_create(request, semester_id):
    semester = get_object_or_404(Semester, id=semester_id)
    course = Course(semester=semester)
    ContributionFormset = inlineformset_factory(Course,
                                                Contribution,
                                                formset=ContributorFormSet,
                                                form=ContributionForm,
                                                extra=1,
                                                exclude=('course', ))

    form = CourseForm(request.POST or None, instance=course)
    formset = ContributionFormset(request.POST or None, instance=course)

    if form.is_valid() and formset.is_valid():
        form.save(user=request.user)
        formset.save()

        messages.add_message(request, messages.INFO,
                             _("Successfully created course."))
        return redirect('evap.fsr.views.semester_view', semester_id)
    else:
        return render_to_response("fsr_course_form.html",
                                  dict(semester=semester,
                                       form=form,
                                       formset=formset),
                                  context_instance=RequestContext(request))
Exemplo n.º 2
0
Arquivo: views.py Projeto: Nef10/EvaP
def course_create(request, semester_id):
    semester = get_object_or_404(Semester, id=semester_id)
    course = Course(semester=semester)
    ContributionFormset = inlineformset_factory(Course, Contribution, formset=ContributorFormSet, form=ContributionForm, extra=1, exclude=('course',))

    form = CourseForm(request.POST or None, instance=course)
    formset = ContributionFormset(request.POST or None, instance=course)

    if form.is_valid() and formset.is_valid():
        form.save(user=request.user)
        formset.save()

        messages.success(request, _("Successfully created course."))
        return redirect('evap.fsr.views.semester_view', semester_id)
    else:
        return render_to_response("fsr_course_form.html", dict(semester=semester, form=form, formset=formset), context_instance=RequestContext(request))
Exemplo n.º 3
0
Arquivo: views.py Projeto: Nef10/EvaP
def course_edit(request, semester_id, course_id):
    semester = get_object_or_404(Semester, id=semester_id)
    course = get_object_or_404(Course, id=course_id)
    ContributionFormset = inlineformset_factory(Course, Contribution, formset=ContributorFormSet, form=ContributionForm, extra=0, exclude=('course',))

    # check course state
    if not course.can_fsr_edit():
        messages.warning(request, _("Editing not possible in current state."))
        return redirect('evap.fsr.views.semester_view', semester_id)

    form = CourseForm(request.POST or None, instance=course)
    formset = ContributionFormset(request.POST or None, instance=course, queryset=course.contributions.exclude(contributor=None))

    if form.is_valid() and formset.is_valid():
        form.save(user=request.user)
        formset.save()

        messages.success(request, _("Successfully updated course."))
        return custom_redirect('evap.fsr.views.semester_view', semester_id, tab=get_tab(request))
    else:
        return render_to_response("fsr_course_form.html", dict(semester=semester, course=course, form=form, formset=formset), context_instance=RequestContext(request))
Exemplo n.º 4
0
Arquivo: views.py Projeto: mswart/EvaP
def course_edit(request, semester_id, course_id):
    semester = get_object_or_404(Semester, id=semester_id)
    course = get_object_or_404(Course, id=course_id)
    AssignmentFormset = inlineformset_factory(Course, Assignment, formset=LecturerFormSet, form=AssignmentForm, extra=1, exclude=('course'))
    
    # check course state
    if not course.can_fsr_edit():
        messages.add_message(request, messages.ERROR, _("Editting not possible in current state."))
        return redirect('evap.fsr.views.semester_view', semester_id)
    
    form = CourseForm(request.POST or None, instance=course)
    formset = AssignmentFormset(request.POST or None, instance=course, queryset=course.assignments.exclude(lecturer=None))

    if form.is_valid() and formset.is_valid():
        form.save(user=request.user)
        formset.save()
        
        messages.add_message(request, messages.INFO, _("Successfully updated course."))
        return redirect('evap.fsr.views.semester_view', semester_id)
    else:
        return render_to_response("fsr_course_form.html", dict(semester=semester, course=course, form=form, formset=formset), context_instance=RequestContext(request))
Exemplo n.º 5
0
def course_edit(request, semester_id, course_id):
    semester = get_object_or_404(Semester, id=semester_id)
    course = get_object_or_404(Course, id=course_id)
    ContributionFormset = inlineformset_factory(Course, Contribution, formset=ContributorFormSet, form=ContributionForm, extra=1, exclude=('course',))

    # check course state
    if not course.can_fsr_edit():
        messages.add_message(request, messages.ERROR, _("Editing not possible in current state."))
        return redirect('evap.fsr.views.semester_view', semester_id)

    form = CourseForm(request.POST or None, instance=course)
    formset = ContributionFormset(request.POST or None, instance=course, queryset=course.contributions.exclude(contributor=None))

    if form.is_valid() and formset.is_valid():
        form.save(user=request.user)
        formset.save()

        messages.add_message(request, messages.INFO, _("Successfully updated course."))
        return custom_redirect('evap.fsr.views.semester_view', semester_id, tab=request.GET.get('tab', '1'))
    else:
        return render_to_response("fsr_course_form.html", dict(semester=semester, course=course, form=form, formset=formset), context_instance=RequestContext(request))