Esempio n. 1
0
def add_bookmark(request):
    """
    Add Site to Bookmarks.
    """
    
    if request.method == 'POST':
        if request.POST.get('path') and request.POST.get('title'):
            next = request.POST.get('path')
            try:
                bookmark = Bookmark.objects.get(user=request.user)
            except Bookmark.DoesNotExist:
                bookmark = Bookmark(user=request.user)
                bookmark.save()
            try:
                bookmarkitem = BookmarkItem.objects.get(bookmark=bookmark, link=request.POST.get('path'))
                msg = _('Site is already bookmarked.')
            except BookmarkItem.DoesNotExist:
                try:
                    bookmarkitem = BookmarkItem(bookmark=bookmark, title=request.POST.get('title'), link=request.POST.get('path'))
                    bookmarkitem.save()
                    msg = _('Site was added to Bookmarks.')
                except:
                    msg = _('Error: Site could not be added to Bookmarks.')
        else:
            msg = _('Error: Site could not be added to Bookmarks.')
            next = request.POST.get('path')
    else:
        msg = _('Error: Site could not be added to Bookmarks.')
        next = ADMIN_URL
    
    # MESSAGE & REDIRECT
    request.user.message_set.create(message=msg)
    return HttpResponseRedirect(next)
Esempio n. 2
0
def add_bookmark(request):
    """
    Add Site to Bookmarks.
    """

    if request.GET:
        if request.GET.get('path') and request.GET.get('title'):
            next = request.GET.get('path')
            try:
                bookmark = Bookmark.objects.get(user=request.user)
            except Bookmark.DoesNotExist:
                bookmark = Bookmark(user=request.user)
                bookmark.save()
            bookmarkitem = BookmarkItem(bookmark=bookmark,
                                        title=request.GET.get('title'),
                                        link=request.GET.get('path'))
            bookmarkitem.save()
            msg = _('Site was added to Bookmarks.')
        else:
            msg = _('Error: Site could not be added to Bookmarks.')
            next = "/admin/"
    else:
        msg = _('Error: Site could not be added to Bookmarks.')

    # MESSAGE & REDIRECT
    request.user.message_set.create(message=msg)
    return HttpResponseRedirect(next)
Esempio n. 3
0
def add_bookmark(request):
    """
    Add Site to Bookmarks.
    """
    
    if request.method == 'POST':
        if request.POST.get('path') and request.POST.get('title'):
            next = urllib.unquote(request.POST.get('path'))
            try:
                bookmark = Bookmark.objects.get(user=request.user)
            except Bookmark.DoesNotExist:
                bookmark = Bookmark(user=request.user)
                bookmark.save()
            try:
                bookmarkitem = BookmarkItem.objects.get(bookmark=bookmark, link=urllib.unquote(request.POST.get('path')))
                msg = ['error', _('Site is already bookmarked.')]
            except BookmarkItem.DoesNotExist:
                try:
                    bookmarkitem = BookmarkItem(bookmark=bookmark, title=request.POST.get('title'), link=urllib.unquote(request.POST.get('path')))
                    bookmarkitem.save()
                    msg = ['success', _('Site was added to Bookmarks.')]
                except:
                    msg = ['error', _('Site could not be added to Bookmarks.')]
        else:
            msg = ['error', _('Site could not be added to Bookmarks.')]
            next = request.POST.get('path')
    else:
        msg = ['error', _('Site could not be added to Bookmarks.')]
        next = ADMIN_URL
    
    # MESSAGE & REDIRECT
    if not request.session.get('grappelli'):
        request.session['grappelli'] = {}
    request.session['grappelli']['message'] = msg
    request.session.modified = True
    return HttpResponseRedirect(next)