Пример #1
0
 def test_validates_empty_fields(self):
     """Tests to check that empty fields are not submitted"""
     form = StoryForm(story_title="",
                      tagline="Did you hear that?",
                      category="",
                      content="Some long story here")
     self.assertFalse(form.validate())
def stories():
	form = StoryForm()

	if form.validate_on_submit() :
		story = Stories(body=form.story.data , author=current_user)
		db.session.add(story)
		db.session.commit()
		flash('your post is on live')
		return redirect(url_for('stories'))

	page = request.args.get('page', 1, type=int )

	stories = Stories.query.order_by(Stories.timeStamp.desc()).paginate( page, app.config['POSTS_PER_PAGE'],False)	

	if stories.has_next :
		next_url = url_for('stories' , page=stories.next_num)
	else :
		next_url = None

	if stories.has_prev :
		prev_url = url_for('stories' , page=stories.prev_num)
	else :
		prev_url = None

	return render_template('/sections/stories.html' , posts=stories.items , title='stories' , next_url=next_url , prev_url=prev_url , form=form)
Пример #3
0
 def test_validates_story_form_data(self):
     """Test to check that all fields are filled"""
     form = StoryForm(story_title="The Whisper",
                      tagline="Did you hear that?",
                      category="Fiction",
                      content="Some long story here")
     self.assertTrue(form.validate())
Пример #4
0
def newstory(request):
    if request.user.is_authenticated():
        elem= {
        'title':'Ny Story',
        }
        if request.method=='POST':
            story_form=StoryForm(request.POST)
            elem.update({'story_form':story_form,})

            if story_form.is_valid():
                print story_form.cleaned_data
                title = request.POST['title']
                length = request.POST['length']
                if request.POST.get('availability'):   
                    availability = request.POST['availability']
                else:
                    availability="Public"
                language=request.POST['language']
                category=request.POST['category']

                newstory=Story(created=datetime.datetime.now(),creator=request.user,title=title,length=length,availability=availability,language=language,category=category)
                newstory.save()
                return HttpResponseRedirect('/home')
            else:
                print "invalid story_form"
        else:
            story_form=StoryForm()
            elem.update({'story_form':story_form,})
        return render_to_response("newstory.html",elem,context_instance=RequestContext(request))
    else:
        return HttpResponseRedirect("/")
Пример #5
0
def timing():
    storyform = StoryForm()

    if storyform.validate_on_submit():
        session['story'].start_time = storyform.time.data
        return redirect(url_for('events'))

    return render_template("timing.html", storyform=storyform)
Пример #6
0
def index():
    storyform = StoryForm()

    if storyform.validate_on_submit():
        session['story'].start_location = storyform.location.data
        return redirect(url_for("timing"))

    return render_template("index.html", storyform=storyform)
Пример #7
0
 def test_validates_empty_fields(self):
     """Tests to check that empty fields are not submitted"""
     form = StoryForm(
         story_title="",
         tagline="Did you hear that?",
         category="",
         content="Some long story here"
     )
     self.assertFalse(form.validate())
Пример #8
0
 def test_validates_story_form_data(self):
     """Test to check that all fields are filled"""
     form = StoryForm(
         story_title="The Whisper",
         tagline="Did you hear that?",
         category="Fiction",
         content="Some long story here"
     )
     self.assertTrue(form.validate())
Пример #9
0
def events():
    storyform = StoryForm()

    if storyform.validate_on_submit():
        if storyform.event_name.data not in ['Stop', 'stop', 'STOP']:
            session['story'].events.append(storyform.event_name.data)
            return render_template("events.html", storyform=storyform)
        else:
            return redirect(url_for("finale"))
Пример #10
0
def story(id: Any) -> Any:

    session = new_session()
    story = session.query(ShortStory)\
        .filter(ShortStory.id == id)\
        .first()

    editions = session.query(Edition)\
                      .join(Part)\
                      .filter(Part.shortstory_id == id)\
                      .filter(Part.edition_id == Edition.id)\
                      .all()

    works = session.query(Work)\
                   .join(Part)\
                   .filter(Part.shortstory_id == id)\
                   .filter(Part.work_id == Work.id)\
                   .all()

    authors = session.query(Person)\
                     .distinct(Person.id)\
                     .join(Contributor, Contributor.role_id == 0)\
        .filter(Contributor.person_id == Person.id)\
        .filter(Person.id == Contributor.person_id)\
        .join(Part)\
        .filter(Contributor.part_id == Part.id,
                Part.shortstory_id == id)\
        .all()

    form = StoryForm(request.form)

    if request.method == 'GET':
        form.id.data = story.id
        form.title.data = story.title
        form.orig_title.data = story.orig_title
        form.pubyear.data = story.pubyear
    elif form.validate_on_submit():
        story.title = form.title.data
        story.orig_title = form.orig_title.data
        story.pubyear = form.pubyear.data
        session.add(story)
        session.commit()
    else:
        app.logger.error('Errors: {}'.format(form.errors))
        print(f'Errors: {form.errors}')

    return render_template('story.html',
                           id=id,
                           story=story,
                           editions=editions,
                           works=works,
                           authors=authors,
                           form=form)
