Example #1
0
def add():
    user = Users("Debabrata", "Patnaik")
    form = BookmarkForm()
    form.userform.data = user.getfullname()[:3]
    # if request.method == "POST":
    #     url = request.form["url"]
    #     user = request.form.get("user","Deb")
    #     store_bookmarks(url, user)
    #     app.logger.debug("Stored URL: " + url)
    #     flash("Stored URL: " + url)
    #     return redirect(url_for('index'))
    # return render_template("add.html")
    if form.validate_on_submit():
        print form.url.data, form.description.data
        try:
            print form.userform
        except Exception, exc:
            print exc
        url = form.url.data
        description = form.description.data
        user = form.userform.data

        store_bookmarks(url, user, description)
        app.logger.debug("Stored URL: " + url)
        flash("Stored URL: {}".format(url))
        return redirect(url_for("index"))
Example #2
0
def add():
    form = BookmarkForm()
    if form.validate_on_submit():
        url = form.url.data
        description = form.description.data
        destination = form.destination.data
        outbound_date = form.outbound_date.data
        outbound_time = form.outbound_time.data
        inbound_date = form.inbound_date.data
        inbound_time = form.inbound_time.data
        tags = form.tags.data
        bm = Bookmark(user=current_user,
                      url=url,
                      description=description,
                      destination=destination,
                      tags=tags,
                      outbound_date=outbound_date,
                      outbound_time=outbound_time,
                      inbound_date=inbound_date,
                      inbound_time=inbound_time)
        db.session.add(bm)
        db.session.commit()
        flash("Stored trip '{}'".format(description))
        return redirect(url_for('index'))
    return render_template('bookmark_form.html', form=form, title="Add a Trip")
Example #3
0
def add_bookmark():
    """
    Add a bookmark to the database
    """

    add_bookmark = True

    form = BookmarkForm()
    if form.validate_on_submit():
        bookmark = Bookmark(name=form.name.data,
                            url=form.url.data,
                            description=form.description.data,
                            user_id=current_user.id)
        try:
            # add bookmark to the database
            db.session.add(bookmark)
            db.session.commit()
            flash('You have successfully added a new bookmark.')
        except:
            # in case bookmark name already exists
            flash('Error: bookmark name already exists.')

        # redirect to bookmarks page
        return redirect(url_for('profile.list_bookmarks'))

    # load bookmark template
    return render_template('profile/bookmarks/bookmark.html',
                           action="Add",
                           add_bookmark=add_bookmark,
                           form=form,
                           title="Add Bookmark")
Example #4
0
def edit_bookmark(id):
    """
    Edit a bookmark
    """

    add_bookmark = False

    bookmark = Bookmark.query.get_or_404(id)
    form = BookmarkForm(obj=bookmark)
    if form.validate_on_submit():
        bookmark.name = form.name.data
        bookmark.url = form.url.data
        bookmark.description = form.description.data
        db.session.commit()
        flash('You have successfully edited the bookmark.')

        # redirect to the bookmarks page
        return redirect(url_for('profile.list_bookmarks'))

    form.description.data = bookmark.description
    form.url.data = bookmark.url
    form.name.data = bookmark.name
    return render_template('profile/bookmarks/bookmark.html',
                           action="Edit",
                           add_bookmark=add_bookmark,
                           form=form,
                           bookmark=bookmark,
                           title="Edit Bookmark")
Example #5
0
def add_bookmark(request):
    """
    This view serves and validates a bookmark form.
    If requested via ajax it also returns the drop bookmark form to replace the 
    add bookmark form.
    """
    if request.method == "POST":
        form = BookmarkForm(user=request.user, data=request.POST)
        if form.is_valid():
            bookmark = form.save()
            if not request.is_ajax():
                messages.success(request, 'Bookmark added')
                if request.POST.get('next'):
                    return HttpResponseRedirect(request.POST.get('next'))
                return HttpResponse('Added')
            return render_to_response('admin_tools/menu/remove_bookmark_form.html',
                       RequestContext(request, {
                'bookmark': bookmark,
                'url': bookmark.url,
            }))
    else:
        form = BookmarkForm(user=request.user)
    return render_to_response('admin_tools/menu/form.html',
               RequestContext(request, {
        'form': form,
        'title': 'Add Bookmark',
    }))
