Coverage for mongo/announcement.py: 100%

29 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2024-11-05 04:22 +0000

1from . import engine 

2from .user import * 

3from .course import * 

4from .base import * 

5from .utils import * 

6 

7__all__ = ['Announcement'] 

8 

9 

10class Announcement(MongoBase, engine=engine.Announcement): 

11 qs_filter = {'status': 0} 

12 

13 def __init__(self, ann_id): 

14 self.ann_id = ann_id 

15 

16 @classmethod 

17 def ann_list(cls, user: User, course_name: str): 

18 if course_name == 'Public': 

19 return engine.Announcement.objects( 

20 course=Course('Public').obj, 

21 status=0, 

22 ).order_by('-createTime') 

23 course = Course(course_name) 

24 if not course: 

25 return [] 

26 if not course.permission(user, Course.Permission.VIEW): 

27 return [] 

28 anns = engine.Announcement.objects( 

29 course=course.obj, 

30 status=0, 

31 ).order_by('-createTime') 

32 return anns 

33 

34 @classmethod 

35 @doc_required('course', 'course', Course) 

36 def new_ann( 

37 cls, 

38 title, 

39 creator, 

40 markdown, 

41 pinned, 

42 course: Course, 

43 ): 

44 if not course.permission(creator, Course.Permission.GRADE): 

45 return None 

46 ann = engine.Announcement( 

47 title=title, 

48 course=course.obj, 

49 creator=creator, 

50 updater=creator, 

51 markdown=markdown, 

52 pinned=pinned, 

53 ) 

54 ann.save() 

55 return ann