def feed(): form = FeedForm() if form.validate_on_submit(): feed = models.Feed(url=form.url.data, title=form.title.data) db_session.add(feed) db_session.commit() return redirect('/') return render_template('feed.html', form=form)
def feed(): form = FeedForm() if form.validate_on_submit(): feed = models.Feed(url=form.url.data,title=form.title.data) db_session.add(feed) db_session.commit() return redirect('/') return render_template('feed.html',form=form)
def feed(id=None, page=1): if 'edit' in request.values: edit = True else: edit = False if id is None: f = Feed(name='New Feed') g.user.feeds.append(f) s = Subscription(subscriber=g.user, feed=f) db.session.add(f) db.session.add(s) db.session.commit() edit = True return redirect(url_for('feed', id=f.id, edit=True)) else: f = Feed.query.filter(Feed.id == id).first() s = Subscription.query.filter(and_(Subscription.feed_id == id, Subscription.user_id == g.user.id)).first() form = FeedForm(request.form, f, subscription=s) if form.validate_on_submit(): edit = True if 'Delete' in request.values: if f is not None: # not sure if this is necessary (and will need to revise once it's possible to share feeds) for s in Subscription.query.filter(Subscription.feed_id == f.id): db.session.delete(s) db.session.delete(f) db.session.commit() return redirect(url_for('index')) print 'validated' f = form.populate_obj(f) s.enable_email = form.enable_email.data s.email_frequency = form.email_frequency.data db.session.add(f) db.session.add(s) db.session.commit() flash('Feed updated.') return redirect(url_for('feed', id=f.id, edit=edit)) else: if f is not None: articles = f.feed_articles().paginate(page, ARTICLES_PER_PAGE, False) if articles.total == 0: edit = True form.enable_email.data = form.subscription.enable_email form.email_frequency.data = form.subscription.email_frequency else: articles = None edit = True if f is not None: feed_authors = f.authors.order_by(Author.lastname) return render_template('feed.html', feed=f, form=form, articles=articles, feed_authors=feed_authors, user=g.user, edit=edit)
def add_feed(request): if request.method == "POST": form = FeedForm(data=request.POST) if form.is_valid() and not Feed.objects.filter(url=form.cleaned_data["url"]).all(): event = form.save() return HttpResponse("OK") # return HttpResponseRedirect("%s" % post.get_nice_url()) else: form = FeedForm() return HttpResponse("0")
def add_feed(request): if request.method == 'POST': form = FeedForm(data=request.POST) if form.is_valid(): event = form.save() return HttpResponse('OK') #return HttpResponseRedirect("%s" % post.get_nice_url()) else: form = FeedForm() return HttpResponse('0')
def edit_feed(feed_id): record = FeedRecord.query.filter(FeedRecord.id == feed_id).first() feed_form = FeedForm(request.form, record) if request.method == 'POST': feed_form.populate_obj(record) if 'key' in request.form: record.quant = int(request.form['key']) db_session.add(record) db_session.commit() flash(u'记录编辑成功!') return redirect(url_for('.feed')) else: return render_template('feed/edit.html', feed_form=feed_form)
def feed(request): '''This view will hold the feed''' # Creating FeedForm object feedForm = FeedForm() # Creating title for the new feed page. title = 'New Feed' # The below if statement deals with POST data sent to the FeedForm form. if request.POST: feedForm = FeedForm(request.POST) # Checking the validity of the form if feedForm.is_valid(): # Saving the submitted data to the approriate tables via the save method. feedForm.save() # Success message string that is sent to the template below to confirm that the write to the database was successful. success_message = 'SUCCESS' # Creating first context this is a total success of form. context = { 'title': title, 'feedForm':feedForm, 'success_message': success_message } # This return is issued if no post data was made return render(request,'feeds/feed.html',context) # Default context. This is an empty forum. context = { 'title': title, 'feedForm':feedForm } #This return is issued if no post data was made return render(request,'feeds/feed.html',context)
def feed2(): form = FeedForm() feed = request.form['body'] mongo.db.feed.insert({'feedback': feed}) message = "Your feedback has been submitted to us. We will get back shortly" return render_template('feed.html', form=form, mes=message)
def feed(): form = FeedForm() return render_template('feed.html', form=form)
def feed(id=None, page=1): if 'edit' in request.values: edit = True else: edit = False if id is None: f = Feed(name='New Feed') g.user.feeds.append(f) s = Subscription(subscriber=g.user, feed=f) db.session.add(f) db.session.add(s) db.session.commit() edit = True return redirect(url_for('feed', id=f.id, edit=True)) else: f = Feed.query.filter(Feed.id == id).first() s = Subscription.query.filter( and_(Subscription.feed_id == id, Subscription.user_id == g.user.id)).first() form = FeedForm(request.form, f, subscription=s) if form.validate_on_submit(): edit = True if 'Delete' in request.values: if f is not None: # not sure if this is necessary (and will need to revise once it's possible to share feeds) for s in Subscription.query.filter( Subscription.feed_id == f.id): db.session.delete(s) db.session.delete(f) db.session.commit() return redirect(url_for('index')) print 'validated' f = form.populate_obj(f) s.enable_email = form.enable_email.data s.email_frequency = form.email_frequency.data db.session.add(f) db.session.add(s) db.session.commit() flash('Feed updated.') return redirect(url_for('feed', id=f.id, edit=edit)) else: if f is not None: articles = f.feed_articles().paginate(page, ARTICLES_PER_PAGE, False) if articles.total == 0: edit = True form.enable_email.data = form.subscription.enable_email form.email_frequency.data = form.subscription.email_frequency else: articles = None edit = True if f is not None: feed_authors = f.authors.order_by(Author.lastname) return render_template('feed.html', feed=f, form=form, articles=articles, feed_authors=feed_authors, user=g.user, edit=edit)