Ejemplo n.º 1
0
def create(request):
    print "%s is wants to create a new group" % request.user
    if request.POST:
        print "posted values %s" % request.POST
        group_form = GroupForm(request.POST)
        # get unsaved reference to a group model
        group = group_form.save(commit=False)
        # add the owner field (required)
        group.creator = request.user
        group.save()
        # add the owner as a member of the group
        GroupMember.objects.create(user=request.user, group=group)
        print "created a new group %s" % group
        return redirect("group_home", group.id)
    else:
        group_form = GroupForm()
        return render(request, 'wishlist_app/group/new_group.html', {'group_form': group_form})
Ejemplo n.º 2
0
def update(request, group_id):
    group = get_object_or_404(WishlistGroup, pk=group_id)
    if request.user != group.creator:
        print "user is not allowed to edit this group"
        raise PermissionDenied("Only the creator can edit an group")

    print "Update group: %s" % group
    if request.POST:
        print "posted values %s" % request.POST
        f = GroupForm(request.POST, instance=group)
        if not f.is_valid():
            return render(request, 'wishlist_app/group/update_group.html', {'group_form': f, 'group': group})
        group = f.save()
        print "update group %s" % group
        return redirect("group_home", group.id)
    else:
        group_form = GroupForm(instance=group)
        return render(request, 'wishlist_app/group/update_group.html', {'group_form': group_form, 'group': group})