Skip to content

Commit 210c988

Browse files
committed
内网更新
1 parent ca35e5f commit 210c988

File tree

14 files changed

+641
-82
lines changed

14 files changed

+641
-82
lines changed

LICENSE

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
MIT License
22

3+
Copyright (c) 2017 Grey Li
4+
35
Permission is hereby granted, free of charge, to any person obtaining a copy
46
of this software and associated documentation files (the "Software"), to deal
57
in the Software without restriction, including without limitation the rights

README.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# 影像数据管理工具
2-
dicom数据队列下载工具,账号注册,下载任务提交到审批
2+
33
*医学影像科研数据管理更便捷*
44
以下提供了三种部署方式
55
## 用pipenv构建
@@ -22,8 +22,7 @@ $ flask run
2222
```
2323
pip install -r requirements.txt
2424
set FLASK_APP=datacenter
25-
flask initdb
26-
flask init
25+
flask forge
2726
```
2827

2928
## docker 运行
@@ -32,10 +31,10 @@ flask init
3231
cd center
3332
docker build -t webenv:2.01 .
3433
```
35-
运行,挂载目录必须是完整路径
34+
运行
3635
```
3736
cd ..
38-
docker run -v ~/center:/app -p 8000:8000 -p 10001:10001 -i -t webenv:2.01 python run.py
37+
docker run -v /home/public/liuweipeng/datacenter2/center/:/app -v /home/pictures/WinShare/DcmData/:/app/downloads -v /etc/localtime:/etc/localtime:ro -p 8080:8000 -p 10002:10002 -i -t webenv:2.01 python run.py
3938
```
4039

4140

datacenter/__init__.py

+38-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
from datacenter.blueprints.main import main_bp
1818
from datacenter.blueprints.user import user_bp
1919
from datacenter.extensions import bootstrap, db, login_manager, mail, dropzone, moment, whooshee, avatars, csrf, ckeditor
20-
from datacenter.models import Role, User, Permission, Tasks, StatusDict, AEDict
20+
from datacenter.models import Role, User, Photo, Tag, Follow, Notification, Comment, Collect, Permission
21+
from datacenter.models import Tasks, StatusDict, AEDict
2122
from datacenter.settings import config
2223

2324

@@ -63,7 +64,9 @@ def register_blueprints(app):
6364
def register_shell_context(app):
6465
@app.shell_context_processor
6566
def make_shell_context():
66-
return dict(db=db, User=User)
67+
return dict(db=db, User=User, Photo=Photo, Tag=Tag,
68+
Follow=Follow, Collect=Collect, Comment=Comment,
69+
Notification=Notification)
6770

6871

6972
def register_template_context(app):
@@ -118,17 +121,46 @@ def initdb(drop):
118121

119122
@app.cli.command()
120123
def init():
121-
"""Initialize dict."""
124+
"""Initialize Albumy."""
122125
click.echo('Initializing the database...')
123126
db.create_all()
124127

125128
click.echo('Initializing the roles and permissions...')
126129
Role.init_role()
127130

131+
click.echo('Done.')
132+
133+
@app.cli.command()
134+
# @click.option('--user', default=10, help='Quantity of users, default is 10.')
135+
# @click.option('--follow', default=30, help='Quantity of follows, default is 50.')
136+
# @click.option('--photo', default=30, help='Quantity of photos, default is 500.')
137+
# @click.option('--tag', default=20, help='Quantity of tags, default is 500.')
138+
# @click.option('--collect', default=50, help='Quantity of collects, default is 500.')
139+
# @click.option('--comment', default=100, help='Quantity of comments, default is 500.')
140+
# def forge(user, follow, photo, tag, collect, comment):
141+
# from datacenter.fakes import fake_admin, fake_comment, fake_follow, fake_photo, fake_tag, fake_user, fake_collect
142+
def forge():
143+
"""Generate dict."""
144+
db.drop_all()
145+
db.create_all()
146+
147+
Role.init_role()
148+
click.echo('Initialized the roles and permissions...')
128149
AEDict.init_aedict()
129150
click.echo('Initialized ae dict.')
130151
StatusDict.init_statusdict()
131152
click.echo('Initialized status dict.')
132-
click.echo('Done.')
133-
134-
153+
# fake_admin()
154+
# click.echo('Generating %d users...' % user)
155+
# fake_user(user)
156+
# click.echo('Generating %d follows...' % follow)
157+
# fake_follow(follow)
158+
# click.echo('Generating %d tags...' % tag)
159+
# fake_tag(tag)
160+
# click.echo('Generating %d photos...' % photo)
161+
# fake_photo(photo)
162+
# click.echo('Generating %d collects...' % photo)
163+
# fake_collect(collect)
164+
# click.echo('Generating %d comments...' % comment)
165+
# fake_comment(comment)
166+
# click.echo('Done.')

datacenter/blueprints/admin.py

+75-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,30 @@
1010
from datacenter.decorators import admin_required, permission_required
1111
from datacenter.extensions import db
1212
from datacenter.forms.admin import EditProfileAdminForm
13-
from datacenter.models import Role, User,Tasks
13+
from datacenter.models import Role, User, Tag, Photo, Comment, Tasks
1414
from datacenter.utils import redirect_back
1515

1616
admin_bp = Blueprint('admin', __name__)
1717

1818

19+
# @admin_bp.route('/')
20+
# @login_required
21+
# @permission_required('MODERATE')
22+
# def index():
23+
# user_count = User.query.count()
24+
# locked_user_count = User.query.filter_by(locked=True).count()
25+
# blocked_user_count = User.query.filter_by(active=False).count()
26+
# photo_count = Photo.query.count()
27+
# reported_photos_count = Photo.query.filter(Photo.flag > 0).count()
28+
# tag_count = Tag.query.count()
29+
# comment_count = Comment.query.count()
30+
# reported_comments_count = Comment.query.filter(Comment.flag > 0).count()
31+
# return render_template('admin/index.html', user_count=user_count, photo_count=photo_count,
32+
# tag_count=tag_count, comment_count=comment_count, locked_user_count=locked_user_count,
33+
# blocked_user_count=blocked_user_count, reported_comments_count=reported_comments_count,
34+
# reported_photos_count=reported_photos_count)
35+
36+
1937
@admin_bp.route('/profile/<int:user_id>', methods=['GET', 'POST'])
2038
@login_required
2139
@admin_required
@@ -90,6 +108,17 @@ def unlock_user(user_id):
90108
return redirect_back()
91109

92110

111+
@admin_bp.route('/delete/tag/<int:tag_id>', methods=['GET', 'POST'])
112+
@login_required
113+
@permission_required('MODERATE')
114+
def delete_tag(tag_id):
115+
tag = Tag.query.get_or_404(tag_id)
116+
db.session.delete(tag)
117+
db.session.commit()
118+
flash('Tag deleted.', 'info')
119+
return redirect_back()
120+
121+
93122
@admin_bp.route('/to_top/<int:task_id>', methods=['GET', 'POST'])
94123
@login_required
95124
@permission_required('MODERATE')
@@ -145,7 +174,7 @@ def reject(task_id):
145174
def manage_user():
146175
filter_rule = request.args.get('filter', 'all') # 'all', 'locked', 'blocked', 'administrator', 'moderator'
147176
page = request.args.get('page', 1, type=int)
148-
per_page = current_app.config['MANAGE_USER_PER_PAGE']
177+
per_page = current_app.config['ALBUMY_MANAGE_USER_PER_PAGE']
149178
administrator = Role.query.filter_by(name='Administrator').first()
150179
moderator = Role.query.filter_by(name='Moderator').first()
151180

@@ -165,6 +194,34 @@ def manage_user():
165194
return render_template('admin/manage_user.html', pagination=pagination, users=users)
166195

167196

197+
@admin_bp.route('/manage/photo', defaults={'order': 'by_flag'})
198+
@admin_bp.route('/manage/photo/<order>')
199+
@login_required
200+
@permission_required('MODERATE')
201+
def manage_photo(order):
202+
page = request.args.get('page', 1, type=int)
203+
per_page = current_app.config['ALBUMY_MANAGE_PHOTO_PER_PAGE']
204+
order_rule = 'flag'
205+
if order == 'by_time':
206+
pagination = Photo.query.order_by(Photo.timestamp.desc()).paginate(page, per_page)
207+
order_rule = 'time'
208+
else:
209+
pagination = Photo.query.order_by(Photo.flag.desc()).paginate(page, per_page)
210+
photos = pagination.items
211+
return render_template('admin/manage_photo.html', pagination=pagination, photos=photos, order_rule=order_rule)
212+
213+
214+
@admin_bp.route('/manage/tag')
215+
@login_required
216+
@permission_required('MODERATE')
217+
def manage_tag():
218+
page = request.args.get('page', 1, type=int)
219+
per_page = current_app.config['ALBUMY_MANAGE_TAG_PER_PAGE']
220+
pagination = Tag.query.order_by(Tag.id.desc()).paginate(page, per_page)
221+
tags = pagination.items
222+
return render_template('admin/manage_tag.html', pagination=pagination, tags=tags)
223+
224+
168225
@admin_bp.route('/')
169226
@admin_bp.route('/manage/task')
170227
@login_required
@@ -180,3 +237,19 @@ def manage_task():
180237
tasks = pagination.items
181238
return render_template('admin/manage_task.html', pagination=pagination, tasks=tasks)
182239

240+
241+
@admin_bp.route('/manage/comment', defaults={'order': 'by_flag'})
242+
@admin_bp.route('/manage/comment/<order>')
243+
@login_required
244+
@permission_required('MODERATE')
245+
def manage_comment(order):
246+
page = request.args.get('page', 1, type=int)
247+
per_page = current_app.config['ALBUMY_MANAGE_COMMENT_PER_PAGE']
248+
order_rule = 'flag'
249+
if order == 'by_time':
250+
pagination = Comment.query.order_by(Comment.timestamp.desc()).paginate(page, per_page)
251+
order_rule = 'time'
252+
else:
253+
pagination = Comment.query.order_by(Comment.flag.desc()).paginate(page, per_page)
254+
comments = pagination.items
255+
return render_template('admin/manage_comment.html', pagination=pagination, comments=comments, order_rule=order_rule)

datacenter/blueprints/ajax.py

+89-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
from flask import render_template, jsonify, Blueprint
88
from flask_login import current_user
99
from sqlalchemy import and_
10-
from datacenter.models import Tasks, Patients
10+
from datacenter.models import User, Photo, Notification, Tasks, Patients
11+
from datacenter.notifications import push_collect_notification, push_follow_notification
1112
ajax_bp = Blueprint('ajax', __name__)
1213

1314

@@ -25,6 +26,90 @@ def notifications_count():
2526
return jsonify(count=count1)
2627

2728

29+
@ajax_bp.route('/profile/<int:user_id>')
30+
def get_profile(user_id):
31+
user = User.query.get_or_404(user_id)
32+
return render_template('main/profile_popup.html', user=user)
33+
34+
35+
@ajax_bp.route('/followers-count/<int:user_id>')
36+
def followers_count(user_id):
37+
user = User.query.get_or_404(user_id)
38+
count = user.followers.count() - 1 # minus user self
39+
return jsonify(count=count)
40+
41+
42+
@ajax_bp.route('/<int:photo_id>/followers-count')
43+
def collectors_count(photo_id):
44+
photo = Photo.query.get_or_404(photo_id)
45+
count = len(photo.collectors)
46+
return jsonify(count=count)
47+
48+
49+
@ajax_bp.route('/collect/<int:photo_id>', methods=['POST'])
50+
def collect(photo_id):
51+
if not current_user.is_authenticated:
52+
return jsonify(message='Login required.'), 403
53+
if not current_user.confirmed:
54+
return jsonify(message='Confirm account required.'), 400
55+
if not current_user.can('COLLECT'):
56+
return jsonify(message='No permission.'), 403
57+
58+
photo = Photo.query.get_or_404(photo_id)
59+
if current_user.is_collecting(photo):
60+
return jsonify(message='Already collected.'), 400
61+
62+
current_user.collect(photo)
63+
if current_user != photo.author and photo.author.receive_collect_notification:
64+
push_collect_notification(collector=current_user, photo_id=photo_id, receiver=photo.author)
65+
return jsonify(message='Photo collected.')
66+
67+
68+
@ajax_bp.route('/uncollect/<int:photo_id>', methods=['POST'])
69+
def uncollect(photo_id):
70+
if not current_user.is_authenticated:
71+
return jsonify(message='Login required.'), 403
72+
73+
photo = Photo.query.get_or_404(photo_id)
74+
if not current_user.is_collecting(photo):
75+
return jsonify(message='Not collect yet.'), 400
76+
77+
current_user.uncollect(photo)
78+
return jsonify(message='Collect canceled.')
79+
80+
81+
@ajax_bp.route('/follow/<username>', methods=['POST'])
82+
def follow(username):
83+
if not current_user.is_authenticated:
84+
return jsonify(message='Login required.'), 403
85+
if not current_user.confirmed:
86+
return jsonify(message='Confirm account required.'), 400
87+
if not current_user.can('FOLLOW'):
88+
return jsonify(message='No permission.'), 403
89+
90+
user = User.query.filter_by(username=username).first_or_404()
91+
if current_user.is_following(user):
92+
return jsonify(message='Already followed.'), 400
93+
94+
current_user.follow(user)
95+
if user.receive_collect_notification:
96+
push_follow_notification(follower=current_user, receiver=user)
97+
return jsonify(message='User followed.')
98+
99+
100+
@ajax_bp.route('/unfollow/<username>', methods=['POST'])
101+
def unfollow(username):
102+
if not current_user.is_authenticated:
103+
return jsonify(message='Login required.'), 403
104+
105+
user = User.query.filter_by(username=username).first_or_404()
106+
if not current_user.is_following(user):
107+
return jsonify(message='Not follow yet.'), 400
108+
109+
current_user.unfollow(user)
110+
return jsonify(message='Follow canceled.')
111+
112+
28113
@ajax_bp.route('/bar/', methods=['GET'])
29114
def bar():
30115
"""
@@ -40,5 +125,6 @@ def bar():
40125
ratio = str(finished_count/count*100)
41126
ret = {'title': task.title, 'percent': ratio}
42127
# ret = {'title': 'biaoti', 'percent': '20'}
43-
# print(ret)
44-
return jsonify(ret)
128+
# ret = app.config['BAR']
129+
print(ret)
130+
return jsonify(ret)

0 commit comments

Comments
 (0)