Coverage for app/backend/src/couchers/servicers/dashboard.py: 100%

12 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-07-22 18:39 +0000

1from google.protobuf import empty_pb2 

2from sqlalchemy.orm import Session 

3 

4from couchers.context import CouchersContext 

5from couchers.proto import ( 

6 conversations_pb2, 

7 dashboard_pb2, 

8 dashboard_pb2_grpc, 

9 discussions_pb2, 

10 events_pb2, 

11 requests_pb2, 

12) 

13from couchers.servicers.account import Account 

14from couchers.servicers.discussions import Discussions 

15from couchers.servicers.events import Events 

16from couchers.servicers.requests import Requests 

17 

18# the dashboard shows a small preview of each section 

19DASHBOARD_PAGE_SIZE = 3 

20 

21 

22class Dashboard(dashboard_pb2_grpc.DashboardServicer): 

23 def GetDashboardV2( 

24 self, request: dashboard_pb2.GetDashboardV2Req, context: CouchersContext, session: Session 

25 ) -> dashboard_pb2.GetDashboardV2Res: 

26 return dashboard_pb2.GetDashboardV2Res( 

27 reminders=Account().GetReminders(empty_pb2.Empty(), context, session), 

28 surfing=Requests().ListHostRequests( 

29 requests_pb2.ListHostRequestsReq( 

30 only_sent=True, 

31 only_active=True, 

32 status_in=[ 

33 conversations_pb2.HOST_REQUEST_STATUS_ACCEPTED, 

34 conversations_pb2.HOST_REQUEST_STATUS_CONFIRMED, 

35 ], 

36 sort_by=requests_pb2.HOST_REQUEST_SORT_BY_FROM_DATE, 

37 ), 

38 context, 

39 session, 

40 ), 

41 hosting=Requests().ListHostRequests( 

42 requests_pb2.ListHostRequestsReq( 

43 only_received=True, 

44 only_active=True, 

45 status_in=[ 

46 conversations_pb2.HOST_REQUEST_STATUS_ACCEPTED, 

47 conversations_pb2.HOST_REQUEST_STATUS_CONFIRMED, 

48 ], 

49 sort_by=requests_pb2.HOST_REQUEST_SORT_BY_FROM_DATE, 

50 ), 

51 context, 

52 session, 

53 ), 

54 my_events=Events().ListMyEvents( 

55 events_pb2.ListMyEventsReq(page_size=DASHBOARD_PAGE_SIZE), 

56 context, 

57 session, 

58 ), 

59 community_events=Events().ListMyEvents( 

60 events_pb2.ListMyEventsReq( 

61 page_size=DASHBOARD_PAGE_SIZE, 

62 my_communities=True, 

63 my_communities_exclude_global=True, 

64 exclude_attending=True, 

65 ), 

66 context, 

67 session, 

68 ), 

69 discussions=Discussions().ListMyCommunitiesDiscussions( 

70 discussions_pb2.ListMyCommunitiesDiscussionsReq(page_size=DASHBOARD_PAGE_SIZE), 

71 context, 

72 session, 

73 ), 

74 )