示例#1
0
def edit_groups(request, *args, **kwargs):
    """View, add, or delete edit groups
    :param request:  
    :param args: 
    :param kwargs: 
    :return:
    """
    page = Page.objects.get(slug=kwargs['slug']).get_content_model()
    
    if request.method == 'POST':
        try:
            page.add_edit_group(Group.objects.get(name=request.POST['name']))
        except:
            pass
        return to_referrer(request)
    elif request.method == 'DELETE':
        try:
            grp = int(kwargs['group'])
            page.remove_edit_group(Group.objects.get(pk=grp))
        except:
            grp = kwargs['group']
            page.remove_edit_group(Group.objects.get(name=grp))
        return to_referrer(request)

    return json_or_jsonp(request, list(page.edit_groups), 200)
示例#2
0
def edit_users(request, *args, **kwargs):
    """View, add, or delete edit users
    :param request:  
    :param args: 
    :param kwargs: 
    :return:
    """

    print kwargs
    page = Page.objects.get(slug=kwargs['slug']).get_content_model()
    
    if request.method == 'POST':
        try:
            page.add_edit_user(User.objects.get(email=request.POST['name']))
        except:
            pass # invalid email address - need to handle better

        return to_referrer(request)
    elif request.method == 'DELETE':
        try:
            grp = int(kwargs['user'])
            page.remove_edit_user(User.objects.get(pk=grp))
        except:
            grp = kwargs['user']
            page.remove_edit_user(User.objects.get(username=grp))
        return to_referrer(request)

    return json_or_jsonp(request, list(page.edit_users.union({page.owner.pk} if page.owner else set())), 200)
示例#3
0
def view_users(request, *args, **kwargs):
    """View, add, or delete view users
    :param request:  
    :param args: 
    :param kwargs: 
    :return:
    """

    page = Page.objects.get(slug=kwargs['slug']).get_content_model()
    
    if request.method == 'POST':
        try:
            page.add_view_user(User.objects.get(email=request.POST['name']))
        except:
            pass

        return to_referrer(request)
    elif request.method == 'DELETE':
        try:
            grp = int(kwargs['user'])
            page.remove_view_user(grp)
            print "removed user {u} from page {p}".format(u=grp, p=page.pk)
        except:
            grp = kwargs['user']
            page.remove_view_user(User.objects.get(email=grp))
        return to_referrer(request)

    return json_or_jsonp(request, list(page.view_users.union({page.owner.pk} if page.owner else set())), 200)
示例#4
0
def delete_page(request):
    slug = request.GET['slug']
    p = Page.objects.get(slug=slug)
    parent = p.parent
    p.delete()
    if slug in request.META['HTTP_REFERER']:
       if parent == None:
          return HttpResponseRedirect('/')
       return HttpResponseRedirect('/' + parent.slug)
    return to_referrer(request)