示例#1
0
def group_edit(request, group_id):
    group = get_object_or_404(Group, pk=group_id)
    if request.method == 'POST':
        form = GroupForm(request.POST, instance=group)
        if form.is_valid():
            form.save()
            return redirect('index')
    else:
        form = GroupForm(instance=group)
    c = {'form': form, 'breadcrumbs': breadcrumbs('group_edit')}
    return render(request, 'students/group_manage.html', c)
示例#2
0
def group_add(request):
    c = {}
    c.update(csrf(request))
    c['title'] = u'Добавление новой группы'
    if request.method == 'POST':
        form = GroupForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/')
    else:
        form = GroupForm()
    c['form'] = form
    return render_to_response('form.html', c)
示例#3
0
def group_edit(request, group_id):
    c = {}
    c.update(csrf(request))
    c['title'] = u'Редактирование данных группы'
    group = Group.objects.get(id=group_id)
    if request.method == 'POST':
        form = GroupForm(request.POST, instance=group)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/')
    else:
        form = GroupForm(instance=group)
    c['form'] = form
    return render_to_response('form.html', c)
示例#4
0
    def dispatch(self, request, *args, **kwargs):
        form = GroupForm()
        if request.method == "POST":
            form = GroupForm(request.POST)

            if form.is_valid():
                form.save()
                MailSender.notify_about_new_group(request, form.instance)
                messages.success(request, "Группа успешно создана")
                return redirect("/")
        return render(request, self.template_name, {"form": form})
示例#5
0
    def dispatch(self, request, *args, **kwargs):
        group_id = kwargs['group_id']
        group = Group.objects.get(id=group_id)

        form = GroupForm(instance=group)
        if request.method == "POST":
            form = GroupForm(request.POST, instance=group)
            if form.is_valid():
                form.save()
                messages.success(request, "Группа успешно изменена")
                return redirect(reverse("group", kwargs={"group_id":
                                                         group_id}))

        return render(request, self.template_name, {"form": form})