Example #1
0
def save_bookmark(request, bookmark_id=False):
    if request.is_ajax:
        return ajax_save_bookmark(request, bookmark_id)
    form = BookmarkForm()
    bookmark = get_object_or_None(Bookmark, pk=bookmark_id)
    if bookmark:
        form = BookmarkForm(instance=bookmark)
        if not request.user.is_authenticated() or (
                not request.user.is_staff and
            (bookmark.note.author == request.user)):
            return HttpResponseRedirect(reverse(list, args=(note.id, )))
    if request.method == "POST":
        if bookmark:
            form = BookmarkForm(request.POST, instance=bookmark)
        else:
            form = BookmarkForm(request.POST)
        if form.is_valid():
            if not bookmark:
                bookmark = Bookmark()
                bookmark.save()
            if 'text' in form.cleaned_data:
                bookmark.text = form.cleaned_data['text']
            if 'chart' in form.cleaned_data:
                bookmark.chart = form.cleaned_data['chart']
            if 'tags' in form.cleaned_data:
                bookmark.tags = form.cleaned_data['tags']
            if 'note' in form.cleaned_data:
                bookmark.note = form.cleaned_data['note']
            bookmark.save()
            return HttpResponseRedirect(
                reverse(save_bookmark, kwargs={
                    "bookmark_id": bookmark.id,
                }))
    return render_to_response('notes/form_page.html', {'form': form},
                              context_instance=RequestContext(request))
Example #2
0
def bookmark(request, id):
    try:
        bookmark = Bookmark.objects.get(user=request.user, event_id=id)
    except Bookmark.DoesNotExist:
        bookmark = Bookmark(user=request.user, event_id=id)
        bookmark.save()
    return redirect(bookmark)
Example #3
0
def save_bookmark_to_note(request, note):
    saved_bookmarks = 0
    if request.method == 'POST':
        if 'bookmarks' in request.POST:
            for bookmark_id in request.POST['bookmarks'].split(","):
                if bookmark_id != '':
                    bookmark = get_object_or_None(Bookmark, pk=bookmark_id)
                    if bookmark:
                        bookmark.note = note
                        bookmark.save()
        chart = False
        tags = []
        if 'chart_id' in request.POST:
            chart = get_object_or_None(Chart, pk=request.POST['chart_id'])
        if 'tags' in request.POST:
            for short in request.POST['tags'].split(','):
                if short != '':
                    tag = get_object_or_None(Tag, short=short)
                    if tag:
                        tags.append(tag)
        if chart:
            bookmark = Bookmark()
            bookmark.chart = chart
            bookmark.note = note
            bookmark.save()
            bookmark.tags = tags
    return saved_bookmarks
Example #4
0
def bookmark(request,id):
    try:
        bookmark = Bookmark.objects.get(user=request.user,event_id=id)
    except Bookmark.DoesNotExist:
        bookmark = Bookmark(user=request.user,event_id=id)
        bookmark.save()
    return redirect(bookmark)
Example #5
0
    def test_addition_of_results_to_folder(self):
        f1 = create_folder(self.ie,'test')

        r1 = Result(title='r1',url='www.love.com',summary="Gambo Gambo")

        b1 = Bookmark(folder=f1,title=r1.title, url=r1.url, summary=r1.summary)
        b1.save()

        b2 = add_result_to_folder(f1.id, r1)
        self.assertEquals(b1,b2)
Example #6
0
def upload(request, usrid):
    if request.method == "POST":

        this = AudioMeta()
        try:
            this.name = request.POST['title']
        except:
            this.name = "NONE"

        try:
            this.user_id = User.objects.get(id=usrid)
        except:
            try:
                this.user_id = User.objects.get(id=1)
            except:
                pass

        this.annotations = 0
        this.transcriptions = 0
        this.plays = 0
        this.likes = 0

        if request.FILES:

            this.bytes = request.FILES['file'].size
            a = open("/home/leegao/webapps/notetag/notetag/audio/a.txt", "w")
            a.write(str(request.FILES))
            a.close()
            try:
                this.type = extension_re.search(
                    request.FILES['file'].name).group(1).lower()
            except:
                this.type = "wav"
            this.save()

            try:
                marks = request.POST['marks']

                for secs in [int(i.strip()) for i in marks.split(",") if i]:
                    m = Bookmark(aud_id=this, time=secs)
                    m.save()
            except:
                pass

            handle_uploaded_file(request.FILES['file'], this.id, this.type)
        else:
            return HttpResponseForbidden()

        return HttpResponse(content="1")
    else:
        form = UploadFileForm()
        return render_to_response('upload.html', {
            'form': form,
            'usrid': usrid
        })
