Exemplo n.º 1
0
def update(request, group_id):
    group = get_object_or_404(Group, pk=group_id)

    ''' add function '''
    if request.method == 'POST':  # If the form has been submitted...
        form = GroupForm(request.contact.site, request.POST)
        if form.is_valid():  # All validation rules pass
            code = form.cleaned_data['code']
            name = form.cleaned_data['name']
            active = form.cleaned_data['active']
            recipients = form.cleaned_data['recipients']
            managers = form.cleaned_data['managers']

            try:
                group = Group.objects.get(id=group_id)
                group.name = name
                group.code = code
                group.active = active
                group.save()

                group.recipients.clear()
                for recipient in recipients:
                    group.recipients.add(recipient)
                group.managers.clear()
                for manager in managers:
                    group.managers.add(manager)
                    
            except Exception, e:
                return HttpResponse("Error 2 : %s" % e)

            return HttpResponseRedirect('/group_messaging/groups/')
Exemplo n.º 2
0
def add(request):
    ''' add function '''
    if request.method == 'POST':  # If the form has been submitted...
        form = GroupForm(request.contact.site, request.POST)
        if form.is_valid():  # All validation rules pass
            form.save()
            return HttpResponseRedirect(reverse('new_group'))
    else:
        form = GroupForm(site=request.contact.site)  # An unbound form
    context = {'form': form}
    return render_to_response('groups_users/groups/create_edit.html', context,
                              context_instance=RequestContext(request))
Exemplo n.º 3
0
def create_edit_group(request, group_id=None):
    group = None
    if 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()
            messages.info(request, "Group saved successfully")
            return HttpResponseRedirect(reverse('groups'))
    else:
        form = GroupForm(instance=group)
    context = {
        'form': form,
        'group': group,
    }
    return render_to_response('groups_users/groups/create_edit.html', context,
                              context_instance=RequestContext(request))