Beispiel #1
0
def edit_friendlist(request, id):
    """
    Edit a friendlist.
    
    **Template:**
    ``friendycontrol/friendlist_form.html``
    
    **Context:**
        ``form``: The form object to render
        
        ``add``: ``True`` if you want to re-mark that is an *add* operation
    
    **Decorators:**
        :func:`django.contrib.auth.decorators.login_required` 
    """
    try:
        friendlist = get_object_or_404(FriendListGroupName, id=id,
                                                            owner = request.user)
    except Http404:
        raise Http404
    if request.method == "POST":
        form = FriendListForm(instance=friendlist, data = request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('friendy_show_main_friendylist'))
    else:
        form = FriendListForm(instance=friendlist)
    return render_to_response('friendycontrol/friendlist_form.html',
                              {'form': form,
                               'add': False}, 
                              context_instance = RequestContext(request))
Beispiel #2
0
def add_friendlist(request):
    """
    Creates a friendlist that will be elegible for the ``CompositionList``.
    
    **Template:**
    ``friendycontrol/friendlist_form.html``
    
    **Context:**
        ``form``: The form object to render
        
        ``add``: ``True`` if you want to re-mark that is an *add* operation
    
    **Decorators:**
        :func:`django.contrib.auth.decorators.login_required`    
    """
    if request.method == 'POST':
        form = FriendListForm(data=request.POST)
        if form.is_valid():
            friendlist = form.save(commit=False)
            friendlist.owner = request.user
            slug = str(slugify(friendlist.group_name))
            friendlist.slug = slug
            try:
                friendlist.save()
            except IntegrityError:
                form.non_field_errors = 'This group name already exist. Please, choose another one.'
            else:
                return HttpResponseRedirect(reverse('friendy_show_main_friendylist'))
    else:
        form = FriendListForm()
    return render_to_response('friendycontrol/friendlist_form.html',
                              {'form': form,
                               'add': True},
                              context_instance = RequestContext(request))