def story(id): st = Story.query.filter_by(id=id).first_or_404() temp_st = Story() temp_st.title = str(st.title) temp_st.slug = str(st.slug) print st.title print "is the title before POST" form = StoryForm(obj=st) form.populate_obj(st) if request.method == "POST": print temp_st.title print "is temp_st.title" st.text = form.text.data st.title = temp_st.title st.slug = temp_st.slug print st.title print "is the title after POST" if request.form.get('submit_button')== "Save": flash("Story saved.", 'success') if request.form.get('submit_button')== "Translate": flash("Story Ready To Translate.", 'success') st.ready_to_translate = True db.session.add(st) db.session.commit() return render_template("stories/story.html", story=st, form=form)
def create_new_story(request): if request.method == "POST": # They attempted to create a story story_form = forms.NewStoryForm(request.POST) frag_form = forms.AddFragmentForm(request.POST) if story_form.is_valid() and frag_form.is_valid(): # Store the new story and the fragment story = Story( name = story_form.cleaned_data['story_name'], last_update_date = datetime.datetime.now() ) # Give 'er a slug! story.slug = slugify(story.name, instance=story) story.save() story.add_fragment(frag_form.cleaned_data['fragment_text'], request.user) return HttpResponseRedirect(reverse('story_detail', kwargs={'slug':story.slug})) else: # Return a blank form page story_form = forms.NewStoryForm() frag_form = forms.AddFragmentForm() return render_to_response("stories/add_new_story.html", RequestContext(request, { 'story_form':story_form, 'frag_form':frag_form, }) )