Browse Source

move begin text into config

pull/1/head
namasikanam 2 years ago
parent
commit
2b8c09eaf6
3 changed files with 7 additions and 16 deletions
  1. +2
    -1
      app.py
  2. +4
    -14
      init_data.py
  3. +1
    -1
      templates/story.html

+ 2
- 1
app.py View File

@ -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')

+ 4
- 14
init_data.py View File

@ -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)

+ 1
- 1
templates/story.html View File

@ -38,7 +38,7 @@
<div class="part1 col-md-6">
<div class="story-box qbox part-box">
<h1>{{story.title}}</h1>
<p class="story-text" title="{{paragraph_part[0].author}}, {{paragraph_part[0].create_at}}, {{paragraph_part[0].like_num}}">{{paragraph_part[0].text}}</p>
<p class="story-text" title="{{paragraph_part[0].author}}, {{paragraph_part[0].create_at}}, {{paragraph_part[0].like_num}}">{{begin_text}}</p>
<img src="{{story.avatar}}" style="width: 80%">
<hr>
{% for p in paragraph_part[1:] %}

Loading…
Cancel
Save