Coverage for portality / view / dashboard.py: 63%

60 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-05-04 09:41 +0100

1from flask import Blueprint, make_response 

2from flask import render_template, abort, request 

3from flask_login import current_user, login_required 

4 

5from portality.decorators import ssl_required, write_required 

6from portality.bll import DOAJ, exceptions 

7from portality.util import jsonp 

8from portality.ui import templates 

9 

10import json 

11 

12from portality.core import app 

13 

14# ~~Dashboard:Blueprint~~ 

15blueprint = Blueprint('dashboard', __name__) 

16 

17 

18@blueprint.route('/') 

19@login_required 

20@ssl_required 

21def top_todo(): 

22 filter = request.values.get("filter") 

23 new_applications, update_requests, on_hold = True, True, True 

24 if filter == "na": 

25 on_hold = False 

26 update_requests = False 

27 elif filter == "ur": 

28 on_hold = False 

29 new_applications = False 

30 elif filter == "oh": 

31 update_requests = False 

32 new_applications = False 

33 

34 # ~~-> Todo:Service~~ 

35 svc = DOAJ.todoService() 

36 todos = svc.top_todo(current_user._get_current_object(), 

37 size=app.config.get("TODO_LIST_SIZE"), 

38 new_applications=new_applications, 

39 update_requests=update_requests, 

40 on_hold=on_hold) 

41 

42 count = svc.user_finished_historical_counts(current_user._get_current_object()) 

43 

44 # ~~-> Dashboard:Page~~ 

45 return render_template(templates.DASHBOARD, todos=todos, historical_count=count) 

46 

47 

48@blueprint.route("/top_notifications") 

49@login_required 

50@ssl_required 

51@jsonp 

52def top_notifications(): 

53 # ~~-> Notifications:Service 

54 svc = DOAJ.notificationsService() 

55 notes = svc.top_notifications(current_user._get_current_object(), size=10) 

56 

57 data = json.dumps([n.data for n in notes]) 

58 

59 resp = make_response(data) 

60 resp.mimetype = "application/json" 

61 return resp 

62 

63 

64@blueprint.route("/notifications/<notification_id>/seen", methods=["POST"]) 

65@login_required 

66@write_required() 

67@ssl_required 

68@jsonp 

69def notification_seen(notification_id): 

70 # ~~-> Notifications:Service 

71 svc = DOAJ.notificationsService() 

72 try: 

73 result = svc.notification_seen(current_user._get_current_object(), notification_id) 

74 except exceptions.NoSuchObjectException: 

75 abort(400) 

76 

77 data = json.dumps({"result" : result}) 

78 resp = make_response(data) 

79 resp.mimetype = "application/json" 

80 return resp 

81 

82 

83@blueprint.route("/notifications") 

84@login_required 

85@ssl_required 

86def notifications(): 

87 # ~~-> Notifications:Page~~ 

88 return render_template(templates.NOTIFICATIONS)