Skip to content

Commit 5003f49

Browse files
author
root
committed
1. 在 员工的页面中显示 两周的周报内容;2. 在 后台周报中 增加 周次的时间查询功能;3. 周报导出时候对 h5的页面格式进行转化;4. 修复填写周报之后未对上周周报进行保存的问题
1 parent 0085ddd commit 5003f49

File tree

9 files changed

+112
-9
lines changed

9 files changed

+112
-9
lines changed

deploy/app/main/views.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010
from . import main
1111
from .. import admin, db
1212
from ..models import Permission, User, Role, Report, Department
13-
from ..utils import permission_required, is_allowed_file
13+
from ..utils import permission_required, is_allowed_file, clean_html
1414
from sqlalchemy.exc import OperationalError
1515

16-
1716
@main.route('/', methods=['GET', 'POST'])
1817
def index():
1918
# check if the database is initialized.
@@ -113,6 +112,7 @@ class ReportAdminView(WeeklyReportModelView):
113112
column_list = ('author', 'department', 'year', 'week_count', 'last_content',
114113
'content', 'created_at')
115114
column_default_sort = ('created_at', True)
115+
column_searchable_list = ('week_count',)
116116
form_columns = ['created_at', 'week_count', 'year', 'content']
117117
list_template = '/admin/model/report_list_template.html'
118118
can_edit = True
@@ -132,12 +132,43 @@ class ReportAdminView(WeeklyReportModelView):
132132

133133
def date_format(view, value):
134134
return value.strftime('%Y-%m-%d')
135+
136+
def author_format(v, c, m, p):
137+
return str(m.author)
138+
139+
def department_format(v, c, m, p):
140+
return str(m.department)
141+
142+
def format_last_content(v, c, m, p):
143+
if m.last_content:
144+
return clean_html(m.last_content)
145+
146+
return ''
147+
148+
def format_content(v, c, m, p):
149+
if m.content:
150+
return clean_html(m.content)
151+
152+
return ''
153+
154+
def format_created_at(v, c, m, p):
155+
return m.created_at.strftime('%Y-%m-%d')
135156

136157
REPORT_FORMATTERS = dict(typefmt.BASE_FORMATTERS)
137158
REPORT_FORMATTERS.update({
138-
date: date_format
159+
date: date_format,
139160
})
140161
column_type_formatters = REPORT_FORMATTERS
162+
163+
EXPORT_REPORT_FORMATTERS = dict(typefmt.BASE_FORMATTERS)
164+
EXPORT_REPORT_FORMATTERS.update({
165+
"author": author_format,
166+
"department": department_format,
167+
"last_content": format_last_content,
168+
"content": format_content,
169+
"created_at":format_created_at,
170+
})
171+
column_formatters_export = EXPORT_REPORT_FORMATTERS
141172

142173

143174
admin.add_view(UserAdminView(User, db.session, name='用户'))

deploy/app/models.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ def insert_roles():
4646

4747
def __str__(self):
4848
return self.name
49+
50+
def __repr__(self):
51+
return self.name
4952

5053

5154
class Department(db.Model):
@@ -72,6 +75,9 @@ def delete_departments():
7275

7376
def __str__(self):
7477
return self.name
78+
79+
def __repr__(self):
80+
return self.name
7581

7682

7783
class User(db.Model, UserMixin):
@@ -134,6 +140,9 @@ def is_authenticated(self):
134140

135141
def __str__(self):
136142
return self.username
143+
144+
def __repr__(self):
145+
return self.username
137146

138147

139148
class AnonymousUser(AnonymousUserMixin):
@@ -195,6 +204,10 @@ def get_last_report(author_id, week_count):
195204
def __str__(self):
196205
return 'Posted by {} at {}'.format(
197206
User.query.get(self.author_id).email, self.created_at)
207+
208+
def __repr__(self):
209+
return 'Posted by {} at {}'.format(
210+
User.query.get(self.author_id).email, self.created_at)
198211

199212

200213
@login_manager.user_loader

deploy/app/report/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def write():
3939
else:
4040
report = Report(
4141
content=form.body.data.replace('<br>', ''),
42+
last_content=form.last_content.data.replace('<br>', ''),
4243
author_id=current_user.id,
4344
week_count=get_week_count(),
4445
year=datetime.today().year)

deploy/app/templates/admin/model/report_list_template.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353

5454
{% if search_supported %}
5555
<li>
56+
{{_('Week Count')}}
5657
{{ model_layout.search_form() }}
5758
</li>
5859
{% endif %}

