def list_attendees(request, meeting_id): ''' List attendees for a specific meeting. Requesting user must be an admin in the meeting. Supplying a 'filter' GET parameter to filter the results by name/username. ''' ctx = {} try: meeting_id = int(meeting_id) except ValueError: return error('Invalid parameter (meeting_id). Should be a positive integer.') try: meeting = Meeting.objects.get(id=meeting_id) except Meeting.DoesNotExist: return error('Meeting object not found') try: meeting.managers.get(id=request.user.id) except User.DoesNotExist: return error('You must be a meeting manager to list the attendees.') filter_term = request.GET.get('filter', None) limit = 10 qs = ( Q(first_name__istartswith=filter_term) | Q(last_name__istartswith=filter_term) | Q(username__istartswith=filter_term) ) attendees = meeting.attendees.filter(qs)[:limit] # TODO: Why will the below not work? Later... #qs = ( #> Q(first_name__icontains=filter_term) | # Q(last_name__icontains=filter_term) | # Q(username__icontains=filter_term) #) #attendees = meeting.attendees.filter(qs, id__not=[a.id for a in attendees])[:limit - len(attendees)] ctx['attendees'] = [ { 'id': m.id, 'username': m.username, 'str': m.get_full_name() or str(m), } for m in attendees ] ctx['ok'] = True return ctx
def list_attendees(request, meeting_id): ''' List attendees for a specific meeting. Requesting user must be an admin in the meeting. Supplying a 'filter' GET parameter to filter the results by name/username. ''' ctx = {} try: meeting_id = int(meeting_id) except ValueError: return error( 'Invalid parameter (meeting_id). Should be a positive integer.') try: meeting = Meeting.objects.get(id=meeting_id) except Meeting.DoesNotExist: return error('Meeting object not found') try: meeting.managers.get(id=request.user.id) except User.DoesNotExist: return error('You must be a meeting manager to list the attendees.') filter_term = request.GET.get('filter', None) limit = 10 qs = (Q(first_name__istartswith=filter_term) | Q(last_name__istartswith=filter_term) | Q(username__istartswith=filter_term)) attendees = meeting.attendees.filter(qs)[:limit] # TODO: Why will the below not work? Later... #qs = ( #> Q(first_name__icontains=filter_term) | # Q(last_name__icontains=filter_term) | # Q(username__icontains=filter_term) #) #attendees = meeting.attendees.filter(qs, id__not=[a.id for a in attendees])[:limit - len(attendees)] ctx['attendees'] = [{ 'id': m.id, 'username': m.username, 'str': m.get_full_name() or str(m), } for m in attendees] ctx['ok'] = True return ctx
def meeting_intervention_add(request): ctx = {} meetingid = int(request.REQUEST.get('meeting', 0)) if not meetingid: ctx["ok"] = False return ctx meeting = get_object_or_404(Meeting, id=meetingid) if not request.user in meeting.attendees.all(): ctx["ok"] = False return ctx motion = int(request.REQUEST.get('type', 0)) if not motion: ctx["ok"] = False return ctx try: currentitem = meeting.meetingagenda_set.get(done=1) except: ctx["ok"] = False return ctx intervention = MeetingIntervention() intervention.meeting = meeting intervention.user = request.user intervention.motion = motion intervention.agendaitem = currentitem intervention.done = 0 intervention.order = 1 try: last_speaker = MeetingIntervention.objects.filter(agendaitem=currentitem).order_by('-order')[0] except IndexError: last_speaker = None if motion != MOTION['TALK']: return error('The first intervention must be a talk (FOR NOW)', ctx) else: same = last_speaker.user == request.user intervention.order = last_speaker.order + 1 if motion == MOTION['TALK']: # Request to talk if same and last_speaker.motion == MOTION['TALK']: return error('One cannot TALK twice in a row.') if motion == MOTION['REPLY']: # Request to reply directly if same and last_speaker.motion in (MOTION['TALK'], MOTION['REPLY']): return error('One cannot REPLY to own\'s REPLY.') if last_speaker.motion not in (MOTION['TALK'], MOTION['REPLY'], ): return error('One can only REPLY to a TALK or another REPLY', ctx) elif motion == MOTION['CLARIFY']: # Request to clarify raise NotImplementedError('This is not implemented now. TALK and REPLY should be enough for now.') elif motion == MOTION['POINT']: # Request to make a point of order raise NotImplementedError('This is not implemented now. TALK and REPLY should be enough for now.') # Shift all existing interventions with greater-or-equal order for i in MeetingIntervention.objects.filter(agendaitem=currentitem, order__gte=intervention.order): i.order += 1 i.save() # Finally save the new intervention intervention.save() return meeting_poll(request)
def meeting_intervention_add(request): ctx = {} meetingid = int(request.REQUEST.get('meeting', 0)) if not meetingid: ctx["ok"] = False return ctx meeting = get_object_or_404(Meeting, id=meetingid) if not request.user in meeting.attendees.all(): ctx["ok"] = False return ctx motion = int(request.REQUEST.get('type', 0)) if not motion: ctx["ok"] = False return ctx try: currentitem = meeting.meetingagenda_set.get(done=1) except MeetingAgenda.DoesNotExist: ctx["ok"] = False return ctx intervention = MeetingIntervention() intervention.meeting = meeting intervention.user = request.user intervention.motion = motion intervention.agendaitem = currentitem intervention.done = 0 intervention.order = 1 try: last_speaker = MeetingIntervention.objects.filter( agendaitem=currentitem).order_by('-order')[0] except IndexError: last_speaker = None if motion != MOTION['TALK']: return error('The first intervention must be a talk (FOR NOW)', ctx) else: same = last_speaker.user == request.user intervention.order = last_speaker.order + 1 if motion == MOTION['TALK']: # Request to talk if same and last_speaker.motion == MOTION['TALK']: return error('One cannot TALK twice in a row.') if motion == MOTION['REPLY']: # Request to reply directly if same and last_speaker.motion in (MOTION['TALK'], MOTION['REPLY']): return error('One cannot REPLY to own\'s REPLY.') if last_speaker.motion not in ( MOTION['TALK'], MOTION['REPLY'], ): return error('One can only REPLY to a TALK or another REPLY', ctx) elif motion == MOTION['CLARIFY']: # Request to clarify raise NotImplementedError( 'This is not implemented now. TALK and REPLY should be enough for now.' ) elif motion == MOTION['POINT']: # Request to make a point of order raise NotImplementedError( 'This is not implemented now. TALK and REPLY should be enough for now.' ) # Shift all existing interventions with greater-or-equal order for i in MeetingIntervention.objects.filter(agendaitem=currentitem, order__gte=intervention.order): i.order += 1 i.save() # Finally save the new intervention intervention.save() return meeting_poll(request)