def get_members(request, entity, entity_name): # which entity type is the user requesting members for? if entity == "groups": entity_obj = Group.objects.get(name=entity_name) elif entity == "companies": entity_obj = Company.objects.get(name=entity_name) # get the members belonging to this entity if entity_obj: members = Member.get_members(entity_obj) else: members = "" members = Member.sort_by_role(members) # serialize each member's data as JSON members_data = [] for member in members: members_data.append({ 'role': member.role, 'username': member.user.username, 'full_name': member.user.get_full_name(), 'avatar': member.user.avatar_url, 'is_consultant': member.user.is_consultant() }) data = { 'members': members_data, } return JsonResponse(data)
def test_editors(self): # get editors & owners company = Company.objects.get(name="Activision") editors = Member.get_members(company) # there are two editors (1 owner, 1 editor) self.assertTrue(len(editors) == 2) # the users are editors self.assertTrue(Member.is_editor(editors[0].user, company)) self.assertTrue(Member.is_editor(editors[1].user, company)) # test company applications self.assertEqual( company.application.date_submitted, datetime.date.today() ) company.application.approve( user=editors[0].user, comment="A well made application, approved!" ) self.assertEqual( company.application.status, Application.StatusType.Approved ) print(""" Company test successful. A single company was created, company.name=%s company.size=%d total company editors: %d editor #1: %s editor #2: %s A company application was also created with this company, company.application.date_submitted=%s company.application.date_approved=%s company.application.approved_by=%s company.application.comment=%s """ % ( company.name, company.size, len(editors), editors[0], editors[1], company.application.date_submitted, company.application.date_approved, company.application.approved_by, company.application.comment ) )
def test_editors(self): # get group & its members group = Group.objects.get(name="PUGB") editors = Member.get_members(group) # there are two editors (1 owner, 1 editor) self.assertTrue(len(editors) == 2) # the users are editors self.assertTrue(Member.is_editor(editors[0].user, group)) self.assertTrue(Member.is_editor(editors[1].user, group)) # test company applications self.assertEqual( group.application.date_submitted, datetime.date.today() ) group.application.approve( user=editors[0].user, comment="A well made application, approved!" ) self.assertEqual( group.application.status, Application.StatusType.Approved ) print(""" Group test successful. A single group was created, group.name=%s total group editors: %d editor #1: %s editor #2: %s A group application was also created with this group, group.application.date_submitted=%s group.application.date_approved=%s group.application.approved_by=%s group.application.comment=%s """ % ( group.name, len(editors), editors[0], editors[1], group.application.date_submitted, group.application.date_approved, group.application.approved_by, group.application.comment ) )
def get(self, request, group): """ User is viewing a profile """ try: group_obj = Group.objects.get(name=group) except ObjectDoesNotExist: return page_not_found(request, exception=ObjectDoesNotExist(), template_name='404.html') entity_obj = Entity.objects.get(group=group_obj) events = Event.get_entity_events(entity=entity_obj) return render(request, 'group/profile.html', { 'group': group_obj, 'events': events, 'members': Member.get_members(group_obj), 'is_owner': Member.is_owner(request.user, group_obj), 'is_editor': Member.is_editor(request.user, group_obj), })
def get(self, request, group): """ User is viewing a profile """ try: group_obj = Group.objects.get(name=group) except ObjectDoesNotExist: return page_not_found(request, exception=ObjectDoesNotExist(), template_name='404.html') entity_obj = Entity.objects.get(group=group_obj) events = Event.get_entity_events(entity=entity_obj) return render( request, 'group/profile.html', { 'group': group_obj, 'events': events, 'members': Member.get_members(group_obj), 'is_owner': Member.is_owner(request.user, group_obj), 'is_editor': Member.is_editor(request.user, group_obj), })
def email_group(self, subject: str, msg: str): members = Member.get_members(self) for member in members: member.user.email_user(subject, msg)