diff --git a/app.py b/app.py index ac97528..5b550e5 100644 --- a/app.py +++ b/app.py @@ -54,7 +54,7 @@ class Story(db.Model): is_tree = db.Column(db.Boolean, default=False) def text_abstract(self, limit=200): - return self.text[:limit] + ("..." if len(self.text) > limit else "") + return (C.BEGIN_TEXT[self.id - 1] + self.text)[:limit] + ("..." if len(C.BEGIN_TEXT[self.id - 1] + self.text) > limit else "") class Paragraph(db.Model): @@ -188,6 +188,7 @@ def story(story_id): paragraph_part = Paragraph.query.filter_by( story_id=story_id, is_chosen=True, is_hidden=False ).all() + begin_text = C.BEGIN_TEXT[story_id - 1] # story_id is 1-based sort_by = request.args.get('sort_by', 'time') diff --git a/init_data.py b/init_data.py index a812390..0da4a25 100644 --- a/init_data.py +++ b/init_data.py @@ -3,63 +3,53 @@ from app import Story, Paragraph, db db.drop_all() db.create_all() -BEGIN_WORDS = [ +AVATARS = [ ( "候选" + "甲", - "男生。某传统工科。那年他收到了华清大学的录取通知书……", "boy1.jpg" ), ( "候选" + "乙", - "女生。商科和管理学科。那年她收到了华清大学的录取通知书……", "girl1.jpg" ), ( "候选" + "丙", - "男生。艺术特长生。那年他收到了华清大学的录取通知书……", "boy2.jpg" ), ( "候选" + "丁", - "女生。某热门工科。那年她收到了华清大学的录取通知书……", "girl2.jpg" ), ( "候选" + "戊", - "男生。理科。那年他收到了华清大学的录取通知书……", "boy3.jpg" ), ( "候选" + "己", - "女生。不喜欢打扮。那年她收到了华清大学的录取通知书……", "girl3.jpg" ), ( "候选" + "庚", - "男生。喜欢穿风衣。那年他收到了华清大学的录取通知书……", "boy4.jpg" ), ( "候选" + "辛", - "女生。出门一般都戴帽子。那年她收到了华清大学的录取通知书……", "girl4.jpg" ), ( "候选" + "壬", - "猫猫。那年它不小心从西门溜进了华清大学……", "cat.jpg" ), ( "候选" + "癸", - "留学生。那年华清大学的录取通知书漂洋过海寄到了家里……", "neutral.jpg" ), ] -for idx, (title, text, avatar) in zip(range(1, 11), BEGIN_WORDS): - s = Story(id=idx, title=title, text=text, tail=idx, is_tree=(idx == 10), +for idx, (title, avatar) in zip(range(1, 11), AVATARS): + s = Story(id=idx, title=title, text='', tail=idx, is_tree=(idx == 10), avatar="/ordinary/static/img/" + avatar) - p = Paragraph(id=idx, text=text, story_id=idx, is_chosen=True, + p = Paragraph(id=idx, text='', story_id=idx, is_chosen=True, author="初始设定") db.session.add(s) db.session.add(p) diff --git a/templates/story.html b/templates/story.html index fe4a54f..277a806 100644 --- a/templates/story.html +++ b/templates/story.html @@ -38,7 +38,7 @@

{{story.title}}

-

{{paragraph_part[0].text}}

+

{{begin_text}}


{% for p in paragraph_part[1:] %}