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 }))
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 }))
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')
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")))
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)
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' )
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 )
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")))
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}) )
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}) )
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}))
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 }))