Example #6
0
def add_bookmark(request):
    """
    This view serves and validates a bookmark form.
    If requested via ajax it also returns the drop bookmark form to replace the
    add bookmark form.
    """
    if request.method == "POST":
        form = BookmarkForm(user=request.user, data=request.POST)
        if form.is_valid():
            bookmark = form.save()
            if not request.is_ajax():
                request.user.message_set.create(message='Bookmark added')
                if request.POST.get('next'):
                    return HttpResponseRedirect(request.POST.get('next'))
                return HttpResponse('Added')
            return TemplateResponse(request, 'client_admin/menu/remove_bookmark_form.html', context={
                'bookmark': bookmark,
                'url': bookmark.url,
            })
    else:
        form = BookmarkForm(user=request.user)
    return TemplateResponse(request, 'client_admin/menu/form.html', context={
        'form': form,
        'title': 'Add Bookmark',
    })
Example #7
0
def add():
    form = BookmarkForm()
    if form.validate_on_submit():
        url, description = form.url.data, form.description.data
        store_bookmark(url, description)
        flash(f"stored url: {url}")
        return redirect(url_for('index'))
    return render_template('add.html', form=form)
Example #8
0
def bookmark_create(request):
	if request.method == 'POST':
		form = BookmarkForm(data=request.POST)
		if form.is_valid():
			form.save(owner=request.user)
			return redirect('game_bookmark_user', username=request.user.username)
	else:
		form = BookmarkForm()
	return render(request, 'game/form.html', {'form': form, 'create': True})
Example #9
0
def add():
    form = BookmarkForm()
    if form.validate_on_submit():
        url = form.url.data
        description = form.description.data
        store_bookmark(url, description)
        flash("Stored bookmark '{}'".format(description))
        return redirect(url_for("index"))
    return render_template("add.html", form=form)
Example #10
0
def addBookmark(request):
    if request.POST:
        form = BookmarkForm(request.POST)
        if form.is_valid():
            mark = form.save(commit=False)
            mark.user_id = auth.get_user(request).id
            mark.save()
            just_print.delay(mark)
    return redirect('/bookmarks/')
Example #11
0
def add():
    form = BookmarkForm()
    if form.validate_on_submit():
        url = form.url.data
        description = form.description.data
        store_bookmark(url, description)
        flash("You have successfully bookmarked {}".format(url))
        return redirect(url_for('index'))
    return render_template('add.html', form=form)
Example #12
0
def add():
    form = BookmarkForm()
    if form.validate_on_submit():
        url = form.url.data
        description = form.description.data
        store_bookmark(url, description)
        flash("Stored bookmark '{}'".format(description))
        return redirect(url_for('index'))
    return render_template('add.html', form=form)
def add():
    form = BookmarkForm()
    if form.validate_on_submit():
        url = form.url.data
        description = form.description.data
        store_bookmark(url, description)
        flash(f'Stored {description}')
        app.logger.debug(f'Stored {url} as {description}')
        return redirect(url_for('index'))
    return render_template('add.html', form=form)
Example #14
0
def add():
    form = BookmarkForm()
    # If method=GET OR form-content is invalid, then...
    if form.validate_on_submit():
        url = form.url.data
        description = form.description.data
        store_bookmark(url, description)
        flash("Stored bookmark '{}'".format(url))
        return redirect(url_for('index'))
    return render_template('add.html', form=form)
Example #15
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 #16
0
def add():
    form = BookmarkForm()
    if form.validate_on_submit():
        url = form.url.data
        description = form.description.data
        #url = request.form['url']  #getting data from 'form' dictionary(works with request reference)
        store_bookmark(url, description)
        flash('Bookmark saved: {}'.format(description))
        #app.logger.debug('stored url:' + url)
        return redirect(url_for('index'))
    return render_template('add.html', form=form)
Example #17
0
def add():
    form = BookmarkForm()
    if form.validate_on_submit():
        url = form.url.data
        description = form.description.data
        bm = models.Bookmark(url = url, description = description)
        db.session.add(bm)
        db.session.commit()
        flash("Store '{}'".format(description))
        return redirect(url_for('index'))
    return render_template('add.html', form=form)