Пример #11
0
def write_story(username):
    """
    Allows Author to write a new story
    :return new story template
    """
    story_form = StoryForm(request.form)
    user = current_user
    if request.method == "POST":
        if story_form.validate_on_submit():
            story = Story(title=story_form.story_title.data, tagline=story_form.tagline.data,
                          category=story_form.category.data, content=story_form.content.data,
                          author_id=user.id)
            db.session.add(story)
            db.session.commit()
            return redirect(url_for('dashboard.user_dashboard', username=user.full_name))
    return render_template("dashboard.new_story.html", user=user, story_form=story_form)
Пример #12
0
def newstory(request):
    if request.user.is_authenticated():
        elem = {
            'title': 'Ny Story',
        }
        if request.method == 'POST':
            story_form = StoryForm(request.POST)
            elem.update({
                'story_form': story_form,
            })

            if story_form.is_valid():
                print story_form.cleaned_data
                title = request.POST['title']
                length = request.POST['length']
                if request.POST.get('availability'):
                    availability = request.POST['availability']
                else:
                    availability = "Public"
                language = request.POST['language']
                category = request.POST['category']

                newstory = Story(created=datetime.datetime.now(),
                                 creator=request.user,
                                 title=title,
                                 length=length,
                                 availability=availability,
                                 language=language,
                                 category=category)
                newstory.save()
                return HttpResponseRedirect('/home')
            else:
                print "invalid story_form"
        else:
            story_form = StoryForm()
            elem.update({
                'story_form': story_form,
            })
        return render_to_response("newstory.html",
                                  elem,
                                  context_instance=RequestContext(request))
    else:
        return HttpResponseRedirect("/")
Пример #13
0
def write_story(username):
    """
    Allows Author to write a new story
    :return new story template
    """
    story_form = StoryForm(request.form)
    user = current_user
    if request.method == "POST":
        if story_form.validate_on_submit():
            story = Story(title=story_form.story_title.data,
                          tagline=story_form.tagline.data,
                          category=story_form.category.data,
                          content=story_form.content.data,
                          author_id=user.id)
            db.session.add(story)
            db.session.commit()
            return redirect(
                url_for('dashboard.user_dashboard', username=user.full_name))
    return render_template("dashboard.new_story.html",
                           user=user,
                           story_form=story_form)
Пример #14
0
def work(workid: Any) -> Any:
    """ Popup has a form to add authors. """
    stories: List[Any] = []
    session = new_session()
    work = session.query(Work)\
                  .filter(Work.id == workid)\
                  .first()
    authors = people_for_book(session, workid, 'A')
    bookseries = session.query(Bookseries)\
                        .join(Work)\
                        .filter(Bookseries.id == work.bookseries_id,
                                Work.id == workid)\
                        .first()
    types: List[str] = [''] * 4
    types[work.type] = 'checked'
    stories = session.query(ShortStory)\
        .join(Part)\
        .filter(Part.shortstory_id == ShortStory.id)\
        .filter(Part.work_id == workid)\
        .group_by(Part.shortstory_id)\
        .all()
    form = WorkForm(request.form)
    form_story = StoryForm(request.form)
    prev_book = None
    next_book = None
    if bookseries:
        books_in_series = session.query(Work)\
                                 .filter(Work.bookseries_id == bookseries.id)\
                                 .order_by(Work.bookseriesorder, Work.pubyear)\
                                 .all()
        for idx, book in enumerate(books_in_series):
            if book.id == int(workid):
                if len(books_in_series) > 1:
                    if idx == 0:
                        # First in series
                        next_book = books_in_series[1]
                    elif idx == len(books_in_series) - 1:
                        # Last in series
                        prev_book = books_in_series[-2]
                    else:
                        prev_book = books_in_series[idx-1]
                        next_book = books_in_series[idx+1]
                    break

    if request.method == 'GET':
        form.id.data = work.id
        form.title.data = work.title
        form.subtitle.data = work.subtitle
        form.orig_title = work.orig_title
        form.pubyear = work.pubyear
        form.bookseriesnum.data = work.bookseriesnum
        form.bookseriesorder.data = work.bookseriesorder
        form.misc.data = work.misc
        form.description.data = work.description
        form.source.data = work.imported_string
    elif form.validate_on_submit():
        work.title = form.title.data
        work.subtitle = form.subtitle.data
        work.orig_title = form.orig_title.data
        work.pubyear = form.pubyear.data
        work.bookseriesnum = form.bookseriesnum.data
        work.bookseriesorder = form.bookseriesorder.data
        work.misc = form.misc.data
        work.description = form.description.data
        work.imported_string = form.source.data
        work.type = form.type.data
        session.add(work)
        session.commit()
        log_change(session, 'Work', work.id)
    else:
        app.logger.error('Errors: {}'.format(form.errors))
        print(f'Errors: {form.errors}')

    title = f'SuomiSF - {work.author_str}: {work.title}'

    return render_template('work.html', work=work,
                           form=form,
                           prev_book=prev_book, next_book=next_book,
                           types=types,
                           title=title)