Skip to content

Commit fd80903

Browse files
committed
[BBGO-106] Implement papers
1 parent 63cf934 commit fd80903

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2423
-115
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.234
1+
1.1.235

bbgo/settings.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
'vaults',
6969
'recipes',
7070
'aliases',
71+
'papers',
7172
)
7273
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + EDITOR_APPS + LOCAL_APPS
7374

@@ -347,3 +348,8 @@
347348
# Setting for Recipe
348349
RECIPE_CATEGORY_MAX = 16
349350
RECIPE_NAME_MAX = 32
351+
352+
# SEtting for Paper
353+
SUMMARY_LIST_COUNT = 5
354+
INBOX_LIST_COUNT = 20
355+
APPROVE_COMMENT_MAX = 1024

bbgo/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
url(r'^recipes/', include(
3434
('recipes.urls', 'recipes'), namespace='recipes')),
3535
url(r'^a/', include(('aliases.urls', 'aliases'), namespace='aliases')),
36+
url(r'^papers/', include(('papers.urls', 'papers'), namespace='papers')),
3637
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
3738

3839
if 'django_summernote' in settings.INSTALLED_APPS:

core/api.py

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from django.utils.translation import ugettext as _
2424

2525
from msgs.models import Msg
26+
from papers.models import Paper, Person
2627
from spams.views import check_spam
2728
from teams.forms import TeamReplyEditForm
2829
from teams.models import Team, TeamReply
@@ -1207,3 +1208,151 @@ def reload_comment(request):
12071208
)
12081209
else:
12091210
return error_to_response(request)
1211+
1212+
1213+
def user_by_name(request):
1214+
"""API user_by_name"""
1215+
if not request.user.is_authenticated:
1216+
return JsonResponse({'status': 'false'}, status=401)
1217+
1218+
if request.method == 'POST':
1219+
approval_type = request.POST['type']
1220+
name = request.POST['name']
1221+
blacklist = request.POST.getlist('blacklist[]')
1222+
1223+
q = Q(username__icontains=name) | Q(
1224+
first_name__icontains=name) | Q(last_name__icontains=name)
1225+
1226+
names = User.objects.filter(is_active=True).filter(q).exclude(
1227+
username__in=blacklist)
1228+
total = names.count()
1229+
1230+
if total == 1:
1231+
data = {
1232+
'type': approval_type,
1233+
'id': names[0].id,
1234+
'username': names[0].username,
1235+
'name': names[0].last_name,
1236+
'email': names[0].email,
1237+
'status': 'only',
1238+
}
1239+
return JsonResponse(data)
1240+
1241+
return render_to_response(
1242+
'papers/user_list.html',
1243+
{
1244+
'user': request.user,
1245+
'type': approval_type,
1246+
'names': names,
1247+
'total': total,
1248+
}
1249+
)
1250+
else:
1251+
return error_to_response(request)
1252+
1253+
1254+
def approve_paper(request):
1255+
"""API approve_paper"""
1256+
if not request.user.is_authenticated:
1257+
return JsonResponse({'status': 'false'}, status=401)
1258+
1259+
if request.method == 'POST':
1260+
id = request.POST['id']
1261+
comment = request.POST['comment']
1262+
paper = get_object_or_404(Paper, pk=id)
1263+
1264+
if paper.completed or request.user != paper.cc.last().user:
1265+
return JsonResponse({'status': 'false'}, status=403)
1266+
if paper.approved and request.user == paper.approver:
1267+
return JsonResponse({'status': 'false'}, status=403)
1268+
1269+
paper.updated_at = timezone.now()
1270+
1271+
if request.user == paper.approver:
1272+
paper.comment = comment
1273+
paper.approved = True
1274+
paper.approved_at = paper.updated_at
1275+
1276+
if paper.supporters.all():
1277+
paper.status = '2progress'
1278+
first = paper.supporters.first()
1279+
person = Person.objects.create(
1280+
order=first.order, user=first.user)
1281+
paper.cc.add(person)
1282+
else:
1283+
paper.status = '5completed'
1284+
paper.completed = True
1285+
for notifier in paper.notifiers.all():
1286+
paper.cc.add(notifier)
1287+
else:
1288+
index = paper.cc.last().order - 3
1289+
supporter = paper.supporters.all()[index]
1290+
1291+
if index < 0 or supporter.user != request.user:
1292+
return JsonResponse({'status': 'false'}, status=403)
1293+
else:
1294+
supporter.comment = comment
1295+
supporter.approved = True
1296+
supporter.approved_at = paper.updated_at
1297+
supporter.save()
1298+
1299+
if paper.supporters.last().user == request.user:
1300+
paper.status = '5completed'
1301+
paper.completed = True
1302+
for notifier in paper.notifiers.all():
1303+
paper.cc.add(notifier)
1304+
else:
1305+
next_supporter = paper.supporters.all()[index + 1]
1306+
person = Person.objects.create(
1307+
order=next_supporter.order, user=next_supporter.user)
1308+
paper.cc.add(person)
1309+
1310+
paper.save()
1311+
return JsonResponse({'status': 'true'}, status=201)
1312+
1313+
1314+
def reject_paper(request):
1315+
"""API reject_paper"""
1316+
if not request.user.is_authenticated:
1317+
return JsonResponse({'status': 'false'}, status=401)
1318+
1319+
if request.method == 'POST':
1320+
id = request.POST['id']
1321+
comment = request.POST['comment']
1322+
paper = get_object_or_404(Paper, pk=id)
1323+
1324+
if not paper.completed and request.user == paper.user:
1325+
paper.updated_at = timezone.now()
1326+
paper.cancelmsg = comment
1327+
paper.status = '4canceled'
1328+
paper.completed = True
1329+
paper.save()
1330+
return JsonResponse({'status': 'true'}, status=201)
1331+
1332+
if paper.completed or request.user != paper.cc.last().user:
1333+
return JsonResponse({'status': 'false'}, status=403)
1334+
if paper.approved and request.user == paper.approver:
1335+
return JsonResponse({'status': 'false'}, status=403)
1336+
1337+
paper.updated_at = timezone.now()
1338+
1339+
if request.user == paper.approver:
1340+
paper.comment = comment
1341+
paper.rejected = True
1342+
paper.approved_at = paper.updated_at
1343+
else:
1344+
index = paper.cc.last().order - 3
1345+
supporter = paper.supporters.all()[index]
1346+
1347+
if index < 0 or supporter.user != request.user:
1348+
return JsonResponse({'status': 'false'}, status=403)
1349+
else:
1350+
supporter.comment = comment
1351+
supporter.rejected = True
1352+
supporter.approved_at = paper.updated_at
1353+
supporter.save()
1354+
1355+
paper.status = '3rejected'
1356+
paper.completed = True
1357+
paper.save()
1358+
return JsonResponse({'status': 'true'}, status=201)