Example #18
0
def add():
    form = BookmarkForm()
    if form.validate_on_submit():
        url = form.url.data
        description = form.description.data
        bm = models.Bookmark(url=url, description=description)
        db.session.add(bm)
        db.session.commit()
        flash("Stored '{}'".format(description))
        return redirect(url_for('index'))
    return render_template('add.html', form=form)
Example #19
0
 def edit(self, bookmark_id):
     if not users.get_current_user():
         webapp2.abort(401)
     bookmark = db.get(db.Key.from_path('Bookmark', int(bookmark_id)))
     form = BookmarkForm(self.get_locale(), self.request.POST, bookmark)
     if self.request.POST and form.validate():
         form.populate_obj(bookmark)
         bookmark.date = datetime.now()
         bookmark.put()
         return self.redirect('/bookmark/list')
     self.render_template('form.html', {'title': _('Bookmark'), 'form': form, 'name': 'bookmark', 'id': bookmark.key().id()})
Example #20
0
def add():
    form = BookmarkForm()
    if form.validate_on_submit():
        url = form.url.data
        description = form.description.data
        store_bookmark(url, description)
        # app.logger.debug('stored_url: ' + url)
        flash("store_bookmark '{}'".format(description))
        return redirect(url_for('index'))

    return render_template('add.html', form=form)
Example #21
0
def edit_bookmark(bookmark_id):
    bookmark = Bookmark.query.get_or_404(bookmark_id)
    if current_user != bookmark.user:
        abort(403)
    form = BookmarkForm(obj=bookmark)
    if form.validate_on_submit():
        form.populate_obj(bookmark)
        db.session.commit()
        flash("Stored '{}'".format(bookmark.description))
        return redirect(url_for('user', username=current_user.username))
    return render_template('bookmark_form.html', form=form, title="Edit Trip")
Example #22
0
def add():
    form = BookmarkForm()
    if form.validate_on_submit():
        db.session.add(
            Bookmark(user=logged_in_user(),
                     url=form.obj.data,
                     description=form.description.data))
        db.session.commit()
        flash("Stored description {}".format(form.description.data))
        return redirect(url_for('index'))
    return render_template('add.html', form=form)
def add():
	form = BookmarkForm()					# On a GET request, the fields are empty and the form variables are also empty. On a POST request, the variables are full. This will likely only work because the action was "", as that means it referring to a still available form to read the values of
	if form.validate_on_submit():			# This line also checks to make sure the method is not GET
		url = form.url.data
		description = form.description.data
		bm = models.Bookmark(user=logged_in_user(), url=url, description=description)
		db.session.add(bm)
		db.session.commit()
		flash("Stored '{}'".format(description))
		return redirect(url_for('index'))
	return render_template('add.html', form=form)  # form=form is sent because the template is actually using the form to populate the DOM with form fields
Example #24
0
def add():
    form = BookmarkForm()
    if form.validate_on_submit():
        url = form.url.data
        description=form.description.data

        store_bookmark(url,description)
        # app.logger.debug('stored url %s' % url)
        flash("Stored bookmark '{}'".format(description))
        return  redirect(url_for('index'))
    return render_template('add.html',Text="1232",form=form)
Example #25
0
def edit_bookmark(bookmark_id):
	bookmark = Bookmark.query.get_or_404(bookmark_id)
	if current_user != bookmark.user:
		abort(403)
	form = BookmarkForm(obj=bookmark)
	if form.validate_on_submit():
		form.populate_obj(bookmark)
		db.session.commit()
		flash("Stored %s" % bookmark.description)
		return redirect(url_for('user',username=current_user.username))
	return render_template('edit.html',form=form,title='Edit Bookmark')
Example #26
0
def add():
    form = BookmarkForm()
    if form.validate_on_submit():
        url = form.url.data
        description = form.description.data
        bm = Bookmark(user=logged_in_user(), url=url, description=description)
        db.session.add(bm)
        db.session.commit()
        flash("Stored bookmak '{}'.".format(description))
        return redirect(url_for("index"))
    return render_template("add.html", form=form)