Example #7
0
def upload(request, usrid):
    if request.method == "POST":

        this = AudioMeta()
        try:
            this.name = request.POST["title"]
        except:
            this.name = "NONE"

        try:
            this.user_id = User.objects.get(id=usrid)
        except:
            try:
                this.user_id = User.objects.get(id=1)
            except:
                pass

        this.annotations = 0
        this.transcriptions = 0
        this.plays = 0
        this.likes = 0

        if request.FILES:

            this.bytes = request.FILES["file"].size
            a = open("/home/leegao/webapps/notetag/notetag/audio/a.txt", "w")
            a.write(str(request.FILES))
            a.close()
            try:
                this.type = extension_re.search(request.FILES["file"].name).group(1).lower()
            except:
                this.type = "wav"
            this.save()

            try:
                marks = request.POST["marks"]

                for secs in [int(i.strip()) for i in marks.split(",") if i]:
                    m = Bookmark(aud_id=this, time=secs)
                    m.save()
            except:
                pass

            handle_uploaded_file(request.FILES["file"], this.id, this.type)
        else:
            return HttpResponseForbidden()

        return HttpResponse(content="1")
    else:
        form = UploadFileForm()
        return render_to_response("upload.html", {"form": form, "usrid": usrid})
Example #8
0
def ajax_save_bookmark(request, bookmark_id=False):
    bookmark = get_object_or_None(Bookmark, pk=bookmark_id)
    if request.method == "POST":
        if 'chart_id' not in request.POST or 'tags' not in request.POST:
            return HttpResponse(
                json.dumps({
                    "message": {
                        'type': 'error',
                        'text': "Can't save bookmark",
                    },
                }), 'application/json')
        if not bookmark:
            bookmark = Bookmark()
            bookmark.save()
        if 'chart_id' in request.POST:
            chart = get_object_or_None(Chart, pk=request.POST['chart_id'])
            if chart:
                bookmark.chart = chart
        if 'tags' in request.POST:
            for short in request.POST['tags'].split(','):
                tag = get_object_or_None(Tag, short=short)
                if tag:
                    bookmark.tags.add(tag)
        if 'note_id' in request.POST:
            note = get_object_or_None(Note, pk=request.POST['note_id'])
            if note:
                bookmark.note = note
            else:
                bookmark.note = False
        bookmark.save()
        _bookmark = bookmark.as_json()
        _bookmark['url'] = 'http://' + request.get_host() + reverse(
            save_bookmark, args=(bookmark.id, ))
        return HttpResponse(
            json.dumps({
                "message": {
                    'type': 'success',
                    'text': "Bookmark saved",
                },
                "bookmarks": [_bookmark],
            }), 'application/json')
    return HttpResponse(
        json.dumps({
            "message": {
                'type': 'error',
                'text': "Use post",
            },
        }), 'application/json')
Example #9
0
def create_bookmark(request):
    form = BookmarkForm()
    if request.method == 'GET' and request.GET:
        form = BookmarkForm(initial=request.GET)
    elif request.method == 'POST':
        form = BookmarkForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            labels = str_to_labels(data.pop('labels'))
            bookmark = Bookmark(**data)
            bookmark.author = request.user
            bookmark.save()
            bookmark.labels = labels
            bookmark.save()
            return HttpResponseRedirect(reverse("bookmarks.views.bookmark_list", args=[]))
    return render_to_response('bookmarks/bookmark_form.html', {'form': form, 
        'labels': Label.objects.all()}, context_instance=RequestContext(request))
Example #10
0
def add(user=None):
    if 'url' not in request.form:
        return jsonify(errors=['Dude, what\'s wrong with you ?', 'You are missing Bookmark Url']), 400
    if not is_url_valid(request.form['url']):
        return jsonify(errors=['Dude, what\'s wrong with you ?', 'Invalid Bookmark Url']), 400
    bookmark = Bookmark(url=request.form['url'], user=user)
    if bookmark.save():
        return jsonify(bookmark=bookmark.to_dict()), 200
    return jsonify(errors=[bookmark.to_dict()]), 400
Example #11
0
def upload(request, usrid):
    if request.method == "POST":

        this = AudioMeta()
        this.name = request.POST['title']
        #try:
        this.user_id = User.objects.get(id=usrid)
        #except:
        #return HttpResponseForbidden()
        this.annotations = 0
        this.transcriptions = 0
        this.plays = 0
        this.likes = 0

        if request.FILES:
            this.bytes = request.FILES['file'].size
            try:
                this.type = extension_re.search(
                    request.FILES['file'].name).group(1).lower()
            except:
                this.type = "wav"
            this.save()
            try:
                marks = request.POST['marks']
                for secs in [int(i.strip()) for i in marks.split(",")]:
                    m = Bookmark(aud_id=this, time=secs)
                    m.save()
            except:
                pass
            handle_uploaded_file(request.FILES['file'], this.id, this.type)
        else:
            return HttpResponseForbidden()

        return HttpResponseRedirect('/')
    else:
        form = UploadFileForm()
        return render_to_response('upload.html', {
            'form': form,
            'usrid': usrid
        })