core/apiurls.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,19 @@
187187
api.reload_comment,
188188
name='reload_comment',
189189
),
190+
url(
191+
r'^user_by_name/$',
192+
api.user_by_name,
193+
name='user_by_name',
194+
),
195+
url(
196+
r'^approve_paper/$',
197+
api.approve_paper,
198+
name='approve_paper',
199+
),
200+
url(
201+
r'^reject_paper/$',
202+
api.reject_paper,
203+
name='reject_paper',
204+
),
190205
]

core/context_processors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def global_settings(request):
3131
'BLOG_CATEGORY': settings.BLOG_CATEGORY,
3232
'ENABLE_MASTERKEY': settings.ENABLE_MASTERKEY,
3333
'MASTERKEY_LENGTH': settings.MASTERKEY_LENGTH,
34+
'APPROVE_COMMENT_MAX': settings.APPROVE_COMMENT_MAX,
3435
'ENABLE_ADSENSE': settings.ENABLE_ADSENSE,
3536
'SITE_INFO': settings.SITE_INFO,
3637
'SITE_LOGO': settings.SITE_LOGO,

core/templatetags/link.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,9 @@
66
@register.filter(name='target_blank', is_safe=True)
77
def _target_blank(link):
88
return link.replace('<a href=', '<a target="_blank" href=')
9+
10+
11+
@register.filter(name='filenamepath')
12+
def _filenamepath(path):
13+
filename = path.split('/')[-1]
14+
return filename

core/templatetags/status.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,13 @@ def _status_to_text(status):
2121
return "<font color=#e54f44>%s</font>" % _('status_deleted')
2222
elif status == '7spam':
2323
return "<font color=#FF574F>%s</font>" % _('status_spam')
24+
elif status == '1proposed':
25+
return _('status_proposed')
26+
elif status == '2progress':
27+
return _('status_progress')
28+
elif status == '3rejected':
29+
return _('status_rejected')
30+
elif status == '4canceled':
31+
return _('status_canceled')
32+
elif status == '5completed':
33+
return _('status_completed')

core/templatetags/user.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ def _nickname(user, is_authenticated=False):
1818
return name
1919

2020

21+
@register.filter(name='realname')
22+
def _realname(user, is_authenticated=False):
23+
name = user
24+
if user.last_name:
25+
name = user.last_name
26+
27+
if is_authenticated:
28+
nametag = "<a href=javascript:void(0) onclick=\"javascript:id_menu(event, '%s');return false;\">%s</a>" % (user.username, name)
29+
return nametag
30+
else:
31+
return name
32+
33+
2134
@register.filter(name='textnickname')
2235
def _textnickname(username, is_authenticated=False):
2336
name = username

locale/en/LC_MESSAGES/django.mo

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)