Example #27
0
def add():
    form = BookmarkForm()
    if form.validate_on_submit():
        url = request.form['url']
        bm = Bookmark(user=current_user, url=url)
        db.session.add(bm)
        db.session.commit()
        application.logger.debug('URL:' + url)
        flash("Stored url: {}".format(url))
        return redirect(url_for('return_200'))
    return render_template('add.html', form=form)
Example #28
0
def add():
    form = BookmarkForm()
    if form.validate_on_submit():
        # url = request.form['url']
        # store_bookmark(url)
        url = form.url.data
        description = form.description.data
        store_bookmark(url, description)
        flash("please find below list of URLs.")
        flash("Bookmark is :- '{}'".format(url))
        return redirect(url_for('hello'))
    return render_template('Add.html', form=form)
Example #29
0
def add_bookmark():
    form = BookmarkForm()
    # checks http request and form
    if form.validate_on_submit():
        url = form.url.data
        description = form.description.data
        bm = Bookmark(url=url, description=description)
        db.session.add(bm)
        db.session.commit()
        flash(f"stored bookmark: {url}")
        return redirect(url_for('index'))
    return render_template('add.html', form=form)
Example #30
0
def add():
	form = BookmarkForm()
	if form.validate_on_submit():
		url = form.url.data
		description = form.description.data
		tags = form.tags.data
		bm = Bookmark(user=current_user,url=url,description=description,tags=tags)
		db.session.add(bm)
		db.session.commit()
		flash("Bookmark Successfully Added")
		return redirect(url_for('index'))
	return render_template('add.html',form=form)
Example #31
0
def editUrl(bookmarkid):
    bookmark = bookmarkDB.query.get(bookmarkid)
    form = BookmarkForm(obj=bookmark)
    if form.validate_on_submit():
        form.populate_obj(bookmark)
        db.session.commit()
        flash("Successfully edited the bookmark")
        return redirect(url_for("user", userid=current_user.id))
    return render_template('addUrlForm.html',
                           form=form,
                           user=current_user,
                           title="Edit bookmark")
Example #32
0
def add():
    form = BookmarkForm()
    if form.validate_on_submit():
        url = form.url.data
        description = form.description.data
        tags = form.tags.data
        bm = Bookmark(user=current_user, url=url, description=description, tags=tags)
        db.session.add(bm)
        db.session.commit()
        flash("Stored '{}'".format(bm.description))
        return redirect(url_for('index'))
    return render_template('bookmark_form.html', form=form, title="Add a bookmark")
Example #33
0
def bookmark_edit(request, pk):
	bookmark = get_object_or_404(Bookmark, pk=pk)
	if bookmark.owner != request.user and not request.user.is_superuser:
		raise PermissionDenied
	if request.method == 'POST':
		form = BookmarkForm(instance=bookmark, data=request.POST)
		if form.is_valid():
			form.save()
			return redirect('game_bookmark_user', username=request.user.username)
	else:
		form = BookmarkForm(instance=bookmark)
	return render(request, 'game/form.html', {'form': form, 'create': False, 'bookmark': bookmark})
Example #34
0
def edit_bookmark(id):
    b = g.user.bid(id)
    form = BookmarkForm(obj=b)
    if not b:
        abort(403)
    if form.validate_on_submit():
        form.populate_obj(b)
        b.updated = datetime.utcnow()
        db.session.add(b)
        db.session.commit()
        flash("Bookmark %s updated" % (form.title.data), category="info")
        return redirect(url_for("index"))
    return render_template("edit.html", title="Edit", form=form)
Example #35
0
def add():
    form = BookmarkForm()
    if form.validate_on_submit():
        url = form.url.data
        description = form.description.data
        bm = models.Bookmark(user=current_user,
                             url=url,
                             description=description)
        db.session.add(bm)
        db.session.commit()
        flash(f'stored bookmark {description}', 'success')
        return redirect(url_for('index'))
    return render_template('bookmark_form.html', form=form, title="Add form")
Example #36
0
def add():
    form = BookmarkForm()
    if form.validate_on_submit():
        url = form.url.data
        description = form.description.data
        bm = models.Bookmark(user=current_user, url=url, description=description)

        db.session.add(bm)
        db.session.commit()
        # app.logger.debug('stored url: ' + url)
        flash("stored '{}' ".format(description))
        return redirect(url_for('index'))
    return render_template("add.html", form=form)