Example #12
0
def add(user=None):
    if 'url' not in request.form:
        return jsonify(errors=[
            'Dude, what\'s wrong with you ?', 'You are missing Bookmark Url'
        ]), 400
    if not is_url_valid(request.form['url']):
        return jsonify(
            errors=['Dude, what\'s wrong with you ?', 'Invalid Bookmark Url'
                    ]), 400
    bookmark = Bookmark(url=request.form['url'], user=user)
    if bookmark.save():
        return jsonify(bookmark=bookmark.to_dict()), 200
    return jsonify(errors=[bookmark.to_dict()]), 400
Example #13
0
def upload(request, usrid):
    if request.method == "POST":


        this = AudioMeta()
        this.name = request.POST['title']
        #try:
        this.user_id = User.objects.get(id=usrid)
        #except:
            #return HttpResponseForbidden()
        this.annotations = 0
        this.transcriptions = 0
        this.plays = 0
        this.likes = 0

        if request.FILES:
            this.bytes = request.FILES['file'].size
            try:
                this.type = extension_re.search(request.FILES['file'].name).group(1).lower()
            except:
                this.type = "wav"
            this.save()
            try:
                marks = request.POST['marks']
                for secs in [int(i.strip()) for i in marks.split(",")]:
                    m = Bookmark(aud_id = this, time = secs)
                    m.save()
            except:
                pass
            handle_uploaded_file(request.FILES['file'], this.id, this.type)
        else:
            return HttpResponseForbidden()

        return HttpResponseRedirect('/')
    else:
        form = UploadFileForm()
        return render_to_response('upload.html', {'form': form, 'usrid':usrid})
Example #14
0
 def POST(self):
     form = bookmark_form()
     if not form.validates():
         content = 'Validation error'
         return render.add_bookmark(content, form)
     else:
         i = web.input()
         #db = web.database(dbn='sqlite', db='bookmarks_webpy.sqlite')
         bookmark = Bookmark(db)
         bookmark.url = i.url
         bookmark.description = i.description
         bookmark.author = session.user_id
         result = bookmark.save()
         content = 'bookmark added'
         return render.add_bookmark_success(content, result)
Example #15
0
def savebookmark(TitleF,UrlF,DescriptionF,TagF,PrivateF,UserF):
    TitleF = unicode(TitleF)
    UrlF = unicode(UrlF)
    DescriptionF = unicode(DescriptionF)
    Tagf = unicode(TagF)
    try :
        UrlB = Url.objects.get(url=UrlF)
    except :
        UrlB = Url(url=UrlF)
    UrlB.save()

    try :
        TitleB = Title.objects.get(title=TitleF)
    except :
        TitleB = Title(title=TitleF)
    TitleB.save();
    try :
        DescriptionB = Description.objects.get(description=DescriptionF)
    except :
        DescriptionB = Description(description=DescriptionF)
    DescriptionB.save()
    try :
        PrivateB = Private.objects.get(private= (PrivateF == 'True'))
    except :
        PrivateB = Private(private= (PrivateF == 'True'))
    PrivateB.save()
    try :
        b2 = Bookmark.objects.get(url=UrlB)
        b2.title=TitleB
        b2.description=DescriptionB
        b2.private=PrivateB
    except :
        b2 = Bookmark(title=TitleB,url=UrlB,description=DescriptionB,private=PrivateB)
        b2.save()
        b2.user.add(UserF)
    b2.save()

    tags = TagF.split(" ")
    tags.sort()
    for t in tags :
        try :
            TagB = Tag.objects.get(tag=t)
        except :
            TagB= Tag(tag=t)
            TagB.save()
            TagB.user.add(UserF)
        TagB.save()
        b2.tag.add(TagB)
    b2.save()
Example #16
0
	def testTwo(self):
		b = Bookmark(title='title',url='url')
		b.save()
		self.assertEqual(b.pk,1)
		self.assertEqual(b.title,'title')
		
Example #17
0
def add_bookmark( user, obj ):
    bookmark = Bookmark( user=user,
            content_object=obj,
            public = get_setting(user, 'profile_public'))
    bookmark.save()
    return bookmark