def edit(request, cohort_id): cohort = get_object_or_404(Cohort, pk=cohort_id) form = CohortForm(data=request.POST or None, instance=cohort) if form.is_valid(): form.save() return redirect(reverse('internship')) context = { 'form': form, 'page_title': _('edit_cohort'), } return render(request, 'cohort/cohort_form.html', context)
def edit(request, cohort_id): cohort = get_object_or_404(Cohort, pk=cohort_id) form = CohortForm(data=request.POST or None, instance=cohort) errors = [] if form.is_valid(): form.save() return redirect(reverse('internship')) else: errors.append(form.errors) display_errors(request, errors) context = { 'form': form, 'page_title': _('Edit cohort'), } return render(request, 'cohort/cohort_form.html', context)
def new(request): form = CohortForm(request.POST or None) errors = [] if form.is_valid(): cohort = form.save() copy_cohort.copy_from_origin(cohort) return redirect(reverse('internship')) else: errors.append(form.errors) display_errors(request, errors) context = {'form': form, 'page_title': _('Add cohort'), 'form_new': True} return render(request, 'cohort/cohort_form.html', context)
def new(request): form = CohortForm(request.POST or None) if form.is_valid(): cohort = form.save() copy_cohort.copy_from_origin(cohort) return redirect(reverse('internship')) context = { 'form': form, 'page_title': _('create_cohort'), 'form_new': True } return render(request, 'cohort/cohort_form.html', context)