Example #37
0
def add():
    form = BookmarkForm()
    if form.validate_on_submit():
        url = form.url.data
        description = form.description.data
        bm = Bookmark(url=url, description=description, user=current_user)
        db.session.add(bm)
        db.session.commit()
        flash('Stored bookmark: {}'.format(url))
        return redirect(url_for('index'))
    return render_template('bookmark_form.html',
                           form=form,
                           title='Add Bookmark')
Example #38
0
def create(request):
    if request.method == 'POST': # If the form has been submitted...
        form = BookmarkForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            bookmark = form.save()
            return HttpResponseRedirect(reverse('bookmark_index')) # Redirect after POST
    else:
        form = BookmarkForm() # An unbound form

    return render_to_response('create.html',
        RequestContext(request, {
            'form': form,
            }))
Example #39
0
def edit_bookmark(id):
    b = g.user.bid(id)
    form = BookmarkForm(obj=b)
    if not b:
        abort(403)
    if form.validate_on_submit():
        form.populate_obj(b)
        b.updated = datetime.utcnow()
        db.session.add(b)
        db.session.commit()
        flash('Bookmark %s updated' % (form.title.data), category='info')
        return redirect(url_for('index'))
    return render_template('edit.html', title='Edit', form=form)
Example #40
0
def edit_bookmark(bookmark_id):
    bookmark = Bookmark.query.get_or_404(bookmark_id)
    if current_user != bookmark.user:
        abort(403)
    form = BookmarkForm(obj=bookmark)
    if form.validate_on_submit():
        form.populate_obj(bookmark)
        db.session.commit()
        flash('Your bookmark was saved succesfully')
        return redirect(url_for('main.user', username=current_user.username))
    return render_template('bookmark_form.html',
                           form=form,
                           title='Edit Bookmark')
Example #41
0
def add_bookmark():
    if not session.get('logged_in'):
        abort(401)
    form = BookmarkForm(request.form)
    if request.method == 'POST' and form.validate():
        if form.url.data and form.description.data:
            author = User.query.filter_by(username=session.get('username')).first()
            bookmark = Bookmark(form.url.data, form.description.data, datetime.utcnow(), author)
            db.session.add(bookmark)
            db.session.commit()
            flash('New bookmark saved successfully')
        else:
            flash('URL is required.')
    return redirect(url_for('show_bookmarks'))
Example #42
0
def edit_bookmark(bookmark_id):
    bookmark = models.Bookmark.query.get_or_404(bookmark_id)
    print(type(bookmark))
    if current_user != bookmark.user:
        abort(403)
    form = BookmarkForm(obj=bookmark)
    if form.validate_on_submit():
        form.populate_obj(bookmark)
        db.session.commit()
        flash('Stored {}'.format(bookmark.description), "success")
        return redirect(url_for('user', username=current_user.username))
    return render_template('bookmark_form.html',
                           form=form,
                           title='Edit Bookmark')
Example #43
0
def add():
    form = BookmarkForm()
    if form.validate_on_submit():
        url = form.url.data
        description = form.description.data
        bm = Bookmark(url=url, description=description, user=current_user)
        db.session.add(bm)
        db.session.commit()
        app.logger.debug('stored url ' + url)
        flash("Stored '{0}'".format(description))
        return redirect(url_for('index'))
    return render_template('bookmark_form.html',
                           form=form,
                           title='Add new bookmark')
Example #44
0
def add():
    form = BookmarkForm()
    if form.validate_on_submit():
        url = form.url.data
        description = form.description.data
        tags = form.tags.data
        bm = Bookmark(user=current_user,
                      url=url,
                      description=description,
                      tags=tags)
        db.session.add(bm)
        db.session.commit()
        flash("Bookmark Successfully Added")
        return redirect(url_for('index'))
    return render_template('add.html', form=form)
Example #45
0
def add():
    form = BookmarkForm()
    if form.validate_on_submit():
        url = form.url.data
        description = form.description.data
        bm = models.Bookmark(user=logged_user(),
                             url=url,
                             description=description)
        db.session.add(
            bm)  # TODO the object has been aleady added through manage.initdb
        db.session.commit()
        flash('Stored bookmark "{}"'.format(url))
        app.logger.debug('strored url: ' + url)  # @TODO print in debug mode
        return redirect(url_for('index'))
    return render_template('add.html', form=form)
