Example #1
0
def bookmark_add(request, username, **kwargs):
    """Adds a new bookmark for the current user.
    """
    user = get_object_or_404(User, username=username)

    bookmarks = user.get_profile().bookmarks
    bookmark = Bookmark(menu=bookmarks, sort_order=bookmarks.links.count())

    if request.method == 'POST':
        form = BookmarkForm(request.POST, instance=bookmark)
        if form.is_valid():
            bookmark.slug = slugify("%s_%s" % (bookmark.title, user.pk))
            bookmark = form.save()
            messages.success(request,
                             _("The bookmark was created successfully."))
            return redirect_to(request,
                               url=reverse('bookmark_list',
                                           args=[user.username]))
    else:
        url = clean_referer(request)
        if url == reverse('bookmark_list', args=[user.username]):
            url = ""
        bookmark.url = url
        form = BookmarkForm(instance=bookmark)

    return render_to_response(
        'menus/bookmark_edit.html',
        RequestContext(request, {
            'form': form,
            'object': bookmark,
            'object_user': user
        }))
Example #2
0
def widget_add(request, slug, **kwargs):
    """Adds a new widget to the given region.
    """
    next = request.GET.get('next', clean_referer(request))

    region = get_object_or_404(Region, slug=slug)
    widget = Widget(region=region,
                    sort_order=region.widgets.count(),
                    editable=True)

    if request.method == 'POST':
        form = WidgetForm(request.POST, instance=widget)
        if form.is_valid():
            widget.slug = slugify("%s_%s" % (widget.title, request.user.pk))
            widget = form.save()
            messages.success(request,
                             _("The widget was created successfully."))
            return redirect_to(request, url=next)
    else:
        form = WidgetForm(instance=widget)

    return render_to_response(
        'widgets/widget_edit.html',
        RequestContext(request, {
            'form': form,
            'object': widget,
            'next': next
        }))
Example #3
0
def tag_add(request, **kwargs):
    """Adds a new tag.
    """
    referer = clean_referer(request)
    if referer == reverse("tag_list"):
        referer = None

    return create_update.create_object(request,
                                       form_class=TagForm,
                                       post_save_redirect=referer,
                                       template_name='taxonomy/tag_edit.html')
Example #4
0
def event_resize(request, id, days, minutes, **kwargs):
    """Resize an event duration.
    """
    evt = Event.objects.get(pk=id)
    
    evt.end = evt.end + timedelta(int(days)) + timedelta(0, 0, 0, 0, int(minutes))
    evt.save()

    if request.is_ajax():
        resp = {"status": "OK"}
        return HttpResponse(simplejson.dumps(resp))
    else:
        return redirect_to(request, permanent=False, url=clean_referer(request, reverse("event_list")))
Example #5
0
def widget_delete(request, slug, **kwargs):
    """Deletes an existing widget.
    """
    next = request.GET.get('next', clean_referer(request))

    return create_update.delete_object(
        request,
        model=Widget,
        slug=slug,
        post_delete_redirect=next,
        template_name='widgets/widget_delete.html',
        extra_context={'next': next},
        **kwargs)
Example #6
0
def tag_add(request, **kwargs):
    """Adds a new tag.
    """
    referer = clean_referer(request)
    if referer == reverse("tag_list"):
        referer = None

    return create_update.create_object(
        request,
        form_class=TagForm,
        post_save_redirect=referer,
        template_name='taxonomy/tag_edit.html'
    )
Example #7
0
def widget_delete(request, slug, **kwargs):
    """Deletes an existing widget.
    """
    next = request.GET.get("next", clean_referer(request))

    return create_update.delete_object(
        request,
        model=Widget,
        slug=slug,
        post_delete_redirect=next,
        template_name="widgets/widget_delete.html",
        extra_context={"next": next},
        **kwargs
    )
Example #8
0
def event_resize(request, id, days, minutes, **kwargs):
    """Resize an event duration.
    """
    evt = Event.objects.get(pk=id)

    evt.end = evt.end + timedelta(int(days)) + timedelta(
        0, 0, 0, 0, int(minutes))
    evt.save()

    if request.is_ajax():
        resp = {"status": "OK"}
        return HttpResponse(simplejson.dumps(resp))
    else:
        return redirect_to(request,
                           permanent=False,
                           url=clean_referer(request, reverse("event_list")))
Example #9
0
def widget_edit(request, slug, **kwargs):
    """Edits an existing widget.
    """
    next = request.GET.get("next", clean_referer(request))

    widget = get_object_or_404(Widget, slug=slug)

    if request.method == "POST":
        form = WidgetForm(request.POST, instance=widget)
        if form.is_valid():
            widget = form.save()
            messages.success(request, _("The widget was updated successfully."))
            return redirect_to(request, url=next)
    else:
        form = WidgetForm(instance=widget)

    return render_to_response(
        "widgets/widget_edit.html", RequestContext(request, {"form": form, "object": widget, "next": next})
    )
Example #10
0
def widget_add(request, slug, **kwargs):
    """Adds a new widget to the given region.
    """
    next = request.GET.get("next", clean_referer(request))

    region = get_object_or_404(Region, slug=slug)
    widget = Widget(region=region, sort_order=region.widgets.count(), editable=True)

    if request.method == "POST":
        form = WidgetForm(request.POST, instance=widget)
        if form.is_valid():
            widget.slug = slugify("%s_%s" % (widget.title, request.user.pk))
            widget = form.save()
            messages.success(request, _("The widget was created successfully."))
            return redirect_to(request, url=next)
    else:
        form = WidgetForm(instance=widget)

    return render_to_response(
        "widgets/widget_edit.html", RequestContext(request, {"form": form, "object": widget, "next": next})
    )
Example #11
0
def bookmark_add(request, username, **kwargs):
    """Adds a new bookmark for the current user.
    """
    user = get_object_or_404(User, username=username)

    bookmarks = user.get_profile().bookmarks
    bookmark = Bookmark(menu=bookmarks, sort_order=bookmarks.links.count())

    if request.method == 'POST':
        form = BookmarkForm(request.POST, instance=bookmark)
        if form.is_valid():
            bookmark.slug = slugify("%s_%s" % (bookmark.title, user.pk))
            bookmark = form.save()
            messages.success(request, _("The bookmark was created successfully."))
            return redirect_to(request, url=reverse('bookmark_list', args=[user.username]))
    else:
        url = clean_referer(request)
        if url == reverse('bookmark_list', args=[user.username]):
            url = ""
        bookmark.url = url
        form = BookmarkForm(instance=bookmark)

    return render_to_response('menus/bookmark_edit.html', RequestContext(request, {'form': form, 'object': bookmark, 'object_user': user}))
Example #12
0
def widget_edit(request, slug, **kwargs):
    """Edits an existing widget.
    """
    next = request.GET.get('next', clean_referer(request))

    widget = get_object_or_404(Widget, slug=slug)

    if request.method == 'POST':
        form = WidgetForm(request.POST, instance=widget)
        if form.is_valid():
            widget = form.save()
            messages.success(request,
                             _("The widget was updated successfully."))
            return redirect_to(request, url=next)
    else:
        form = WidgetForm(instance=widget)

    return render_to_response(
        'widgets/widget_edit.html',
        RequestContext(request, {
            'form': form,
            'object': widget,
            'next': next
        }))