Exemple #1
0
def edit_group(request, group_id):
    can_edit = request.fmsuser.leader
    instance = OrganisationEntity.objects.get(id=group_id)

    # Init formset object for mail config
    GroupMailFormSet = inlineformset_factory(OrganisationEntity, GroupMailConfig, form=GroupMailConfigForm, can_delete=False)

    if request.method == "POST" and can_edit:
        group_form                = GroupForm(request.POST, instance=instance)
        group_mail_config_formset = GroupMailFormSet(request.POST, instance=instance)

        if group_form.is_valid() and group_mail_config_formset.is_valid():
            group_form.save()
            group_mail_config_formset.save()

            messages.add_message(request, messages.SUCCESS, _("Group has been updated successfully"))
            return HttpResponseRedirect(reverse('list_groups'))

    else:
        group_form                = GroupForm(instance=instance)
        group_mail_config_formset = GroupMailFormSet(instance=instance)

    return render_to_response("pro/auth/group_create.html", {
        "group": instance,
        "group_form": group_form,
        "group_mail_config_formset": group_mail_config_formset,
        "memberships": UserOrganisationMembership.objects.filter(organisation=instance),
        "can_edit": can_edit
    }, context_instance=RequestContext(request))
Exemple #2
0
def create_group(request,):
    can_edit = request.fmsuser.leader

    if request.method == "POST" and can_edit:
        group_form = GroupForm(request.POST)

        if group_form.is_valid():
            group = group_form.save(commit=False)
            group.dependency = request.fmsuser.organisation
            group.save()
            config = GroupMailConfig(group=group)
            config.save()

            messages.add_message(request, messages.SUCCESS, _("Group has been created successfully"))
            return HttpResponseRedirect(reverse('list_groups'))

    else:
        group_form = GroupForm()


    return render_to_response("pro/auth/group_create.html", {
        "group_form": group_form,
        "can_edit":  can_edit,
    }, context_instance=RequestContext(request))