Example #46
0
def bookmark(request):
    if not request.user.is_authenticated():
        return HttpResponseRedirect('/login/?next=%s' % request.META['HTTP_REFERER'])
    try:
        bookmark = Bookmark.objects.get(
            user=request.user,
            content_type=request.POST['content_type'], 
            object_id=request.POST['object_id'],
        )
        return HttpResponseRedirect(bookmark.content_object.get_absolute_url())
    except Exception, e:
        bookmark = Bookmark(user=request.user)
        bookmarkform = BookmarkForm(request.POST, instance=bookmark)
        bookmark = bookmarkform.save()
        return HttpResponseRedirect(bookmark.content_object.get_absolute_url())
Example #47
0
 def create(self, parent_id=None):
     if not users.get_current_user():
         webapp2.abort(401)
     form = BookmarkForm(self.get_locale(), self.request.POST, None)
     if self.request.POST and form.validate():
         parent = None
         if form.reference_id.data:
             parent = db.get(db.Key.from_path('Bookmark', int(form.reference_id.data)))
         bookmark = Bookmark(author=users.get_current_user(), reference=parent, title=form.title.data, url=form.url.data)
         bookmark.date = datetime.now()
         bookmark.put()
         return self.redirect('/bookmark/list')
     else:
         if parent_id:
             form.reference_id.data = parent_id
     self.render_template('form.html', {'title': _('Bookmark'), 'form': form, 'name': 'bookmark'})
Example #48
0
def edit_bookmark(request, id):
    bookmark = get_object_or_404(Bookmark, id=id)
    if request.method == "POST":
        form = BookmarkForm(user=request.user, data=request.POST, instance=bookmark)
        if form.is_valid():
            form.save()
            if not request.is_ajax():
                request.user.message_set.create(message='Bookmark updated')
                if request.POST.get('next'):
                    return HttpResponseRedirect(request.POST.get('next'))
            return HttpResponse('Saved')
    else:
        form = BookmarkForm(user=request.user, instance=bookmark)
    return TemplateResponse(request, 'client_admin/menu/form.html', context={
        'form': form,
        'title': 'Edit Bookmark',
    })
Example #49
0
def new_bookmark():
    form = BookmarkForm()
    if form.validate_on_submit():
        b = Bookmark()
        form.populate_obj(b)
        b.owner_id = g.user.id
        b.created = datetime.utcnow()
        b.tags = " ".join([t.strip() for t in form.tags.data.strip().split(",")]).lower()
        b.clicks = 0
        if not form.title.data:
            soup = BSoup(urlopen(form.url.data))
            b.title = soup.title.string
        db.session.add(b)
        db.session.commit()
        flash("New bookmark %s added" % (b.title), category="info")
        return redirect(url_for("index"))
    return render_template("new.html", title="New", form=form)
Example #50
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 #51
0
def new(request):
    if request.method != 'POST':
        return redirect('/')
    
    user = get_object_or_404(User, id=request.session.get('id', None))
    item = get_object_or_404(Item, id=request.POST.get('item', None))

    form = BookmarkForm(request.POST)
    if form.is_valid():
        # lists = request.POST.getlist('lists');
        list = request.POST.get('list', None)
        url  = request.POST.get('url', None)

        # 如果文本框和item的url不一致说明用户修改过url 所以跳到404页面
        if item.url != url:
            raise Http404
            # return render(request, 'debug.html', {'debug': [item.url, url]})

        l = get_object_or_404(List, id=list)

        private = request.POST.get('private', None)
        if private:
            pvalue = 1
        else:
            pvalue = 0

        d = form.save(commit=False)
        d.item = item
        d.private = pvalue
        d.user = user
        d.list = l
        d.url = item.url
        d.save()

        #更新有多少用户收藏了这个书签
        item.favorites = item.bookmark_set.exclude(private=1).count()
        item.save()

        #更新list bookmark的数量
        l.bookmarks = Bookmark.objects.filter(user=user, list=list).count()
        l.save()
        user.update_bookmarks()
        return redirect('/home/')
    
    lists = user.list_set.all()
    return render(request, 'bookmark/new.html', {'form': form, 'lists': lists, 'item': item})