deploy/app/templates/report/read_crew.html

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,31 @@
2626
<a rel="tag" class="post-tag">{{_('Department')}}:{{ report.department.name }}</a>
2727
<a rel="tag" class="post-tag">{{_('Week Count')}}:{{ report.week_count }}</a>
2828
<a rel="tag" class="post-tag">{{_('Year')}}:{{ report.year }}</a>
29-
{{report.content|safe}}
29+
<table class="table table-striped table-bordered table-hover model-list">
30+
<thead>
31+
<tr>
32+
<th class="column-header col-last_content">
33+
{{_('Last Week')}}
34+
</th>
35+
36+
<th class="column-header col-content">
37+
{{_('Current Week')}}
38+
</th>
39+
</tr>
40+
</thead>
41+
<tbody><tr>
42+
<td class="col-last_content">
43+
{{report.last_content|safe}}
44+
</td>
45+
46+
<td class="col-content">
47+
{{report.content|safe}}
48+
</td>
49+
50+
</tr>
51+
</tbody>
52+
</table>
53+
3054
<hr>
3155
</div>
3256
{% endfor %}

deploy/app/templates/report/write.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515

1616
{% block page_content %}
17+
<div class="alert alert-warning">
18+
请注意填写周报的日期
19+
</div>
1720
<h3>第{{ week_count }}周({{start_at}}至{{end_at}})工作周报</h3>
1821
<form class="form form-inline" method="post" role="form">
1922
{{ form.csrf_token }}

deploy/app/translations/zh_Hans_CN/LC_MESSAGES/messages.po

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ msgstr "点击重置密码"
241241

242242
#: templates/report/read.html:15 templates/report/read_crew.html:28
243243
#: templates/report/read_department.html:26
244+
#: templates/admin/model/report_list_template.html:56
244245
msgid "Week Count"
245246
msgstr "周次"
246247

@@ -256,3 +257,11 @@ msgstr "编辑"
256257
#: auth/views.py:25
257258
msgid "Account or password is wrong"
258259
msgstr "邮箱或密码错误"
260+
261+
#: templates/report/read_crew.html:33
262+
msgid "Last Week"
263+
msgstr "上周"
264+
265+
#: templates/report/read_crew.html:37
266+
msgid "Current Week"
267+
msgstr "本周"

deploy/app/utils.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from functools import wraps
44
from flask import abort
55
from flask_login import current_user
6+
import re
67

78

89
def permission_required(permission):
@@ -48,3 +49,24 @@ def get_last_week_content(last_week_content):
4849
if content_index != -1:
4950
return last_week_content[content_index+31:]
5051
return ""
52+
53+
def clean_html(html):
54+
"""
55+
Remove HTML markup from the given string.
56+
:param html: the HTML string to be cleaned
57+
:type html: str
58+
:rtype: str
59+
"""
60+
61+
# First we remove inline JavaScript/CSS:
62+
cleaned = re.sub(r"(?is)<(script|style).*?>.*?(</\1>)", "", html.strip())
63+
# Then we remove html comments. This has to be done before removing regular
64+
# tags since comments can contain '>' characters.
65+
cleaned = re.sub(r"(?s)<!--(.*?)-->[\n]?", "", cleaned)
66+
# Next we can remove the remaining tags:
67+
cleaned = re.sub(r"(?s)<.*?>", " ", cleaned)
68+
# Finally, we deal with whitespace
69+
cleaned = re.sub(r"&nbsp;", " ", cleaned)
70+
cleaned = re.sub(r" ", " ", cleaned)
71+
cleaned = re.sub(r" ", " ", cleaned)
72+
return cleaned.strip()

deploy/config.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@
3535
)
3636

3737
DEFAULT_CONTENT = "<p><strong>1、上周计划完成情况:</strong></p><ol><li></li></ol>" \
38-
"<p>&nbsp;<strong>2、计划外工作:</strong></p><ol><li></li></ol>" \
39-
"<p>&nbsp;<strong>3、协助运维工作: </strong></p><ol><li></li></ol>" \
40-
"<p>&nbsp;<strong>4、重要问题:</strong></p><ol><li></li></ol>" \
41-
"<p>&nbsp;<strong>5、持续未处理解决的事情:</strong></p><ol><li></li></ol>" \
42-
"<p>&nbsp;<strong id=\"next_week\">1、下周计划:</strong></p><ol><li></li></ol>"
38+
"<p>&nbsp;<strong>2、计划外工作(包含协助运维工作):</strong></p><ol><li></li></ol>" \
39+
"<p>&nbsp;<strong>3、重要问题:</strong></p><ol><li></li></ol>" \
40+
"<p>&nbsp;<strong>4、持续未处理解决的事情:</strong></p><ol><li></li></ol>" \
41+
"<p>&nbsp;<strong id=\"next_week\">5、下周计划:</strong></p><ol><li></li></ol>"
4342

4443

4544
#SQLALCHEMY_DATABASE_URI = 'postgresql://postgres:postgres@db/wr_prd'

0 commit comments

Comments
 (0)