class ModifyAttendanceForm(Form): subscribed = ModelMultipleChoiceField(label=u'Présent', queryset=get_active_members(), widget=CheckboxSelectMultiple, required=False) excused = ModelMultipleChoiceField(label=u'Excusé', queryset=get_active_members(), widget=CheckboxSelectMultiple, required=False)
def send(r, event_id): Ev = Event.objects.get(id=event_id) I = Invitation.objects.get(event=Ev) title = settings.TEMPLATE_CONTENT['events']['send']['done']['title'] % str( Ev.title) email_error = { 'ok': True, 'who': (), } recipient_list = [] for m in get_active_members(): recipient_list.append(m.email) ok = send_invitation(Ev, m, I) if not ok: email_error['ok'] = False email_error['who'].add(m.email) # error in email -> show error messages if not email_error['ok']: return TemplateResponse( r, settings.TEMPLATE_CONTENT['events']['send']['done']['template'], { 'title': title, 'error_message': settings.TEMPLATE_CONTENT['error']['email'] + ' ; '.join([e for e in email_error['who']]), }) # all fine -> done else: return TemplateResponse( r, settings.TEMPLATE_CONTENT['events']['send']['done']['template'], { 'title': title, 'message': settings.TEMPLATE_CONTENT['events']['send']['done']['message'] % { 'email': I.message, 'attachement': I.attachement, 'list': ' ; '.join([e for e in recipient_list]), }, })
def attendance(r, meeting_num, attendance_hash): meeting = Meeting.objects.get(num=meeting_num) title = settings.TEMPLATE_CONTENT['meetings']['attendance']['title'] % { 'meeting': meeting.title, } message = '' notify = False for m in get_active_members(): if gen_hash(meeting, m.email) == attendance_hash: # it's a YES meeting.attendance.add(m) message = settings.TEMPLATE_CONTENT['meetings']['attendance'][ 'yes'] % { 'name': gen_fullname(m), } notify = True if gen_hash(meeting, m.email, False) == attendance_hash: # it's a NO meeting.excused.add(m) message = settings.TEMPLATE_CONTENT['meetings']['attendance'][ 'no'] % { 'name': gen_fullname(m), } notify = True if notify: #notify by email message_content = { 'MESSAGE': message, } #send email ok = notify_by_email(False, m.email, title, message_content) meeting.save() return render( r, settings.TEMPLATE_CONTENT['meetings']['attendance']['template'], { 'title': title, 'message': message, })
def send(r,event_id): r.breadcrumbs( ( ('board','/board/'), ('events','/events/'), ('send event invitations','/events/send/'), ) ) Ev = Event.objects.get(id=event_id) I = Invitation.objects.get(event=Ev) email_error = { 'ok': True, 'who': (), } recipient_list = [] for m in get_active_members(): if m.type == Member.ORG: for u in m.users.all(): recipient_list.append(u.email) ok=send_invitation(Ev,u,I) if not ok: email_error['ok']=False email_error['who'].add(u.email) else: recipient_list.append(m.head_of_list.email) ok=send_invitation(Ev,m.head_of_list,I) if not ok: email_error['ok']=False email_error['who'].add(m.head_of_list.email) # error in email -> show error messages if not email_error['ok']: I.save() return render(r, settings.TEMPLATE_CONTENT['events']['send']['done']['template'], { 'title': settings.TEMPLATE_CONTENT['events']['send']['done']['title'] % { 'event': Ev.title, }, 'error_message': settings.TEMPLATE_CONTENT['error']['email'] + ' ; '.join([e for e in email_error['who']]), }) # all fine -> done return render(r, settings.TEMPLATE_CONTENT['events']['send']['done']['template'], { 'title': settings.TEMPLATE_CONTENT['events']['send']['done']['title'] % { 'event': Ev.title, }, 'message': settings.TEMPLATE_CONTENT['events']['send']['done']['message'] % { 'email': I.message, 'attachement': I.attachement, 'list': ' ; '.join([e for e in recipient_list]), }, })
def attendance(r, event_type, event_id, attendance_hash): E = M = title = deadline = e_yes = e_no = message = member = actions = None if event_type == 'meetings': M = Meeting.objects.get(num=event_id) deadline = M.deadline title = settings.TEMPLATE_CONTENT['attendance']['meeting']['title'] % { 'meeting': M.title, } e_yes = settings.TEMPLATE_CONTENT['attendance']['meeting']['email'][ 'yes'] % { 'meeting': M.title, } e_no = settings.TEMPLATE_CONTENT['attendance']['meeting']['email'][ 'no'] % { 'meeting': M.title, } if event_type == 'events': E = Event.objects.get(pk=event_id) deadline = E.deadline title = settings.TEMPLATE_CONTENT['attendance']['event']['title'] % { 'event': E.title, } e_yes = settings.TEMPLATE_CONTENT['attendance']['event']['email'][ 'yes'] % { 'event': E.title, } e_no = settings.TEMPLATE_CONTENT['attendance']['event']['email'][ 'no'] % { 'event': E.title, } if timezone.now() >= deadline: message = settings.TEMPLATE_CONTENT['attendance']['too_late'] else: for m in get_active_members(): notify = False e_message = None A = None if event_type == 'meetings': try: A = Meeting_Attendance.objects.get(meeting=M, member=m) except: A = Meeting_Attendance(meeting=M, member=m) mTm = MtoM.objects.get(meeting=M, member=m) if attendance_hash == mTm.yes_hash: # it's a YES A.present = True A.timestamp = datetime.now() A.save() notify = True member = m message = settings.TEMPLATE_CONTENT['attendance']['yes'] % { 'name': gen_member_fullname(m), } #add meeting information to the confirmation message message += settings.TEMPLATE_CONTENT['attendance'][ 'details'] % { 'when': M.when, 'time': M.time, 'location': M.location, 'address': M.location.address, } e_message = e_yes if M.type == Meeting.C: actions = settings.TEMPLATE_CONTENT['attendance'][ 'actions'] #set meeting:num and member_id for invitee link if actions: for a in actions: a['url'] = a['url'].format( str(M.num), str(member.id)) if attendance_hash == mTm.no_hash: # it's a NO A.present = False A.timestamp = datetime.now() A.save() notify = True message = settings.TEMPLATE_CONTENT['attendance']['no'] % { 'name': gen_member_fullname(m), } e_message = e_no elif event_type == 'events': try: A = Event_Attendance.objects.get(event=E, member=m) except: A = Event_Attendance(event=E, member=m) eTm = EtoM.objects.get(event=E, member=m) if attendance_hash == eTm.yes_hash: # it's a YES A.present = True A.timestamp = datetime.now() A.save() notify = True member = m message = settings.TEMPLATE_CONTENT['attendance']['yes'] % { 'name': gen_member_fullname(m), } #add meeting information to the confirmation message message += settings.TEMPLATE_CONTENT['attendance'][ 'details'] % { 'when': E.when, 'time': E.time, 'location': E.location, 'address': E.location.address, } actions = settings.TEMPLATE_CONTENT['attendance'][ 'actions'] e_message = e_yes if attendance_hash == eTm.no_hash: # it's a NO A.present = False A.timestamp = datetime.now() A.save() notify = True message = settings.TEMPLATE_CONTENT['attendance']['no'] % { 'name': gen_member_fullname(m), } e_message = e_no if notify: #notify by email message_content = { 'FULLNAME': gen_member_fullname(m), 'MESSAGE': e_message, } #send email ok = notify_by_email(False, m.email, title, message_content) return TemplateResponse( r, settings.TEMPLATE_CONTENT['attendance']['template'], { 'title': title, 'actions': actions, 'message': message, }) if event_type == 'events': return TemplateResponse( r, settings.TEMPLATE_CONTENT['attendance']['template'], { 'title': title, 'message': message, })
def add(r): if r.POST: mf = MeetingForm(r.POST,r.FILES) if mf.is_valid(): Mt = mf.save(commit=False) Mt.save() for member in Member.objects.all(): gen_attendance_hashes(Mt,Event.MEET,member) if r.FILES: I = Invitation(meeting=Mt,message=mf.cleaned_data['additional_message'],attachement=r.FILES['attachement']) else: I = Invitation(meeting=Mt,message=mf.cleaned_data['additional_message']) I.save() # all fine -> done I.save() return TemplateResponse(r, settings.TEMPLATE_CONTENT['meetings']['add']['done']['template'], { 'title': settings.TEMPLATE_CONTENT['meetings']['add']['done']['title'], 'message': settings.TEMPLATE_CONTENT['meetings']['add']['done']['message'].format(meeting=Mt,invite=I,list=' ; '.join([gen_member_fullname(m) for m in get_active_members()])), }) # form not valid -> error else: return TemplateResponse(r, settings.TEMPLATE_CONTENT['meetings']['add']['done']['template'], { 'title': settings.TEMPLATE_CONTENT['meetings']['add']['done']['title'], 'error_message': settings.TEMPLATE_CONTENT['error']['gen'] + ' ; '.join([e for e in mf.errors]), }) # no post yet -> empty form else: form = MeetingForm() try: latest = Meeting.objects.values().latest('num') next_num = latest['num'] + 1 except Meeting.DoesNotExist: next_num = 1 form = MeetingForm(initial={ 'title': str(next_num) + '. réunion statutaire', 'num': next_num, }) return TemplateResponse(r, settings.TEMPLATE_CONTENT['meetings']['add']['template'], { 'title': settings.TEMPLATE_CONTENT['meetings']['add']['title'], 'desc': settings.TEMPLATE_CONTENT['meetings']['add']['desc'], 'submit': settings.TEMPLATE_CONTENT['meetings']['add']['submit'], 'form': form, })
def report(r, meeting_num): Mt = Meeting.objects.get(num=meeting_num) if r.POST: e_template = settings.TEMPLATE_CONTENT['meetings']['report']['done']['email']['template'] mrf = MeetingReportForm(r.POST, r.FILES) if mrf.is_valid(): Mt.report = mrf.cleaned_data['report'] Mt.save() send = mrf.cleaned_data['send'] if send: email_error = { 'ok': True, 'who': [], } for m in get_active_members(): #notifiation per email for new report subject = settings.TEMPLATE_CONTENT['meetings']['report']['done']['email']['subject'] % { 'title': str(Mt.title) } message_content = { 'FULLNAME' : gen_member_fullname(m), 'MESSAGE' : gen_report_message(e_template,Mt,m), } attachement = settings.MEDIA_ROOT + str(Mt.report) #send email ok=notify_by_email(settings.EMAILS['sender']['default'],m.email,subject,message_content,False,attachement) if not ok: email_error['ok']=False email_error['who'].append(m.email) # error in email -> show error messages if not email_error['ok']: return TemplateResponse(r, settings.TEMPLATE_CONTENT['meetings']['report']['done']['template'], { 'title': settings.TEMPLATE_CONTENT['meetings']['report']['done']['title'], 'error_message': settings.TEMPLATE_CONTENT['error']['email'] + ' ; '.join([e for e in email_error['who']]), }) else: # done -> with sending return TemplateResponse(r, settings.TEMPLATE_CONTENT['meetings']['report']['done']['template'], { 'title': settings.TEMPLATE_CONTENT['meetings']['report']['done']['title_send'], 'message': settings.TEMPLATE_CONTENT['meetings']['report']['done']['message_send'] + ' ; '.join([gen_member_fullname(m) for m in get_active_members()]), }) else: # done -> no sending return TemplateResponse(r, settings.TEMPLATE_CONTENT['meetings']['report']['done']['template'], { 'title': settings.TEMPLATE_CONTENT['meetings']['report']['done']['title'], 'message': settings.TEMPLATE_CONTENT['meetings']['report']['done']['message'], }) # form not valid -> error else: return TemplateResponse(r, settings.TEMPLATE_CONTENT['meetings']['report']['done']['template'], { 'title': settings.TEMPLATE_CONTENT['meetings']['report']['done']['title'], 'error_message': settings.TEMPLATE_CONTENT['error']['gen'] + ' ; '.join([e for e in mrf.errors]), }) # no post yet -> empty form else: form = MeetingReportForm(initial={ 'num': Mt.num, 'title': Mt.title, 'when': visualiseDateTime(Mt.when), }) title = settings.TEMPLATE_CONTENT['meetings']['report']['title'].format(str(Mt.num)) return TemplateResponse(r, settings.TEMPLATE_CONTENT['meetings']['report']['template'], { 'title': title, 'desc': settings.TEMPLATE_CONTENT['meetings']['report']['desc'], 'submit': settings.TEMPLATE_CONTENT['meetings']['report']['submit'], 'form': form, })
def gen_meeting_listing(template, meeting): content = { 'content': settings.TEMPLATE_CONTENT['meetings']['listing']['content'] } #get attendance / excused / invited present = Meeting_Attendance.objects.filter(meeting=meeting, present=True).only('member') excused = Meeting_Attendance.objects.filter(meeting=meeting, present=False).only('member') invited = Invitee.objects.filter(meeting=meeting) content['listing'] = {} #header row # name (role) / present / excuse / non-excuse / email content['listing']['header'] = [ u'Nom (rôle)', u'présent', u'excusé', u'non excusé', ] #records table (alphabetical order on last_name) members = get_active_members().order_by('last_name') content['listing']['members'] = [] ok = ' <i class="fa fa-check"></i> ' nok = ' <i class="fa fa-times"></i> ' for m in members: p = e = n = '' for x in present: if m.id == x.member.id: p = ok for y in excused: if m.id == y.member.id: e = ok if p == '' and e == '': n = nok content['listing']['members'].append([ gen_member_fullname_n_role(m), p, e, n, ]) #invitees table content['listing']['invitees'] = [] for i in invited: content['listing']['invitees'].append([ i.first_name + ' ' + str.upper(i.last_name), ]) #resume table content['listing']['resume'] = [] # presents / invités / total P = present.count() M = members.all().count() E = excused.count() I = invited.count() N = M - P - E content['listing']['resume'].append([ u'<em>Présents :</em>   ' + str(P) + '/' + str(M) + ' (' + str(int(round((float(P) / M) * 100))) + '%)', u'<em>Invités :</em>   ' + str(I), u'<strong>Total :</strong>   ' + str(P + I), ]) # excusés / non exc. / content['listing']['resume'].append([ u'<em>Excusés :</em>   ' + str(E) + '/' + str(M) + ' (' + str(int(round((float(E) / M) * 100))) + '%)', u'<em>Non-excusés :</em>   ' + str(N) + '/' + str(M) + ' (' + str(int(round((float(N) / M) * 100))) + '%)', ]) return render_to_string(template, content)
def attendance(r, event_type, event_id, attendance_hash): E = M = title = deadline = e_yes = e_no = message = member = actions = None if event_type == 'meetings': M = Meeting.objects.get(num=event_id) deadline = M.deadline title = settings.TEMPLATE_CONTENT['attendance']['meeting']['title'] % { 'meeting': M.title, } e_yes = settings.TEMPLATE_CONTENT['attendance']['meeting']['email']['yes'] % { 'meeting': M.title, } e_no = settings.TEMPLATE_CONTENT['attendance']['meeting']['email']['no'] % { 'meeting': M.title, } if event_type == 'events': E = Event.objects.get(pk=event_id) deadline = E.deadline title = settings.TEMPLATE_CONTENT['attendance']['event']['title'] % { 'event': E.title, } e_yes = settings.TEMPLATE_CONTENT['attendance']['event']['email']['yes'] % { 'event': E.title, } e_no = settings.TEMPLATE_CONTENT['attendance']['event']['email']['no'] % { 'event': E.title, } if timezone.now() >= deadline: message = settings.TEMPLATE_CONTENT['attendance']['too_late'] else: for m in get_active_members(): notify = False e_message = None A = None if event_type == 'meetings': try: A = Meeting_Attendance.objects.get(meeting=M,member=m) except: A = Meeting_Attendance(meeting=M,member=m) mTm = MtoM.objects.get(meeting=M,member=m) if attendance_hash == mTm.yes_hash: # it's a YES A.present = True A.timestamp = datetime.now() A.save() notify=True member=m message = settings.TEMPLATE_CONTENT['attendance']['yes'] % { 'name': gen_member_fullname(m), } #add meeting information to the confirmation message message += settings.TEMPLATE_CONTENT['attendance']['details'] % { 'when': M.when, 'time': M.time, 'location': M.location, 'address': M.location.address, } e_message = e_yes if M.type == Meeting.C: actions = settings.TEMPLATE_CONTENT['attendance']['actions'] #set meeting:num and member_id for invitee link if actions: for a in actions: a['url'] = a['url'].format(str(M.num),str(member.id)) if attendance_hash == mTm.no_hash: # it's a NO A.present = False A.timestamp = datetime.now() A.save() notify=True message = settings.TEMPLATE_CONTENT['attendance']['no'] % { 'name': gen_member_fullname(m), } e_message = e_no elif event_type == 'events': try: A = Event_Attendance.objects.get(event=E,member=m) except: A = Event_Attendance(event=E,member=m) eTm = EtoM.objects.get(event=E,member=m) if attendance_hash == eTm.yes_hash: # it's a YES A.present = True A.timestamp = datetime.now() A.save() notify=True member=m message = settings.TEMPLATE_CONTENT['attendance']['yes'] % { 'name': gen_member_fullname(m), } #add meeting information to the confirmation message message += settings.TEMPLATE_CONTENT['attendance']['details'] % { 'when': E.when, 'time': E.time, 'location': E.location, 'address': E.location.address, } actions = settings.TEMPLATE_CONTENT['attendance']['actions'] e_message = e_yes if attendance_hash == eTm.no_hash: # it's a NO A.present = False A.timestamp = datetime.now() A.save() notify=True message = settings.TEMPLATE_CONTENT['attendance']['no'] % { 'name': gen_member_fullname(m), } e_message = e_no if notify: #notify by email message_content = { 'FULLNAME' : gen_member_fullname(m), 'MESSAGE' : e_message, } #send email ok=notify_by_email(False,m.email,title,message_content) return TemplateResponse(r, settings.TEMPLATE_CONTENT['attendance']['template'], { 'title': title, 'actions' : actions, 'message': message, }) if event_type == 'events': return TemplateResponse(r, settings.TEMPLATE_CONTENT['attendance']['template'], { 'title': title, 'message': message, })
def add(r): if r.POST: mf = MeetingForm(r.POST, r.FILES) if mf.is_valid(): Mt = mf.save(commit=False) Mt.save() for member in Member.objects.all(): gen_attendance_hashes(Mt, Event.MEET, member) if r.FILES: I = Invitation(meeting=Mt, message=mf.cleaned_data['additional_message'], attachement=r.FILES['attachement']) else: I = Invitation(meeting=Mt, message=mf.cleaned_data['additional_message']) I.save() # all fine -> done I.save() return TemplateResponse( r, settings.TEMPLATE_CONTENT['meetings']['add']['done'] ['template'], { 'title': settings.TEMPLATE_CONTENT['meetings']['add']['done'] ['title'], 'message': settings.TEMPLATE_CONTENT['meetings']['add']['done'] ['message'].format(meeting=Mt, invite=I, list=' ; '.join([ gen_member_fullname(m) for m in get_active_members() ])), }) # form not valid -> error else: return TemplateResponse( r, settings.TEMPLATE_CONTENT['meetings']['add']['done'] ['template'], { 'title': settings.TEMPLATE_CONTENT['meetings']['add']['done'] ['title'], 'error_message': settings.TEMPLATE_CONTENT['error']['gen'] + ' ; '.join([e for e in mf.errors]), }) # no post yet -> empty form else: form = MeetingForm() try: latest = Meeting.objects.values().latest('num') next_num = latest['num'] + 1 except Meeting.DoesNotExist: next_num = 1 form = MeetingForm(initial={ 'title': str(next_num) + '. réunion statutaire', 'num': next_num, }) return TemplateResponse( r, settings.TEMPLATE_CONTENT['meetings']['add']['template'], { 'title': settings.TEMPLATE_CONTENT['meetings']['add']['title'], 'desc': settings.TEMPLATE_CONTENT['meetings']['add']['desc'], 'submit': settings.TEMPLATE_CONTENT['meetings']['add']['submit'], 'form': form, })
def report(r, meeting_num): Mt = Meeting.objects.get(num=meeting_num) if r.POST: e_template = settings.TEMPLATE_CONTENT['meetings']['report']['done'][ 'email']['template'] mrf = MeetingReportForm(r.POST, r.FILES) if mrf.is_valid(): Mt.report = mrf.cleaned_data['report'] Mt.save() send = mrf.cleaned_data['send'] if send: email_error = { 'ok': True, 'who': [], } for m in get_active_members(): #notifiation per email for new report subject = settings.TEMPLATE_CONTENT['meetings']['report'][ 'done']['email']['subject'] % { 'title': str(Mt.title) } message_content = { 'FULLNAME': gen_member_fullname(m), 'MESSAGE': gen_report_message(e_template, Mt, m), } attachement = settings.MEDIA_ROOT + str(Mt.report) #send email ok = notify_by_email(settings.EMAILS['sender']['default'], m.email, subject, message_content, False, attachement) if not ok: email_error['ok'] = False email_error['who'].append(m.email) # error in email -> show error messages if not email_error['ok']: return TemplateResponse( r, settings.TEMPLATE_CONTENT['meetings']['report'] ['done']['template'], { 'title': settings.TEMPLATE_CONTENT['meetings']['report'] ['done']['title'], 'error_message': settings.TEMPLATE_CONTENT['error']['email'] + ' ; '.join([e for e in email_error['who']]), }) else: # done -> with sending return TemplateResponse( r, settings.TEMPLATE_CONTENT['meetings']['report'] ['done']['template'], { 'title': settings.TEMPLATE_CONTENT['meetings']['report'] ['done']['title_send'], 'message': settings.TEMPLATE_CONTENT['meetings']['report'] ['done']['message_send'] + ' ; '.join([ gen_member_fullname(m) for m in get_active_members() ]), }) else: # done -> no sending return TemplateResponse( r, settings.TEMPLATE_CONTENT['meetings']['report']['done'] ['template'], { 'title': settings.TEMPLATE_CONTENT['meetings']['report']['done'] ['title'], 'message': settings.TEMPLATE_CONTENT['meetings']['report']['done'] ['message'], }) # form not valid -> error else: return TemplateResponse( r, settings.TEMPLATE_CONTENT['meetings']['report']['done'] ['template'], { 'title': settings.TEMPLATE_CONTENT['meetings']['report']['done'] ['title'], 'error_message': settings.TEMPLATE_CONTENT['error']['gen'] + ' ; '.join([e for e in mrf.errors]), }) # no post yet -> empty form else: form = MeetingReportForm(initial={ 'num': Mt.num, 'title': Mt.title, 'when': visualiseDateTime(Mt.when), }) title = settings.TEMPLATE_CONTENT['meetings']['report'][ 'title'].format(str(Mt.num)) return TemplateResponse( r, settings.TEMPLATE_CONTENT['meetings']['report']['template'], { 'title': title, 'desc': settings.TEMPLATE_CONTENT['meetings']['report']['desc'], 'submit': settings.TEMPLATE_CONTENT['meetings']['report']['submit'], 'form': form, })
def add(r): r.breadcrumbs(( ('home', '/'), ('meetings', '/meetings/'), ('add a meeting', '/meetings/add/'), )) if r.POST: e_template = settings.TEMPLATE_CONTENT['meetings']['add']['done'][ 'email']['template'] mf = MeetingForm(r.POST) if mf.is_valid(): Mt = mf.save(commit=False) Mt.save() email_error = { 'ok': True, 'who': (), } for m in get_active_members(): #invitation email with "YES/NO button" # subject = settings.TEMPLATE_CONTENT['meetings']['add']['done']['email']['subject'].format(title=unicode(Mt.title))) subject = settings.TEMPLATE_CONTENT['meetings']['add']['done'][ 'email']['subject'] % { 'title': unicode(Mt.title) } invitation_message = gen_invitation_message(e_template, Mt, m) message_content = { 'FULLNAME': gen_fullname(m), 'MESSAGE': invitation_message + mf.cleaned_data['additional_message'], } #send email ok = notify_by_email(r.user.email, m.email, subject, message_content) if not ok: email_error['ok'] = False email_error['who'].add(m.email) # error in email -> show error messages if not email_error['ok']: return render( r, settings.TEMPLATE_CONTENT['meetings']['add']['done'] ['template'], { 'title': settings.TEMPLATE_CONTENT['meetings']['add']['done'] ['title'], 'error_message': settings.TEMPLATE_CONTENT['error']['email'] + ' ; '.join([e for e in email_error['who']]), }) # all fine -> done else: return render( r, settings.TEMPLATE_CONTENT['meetings']['add']['done'] ['template'], { 'title': settings.TEMPLATE_CONTENT['meetings']['add']['done'] ['title'], 'message': settings.TEMPLATE_CONTENT['meetings']['add']['done'] ['message'] + ' ; '.join( [gen_fullname(m) for m in get_active_members()]), }) # form not valid -> error else: return render( r, settings.TEMPLATE_CONTENT['meetings']['add']['done'] ['template'], { 'title': settings.TEMPLATE_CONTENT['meetings']['add']['done'] ['title'], 'error_message': settings.TEMPLATE_CONTENT['error']['gen'] + ' ; '.join([e for e in mf.errors]), }) # no post yet -> empty form else: form = MeetingForm() try: latest = Meeting.objects.values().latest('num') next_num = latest['num'] + 1 form = MeetingForm(initial={ 'title': str(next_num) + '. réunion statutaire', 'num': next_num, }) except Meeting.DoesNotExist: pass return render( r, settings.TEMPLATE_CONTENT['meetings']['add']['template'], { 'title': settings.TEMPLATE_CONTENT['meetings']['add']['title'], 'desc': settings.TEMPLATE_CONTENT['meetings']['add']['desc'], 'submit': settings.TEMPLATE_CONTENT['meetings']['add']['submit'], 'form': form, })
def attendance(r, event_type, event_id, attendance_hash): E = M = title = deadline = e_yes = e_no = message = member = actions = None if event_type == 'meetings': M = Meeting.objects.get(pk=event_id) deadline = M.deadline title = settings.TEMPLATE_CONTENT['attendance']['meeting']['title'] % { 'meeting': M.group, } e_yes = settings.TEMPLATE_CONTENT['attendance']['meeting']['email']['yes'] % { 'meeting': M.title, } e_no = settings.TEMPLATE_CONTENT['attendance']['meeting']['email']['no'] % { 'meeting': M.title, } if event_type == 'events': E = Event.objects.get(pk=event_id) G = E.group deadline = E.deadline title = settings.TEMPLATE_CONTENT['attendance']['event']['title'] % { 'event': E.title, } e_yes = settings.TEMPLATE_CONTENT['attendance']['event']['email']['yes'] % { 'event': E.title, } e_no = settings.TEMPLATE_CONTENT['attendance']['event']['email']['no'] % { 'event': E.title, } if timezone.now() >= deadline: message = settings.TEMPLATE_CONTENT['attendance']['too_late'] else: for m in get_active_members(): notify = False e_message = None A = None if event_type == 'meetings': for U in get_group_members(M.group): try: A = Meeting_Attendance.objects.get(meeting=M,user=U) except: A = Meeting_Attendance(meeting=M,user=U) mTm = MtoM.objects.get(meeting=M,user=U) if attendance_hash == mTm.yes_hash: # it's a YES A.present = True A.timestamp = timezone.now() A.save() notify=True member=m message = settings.TEMPLATE_CONTENT['attendance']['yes'] % { 'name': gen_fullname(U), } #add meeting information to the confirmation message message += settings.TEMPLATE_CONTENT['attendance']['details'] % { 'title': M.title, 'when': M.when, 'time': visualiseDateTime(M.start) + ' - ' + visualiseDateTime(M.end), 'location': M.location, } actions = settings.TEMPLATE_CONTENT['attendance']['actions'] e_message = e_yes if attendance_hash == mTm.no_hash: # it's a NO A.present = False A.timestamp = timezone.now() A.save() notify=True message = settings.TEMPLATE_CONTENT['attendance']['no'] % { 'name': gen_fullname(U), } e_message = e_no elif event_type == 'events': for u in get_all_users_for_membership(m): U = User.objects.get(username=u['username']) try: A = Event_Attendance.objects.get(event=E,user=U) except: A = Event_Attendance(event=E,user=U) eTm = EtoM.objects.get(event=E,user=U) if attendance_hash == eTm.yes_hash: # it's a YES A.present = True A.timestamp = timezone.now() A.save() notify=True member=m message = settings.TEMPLATE_CONTENT['attendance']['yes'] % { 'name': gen_fullname(U), } actions = settings.TEMPLATE_CONTENT['attendance']['actions'] e_message = e_yes if attendance_hash == eTm.no_hash: # it's a NO A.present = False A.timestamp = timezone.now() A.save() notify=True message = settings.TEMPLATE_CONTENT['attendance']['no'] % { 'name': gen_fullname(U), } e_message = e_no if notify: #notify by email message_content = { 'FULLNAME' : gen_fullname(U), 'MESSAGE' : e_message, } #send email ok=notify_by_email(U.email,title,message_content) #set meeting: id and member_id for invitee link if actions: actions[0]['url'] += str(M.pk)+'/'+str(member.id) return render(r, settings.TEMPLATE_CONTENT['attendance']['template'], { 'title': title, 'actions' : actions, 'message': message, })