Example #52
0
def update(request, bookmark_id):
    try:
        bookmark = Bookmark.objects.get(id=bookmark_id)
    except Bookmark.DoesNotExist:
        raise Http404

    if request.method == 'POST': # If the form has been submitted...
        form = BookmarkForm(request.POST, instance=bookmark)
        if form.is_valid(): # All validation rules pass
            bookmark = form.save()
            return HttpResponseRedirect(reverse('bookmark_index')) # Redirect after POST
    else:
        form = BookmarkForm(instance=bookmark)

    return render_to_response('update.html',
        RequestContext(request, {
            'form': form,
            }))
Example #53
0
def edit_bookmark(request, id):
    bookmark = get_object_or_404(Bookmark, id=id)
    if request.method == "POST":
        form = BookmarkForm(user=request.user, data=request.POST, instance=bookmark)
        if form.is_valid():
            form.save()
            if not request.is_ajax():
                messages.success(request, 'Bookmark updated')
                if request.POST.get('next'):
                    return HttpResponseRedirect(request.POST.get('next'))
            return HttpResponse('Saved')
    else:
        form = BookmarkForm(user=request.user, instance=bookmark)
    return render_to_response('admin_tools/menu/form.html',
               RequestContext(request, {
        'form': form,
        'title': 'Edit Bookmark',
    }))
Example #54
0
def add():
    form = BookmarkForm()
    if form.validate_on_submit():
        # time_of_day = form.time_of_day.data
        food_word_1 = form.food_word_1.data
        food_word_2 = form.food_word_2.data
        food_word_3 = form.food_word_3.data
        amount_1 = form.amount_1.data
        amount_2 = form.amount_2.data
        amount_3 = form.amount_3.data
        weather = form.weather.data
        mood = form.mood.data
        bm = Bookmark(user=current_user, food_word_1=food_word_1, food_word_2=food_word_2, food_word_3=food_word_3, amount_1=amount_1, amount_2=amount_2, amount_3=amount_3, weather=weather, mood=mood)
        db.session.add(bm)
        db.session.commit()
#        flash("Stored '{}'".format(food_word_1, food_word_2, food_word_3 ))
        return redirect(url_for('index'))
    return render_template('add.html', form=form)
Example #55
0
def edit_bookmark(request, bookmark_id):
    bookmark = get_object_or_404(Bookmark, id=bookmark_id)
    form = BookmarkForm(initial={
        'address': bookmark.address,
        'title': bookmark.title,
        'labels': labels_to_str(bookmark.labels.all()),
        'notes': bookmark.notes,
    })
    if request.method == 'POST':
        form = BookmarkForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            bookmark.title = data['title']
            bookmark.address = data['address']
            bookmark.notes = data['notes']
            bookmark.labels = str_to_labels(data['labels'])
            bookmark.save()
            return HttpResponseRedirect(reverse("bookmarks.views.view_bookmarks", args=[]))
    return render_to_response('bookmarks/bookmark_form.html', 
        {'form': form, 'bookmark': bookmark}, context_instance=RequestContext(request))
Example #56
0
    if bookmark.user.id != request.session.get('id', None):
        raise Http404

    if bookmark.item is None:
        try:
            item = Item.objects.get(url=bookmark.url)
        except Exception, e:
            title = get_bookmark_title(bookmark.url)
            item = Item(url=bookmark.url, title=title.encode('utf-8'), favorites=1)
            item.save()
        bookmark.item = item
        bookmark.save()
        item.favorites = item.bookmark_set.count()
        item.save()

    form = BookmarkForm(initial={'title':bookmark.title})

    if request.method == 'POST':
        form = BookmarkForm(request.POST)
        if form.is_valid():
            list = get_object_or_404(List, id=request.POST.get('list', None))

            if bookmark.item.url != request.POST.get('url', None) or bookmark.item.id != int(request.POST.get('item', None)):
                raise Http404

            bookmark.title = request.POST.get('title')
            private = request.POST.get('private', None)
            if private:
                pvalue = 1
            else:
                pvalue = 0