def cancel_button(who, eqty_id, role, button_text, django_request): return T.form(action=django.urls.reverse("training:cancel"), method='POST')[T.input(type="hidden", name="equiptype", value=eqty_id), T.input(type="hidden", name="role", value=role), T.input(type="hidden", name="person", value=who._id), T.input(type="hidden", name="csrfmiddlewaretoken", value=django.middleware.csrf.get_token(django_request)), T.button(type="submit", value="cancel_request")[button_text]]
def display_or_form(class_name, action_as_form, headers, row_order, labels_dict, data_dict): """Display some data either with or without form inputs to update it.""" table = T.table(class_=class_name)[ T.thead[T.tr[[[T.th[header] for header in (headers or ["Key", "Value"])]]]], T.tbody[[[T.tr[T.th(class_='ralabel')[(labels_dict.get(item, item.capitalize()) if labels_dict else item.capitalize())], T.td[(T.input(type='text', name='item', value=plain_value(data_dict.get(item, ""))) if action_as_form else linked_value(data_dict.get(item, "")))]]] for item in row_order if (action_as_form # display all the fields, even blank ones, if presenting a form # if presenting a read-only display, skip any blank fields: or data_dict.get(item, None) != None)]], T.tfoot[T.tr[T.td[""], T.td[T.input(type='submit', value=[(labels_dict or {'submit': "Submit changes"}).get('submit', "Submit changes")])]]]] return T.form(action=action_as_form, method='POST')[table] if action_as_form else table
def user_list_section(django_request, include_non_members=False, filter_fn=None, filter_opaque=None): """Return the users list, if the viewing person is allowed to see it. Otherwise, just how many people there are. The optional first argument is a flag for whether to include non-members. The optional second argument is a boolean function taking a person object, returning whether to include them in the list. This could be used for things like listing people whose fobs are ready for enabling, or who have missed paying their latest subscription. A third argument is passed through to that function.""" global serverconf if serverconf == None: serverconf = configuration.get_config()['server'] viewing_user = model.person.Person.find(django_request.user.link_id) people = person.Person.list_all_people( ) if include_non_members else person.Person.list_all_members() if filter_fn: people = [ someone for someone in people if filter_fn(someone, filter_opaque) ] people_dict = {whoever.name(): whoever for whoever in people} if viewing_user.is_auditor() or viewing_user.is_admin(): return T.table[[ T.tr[T.th(class_='mem_num')["Mem #"], T.th(class_='username')["Name"], T.th(class_='loginh')["Login"], T.th(class_='flagsh')["Flags"], T.th(class_='email')["Email"], T.th(class_='user')["User"], T.th(class_='owner')["Owner"], T.th(class_='trainer')["Trainer"], T.th(class_='note')["Notes"]] ], [ T.tr[T.td(class_='mem_num')[str(who.membership_number)], T.th(class_='username')[T.a( href=django.urls. reverse('dashboard:user_dashboard', args=( [who.link_id])))[whoname]], T.td(class_='login')[who.get_login_name() or ""], T.td(class_='flags')[flagstring(who)], T.td(class_='email')[T.a( href="mailto:" + who.get_email() or "")[who.get_email() or ""]], T.td(class_='user' )[equipment_type_role_name_list(who, 'user')], T.td(class_='owner' )[equipment_type_role_name_list(who, 'owner')], T.td(class_='trainer' )[equipment_type_role_name_list(who, 'trainer')], T.td(class_='note')[T.form()[who.get_admin_note() or ""]]] for (whoname, who) in [(key, people_dict[key]) for key in sorted(people_dict.keys())] ]] else: return T.p["There are " + str(len(people)) + (" people" if include_non_members else " members") + " in the database."]
def schedule_event_form(who, extras, button_text, django_request): return (T.form(action=django.urls.reverse("events:new_event"), method='POST') ["Date and time: ", T.input(type="datetime", name="when"), T.br, extras, T.input(type="hidden", name="submitter", value=str(who._id)), T.input(type="hidden", name="csrfmiddlewaretoken", value=django.middleware.csrf.get_token(django_request)), T.button(type="submit", value="schedule")[button_text]])
def create_event(django_request): """The first stage of event creation. This sets up the parameters based on the event template.""" config_data = model.configuration.get_config() model.database.database_init(config_data) viewer = model.person.Person.find(django_request.user.link_id) request_params = django_request.GET template_name = request_params.get('event_type', None) if template_name is None or template_name == "": return admin_error_page(django_request, "Event creation error", "No template name given") equipment_type = request_params.get('equipment_type', "") suggested_time = request_params.get('start', "") template = model.event.Event.find_template(template_name) page_data = model.pages.HtmlPage( "Create event", pages.page_pieces.top_navigation(django_request), django_request=django_request) form = T.form( action=django.urls.reverse("makers_admin:create_event_2"), method='POST' )[T.input(type="hidden", name="csrfmiddlewaretoken", value=django.middleware.csrf.get_token(django_request)), T.table[T.tr[ T.th(class_="ralabel")["When"], T.td[T.input(type='datetime', name='start', value=suggested_time)]], T.tr[ T.th(class_="ralabel")["Equipment type"], T.td[pages.page_pieces. equipment_type_dropdown('equipment_type', equipment_type )]], [[ T.tr[T.th( class_="ralabel")[k.replace('_', ' ').capitalize()], T.td[T.input(type='text', name=k, value=str(template[k]). replace('$equipment', equipment_type))]] ] for k in sorted(template.keys()) if k != '_id'], T.tr[T.td[""], T.td[T.input(type='submit', value="Create event")]]]] page_data.add_content( "Event creation form", model.pages.with_help(viewer, form, "event_creation")) return HttpResponse(str(page_data.to_string()))
def special_event_form(eqtype, who_id, role, enable, css_class, button_label, django_request): return T.form(action=django.urls.reverse("events:special"), class_=css_class, method='POST')[T.input(type='hidden', name='eqtype', value=eqtype._id), T.input(type='hidden', name='who', value=who_id), T.input(type='hidden', name='admin_user', value=model.person.Person.find(django_request.user.link_id)._id), T.input(type='hidden', name='role', value=role), T.input(type='hidden', name='enable', value=enable), "Days", T.input(type='text', name='duration', value="indefinite", size=len("indefinite")), T.input(type="hidden", name="csrfmiddlewaretoken", value=django.middleware.csrf.get_token(django_request)), T.input(type='submit', value=button_label)]
def availform(who, available, django_request): days, _, times = model.timeslots.get_slots_conf() return (T.div(class_="availability") [T.form(action=django.urls.reverse("dashboard:update_availability"), method="POST") [T.table(class_="availability") [[T.thead[T.tr[T.th(class_="daylabel")["Day"], [[T.th[slotname]] for slotname in times]]]], T.tbody[[[T.tr[T.th(class_="daylabel")[day], [T.td[T.input(type="checkbox", name=day+"_"+t, checked="checked") if b else T.input(type="checkbox", name=day+"_"+t)] for t, b in zip(times, day_slots)]]] for (day, day_slots) in zip(days, model.timeslots.timeslots_from_int(available))]]], T.input(type="hidden", name="csrfmiddlewaretoken", value=django.middleware.csrf.get_token(django_request)), T.input(type='hidden', name='person', value=str(who._id)), T.input(type="submit", value="Update availability")]])
def edit_event_template(django_request): config_data = model.configuration.get_config() model.database.database_init(config_data) params = django_request.GET if 'event_template_name' not in params: return admin_error_page(django_request, "Missing parameter", "'event_template_name' not set in params") template_name = params['event_template_name'] template_data = { key: "" for key in config_data['event_templates']['standard_fields'] } template_data.update(model.database.find_event_template(template_name)) form = [ T.form(action=django.urls.reverse('makers_admin:save_template_edits'), method='POST') [T.input(type="hidden", name="csrfmiddlewaretoken", value=django.middleware.csrf.get_token(django_request)), T.input( type='hidden', name='original_template_name', value=template_name ), T.table[[ T.tr[T.th(class_='ralabel')[name], T.td[template_field(name, template_data[name])]] for name in sorted(template_data.keys()) ], T.tr[T.td[""], T.td[T.input(type='submit', value="Save template")]]]] ] page_data = model.pages.HtmlPage( "Event template editor", pages.page_pieces.top_navigation(django_request), django_request=django_request) page_data.add_content(template_name + " event template", form) return HttpResponse(str(page_data.to_string()))
def interests_section(interest_levels, mail_levels, django_request, for_person=None): interest_areas = model.configuration.get_config('interest_areas') if interest_areas is None: return [] existing_interests = {area_name: interest_levels.get(area_name, 0) for area_name in interest_areas} return [T.form(action=django.urls.reverse("dashboard:update_levels"), method="POST") [T.table(class_="interests_check_table") [T.thead[T.tr[[T.th["Area"], [[[T.th(class_='level_'+str(lev))[str(lev)]] for lev in range(4)]]]]], T.tbody[[[T.tr[T.th[area], [[[interests_button(area, existing_interests[area], lev)] for lev in range(4)]]]] for area in sorted(interest_areas)]], (T.tfoot[T.tr[T.th["Mail me about events"], T.td[""], [[[T.td[(T.input(type='checkbox', name='mail_'+str(lev), checked='checked') if mail_levels[lev] else T.input(type='checkbox', name='mail_'+str(lev)))]] for lev in range(1,4)]]]] if mail_levels else "")], T.input(type="hidden", name="csrfmiddlewaretoken", value=django.middleware.csrf.get_token(django_request)), # This form can be used either for a person, or for an event T.input(type='hidden', name='subject_user_uuid', value=for_person._id) if for_person else "", T.div(align="right")[T.input(type="submit", value="Update interests")]], T.input(type="hidden", name="csrfmiddlewaretoken", value=django.middleware.csrf.get_token(django_request))]
def invitation_response_form_page(rsvp_uuid): """From an invitation UUID that was mailed to someone, produce a response form.""" global server_conf server_conf = configuration.get_config('server') page_pieces.set_server_conf() person_responding = person.Person.find(database.find_rsvp(rsvp_uuid)) # set up viewing as though the user has actually logged in access_permissions.Access_Permissions.setup_access_permissions(person_responding.link_id) # todo: also tell django that they are effectively logged in? event_responding = event.Event.find_by_id(person_responding.invitations[rsvp_uuid]) form_act = django.urls.reverse("events:rsvp_form", args=[rsvp_uuid]) return T.div(class_="invitresp")[ T.h1["RSVP for " + person_responding.name(access_permissions_event=event_responding)], T.p["This is a " + event_responding.event_type + " event starting at " + str(event_responding.start) + ". The event will be hosted by " + ". and ".join([obj.name(access_permissions_role='host') for obj in event_responding.hosts if obj is not None]) + "."], T.form(action=form_act, method='POST')[ T.input(type="hidden", name="rsvp_uuid", value=rsvp_uuid), T.table[T.tr[T.td[T.input(type='radio', name='rsvp', value='accept')], T.td["Accept invitation"]], T.tr[T.td[T.input(type='radio', name='rsvp', value='decline')], T.td["Decline invitation"]], T.tr[T.td[T.input(type='radio', name='rsvp', value='drop')], T.td["Decline invitation and cancel training request"]]], T.input(type="submit", value="Send response")]]
def one_event_section(ev, who, django_request, with_rsvp=False, rsvp_id=None, with_completion=False, completion_as_form=False, allow_editing=False): allow_editing = who.is_administrator() all_people_ids = ev.signed_up all_people_id_to_name = { p: model.person.Person.find(p).name() for p in all_people_ids } all_people_name_and_id = [(all_people_id_to_name[id], id) for id in all_people_id_to_name.keys()] ids_in_order = [] for name in sorted(all_people_id_to_name.values()): for pair in all_people_name_and_id: if name == pair[0]: ids_in_order.append(pair[1]) hosts = people_list(ev.hosts) # print("Looking for equipment type", ev.equipment_type) eqty = model.equipment_type.Equipment_type.find_by_id(ev.equipment_type) eqty_name = eqty.name if eqty else "---" results = [( T.table(class_='event_details') [T.tr[T.th(class_="ralabel")["Title"], T.td( class_="event_title" )[T.input(type='text', name='title', value=ev.display_title( )) if allow_editing else T.a( href=event_link(ev, django_request))[ev.display_title()]]], T.tr[T.th(class_="ralabel")["Event type"], T.td( class_="event_type" )[T.input(type='text', name='event_type', value=ev.event_type ) if allow_editing else ev.event_type]], T.tr[T.th(class_="ralabel")["Start time"], T.td(class_="event_start" )[T.input(type='datetime', name='start', value=model.times.timestring(ev.start) ) if allow_editing else model.times. timestring(ev.start)]], T. tr[T.th(class_="ralabel")["Duration"], T.td( class_="event_duration" )[T. input(type='text', name='duration', value=str(ev.end - ev.start) ) if allow_editing else str(ev.end - ev.start)]], T.tr[T.th(class_="ralabel")["End time"], T.td(class_="event_end")[model.times.timestring(ev.end)]], T.tr[T.th(class_="ralabel")["Location"], T.td(class_="location" )[pages.page_pieces. location_dropdown('location', ev.location ) if allow_editing else ev.location]], T.tr[T.th(class_="ralabel")["Equipment type"], T.td(class_="event_equipment_type" )[pages.page_pieces.equipment_type_dropdown( 'event_equipment_type', eqty_name ) if allow_editing else eqty_name]], # todo: linkify T.tr[T.th(class_="ralabel")["Hosts"], T.td(class_="hosts" )[T.input(type='text', name='hosts', value=hosts ) if allow_editing else hosts]], T.tr[T.th(class_="ralabel")["Event ID and link"], T.td(class_="event_id")[T.a( href=event_link(ev, django_request))[str(ev._id)]]], (T.tr[T.th(class_="ralabel")[""], T.td[T.input(type='submit', value="Update event details" )]] if allow_editing else "")])] if ev.catered: result += [T.h3["Catering information"], avoidances_subsection(ev)] if allow_editing: results = [ T.form(action=django.urls.reverse("events:update_event"), method='POST') [results, T.input(type='hidden', name='event_id', value=ev._id), T.input(type="hidden", name="csrfmiddlewaretoken", value=django.middleware.csrf.get_token(django_request))] ] if with_rsvp: results += [ T.h4["Reply to invitation"], T.form(action=django.urls.reverse("events:rsvp"), method='POST') [T.input(type='hidden', name='rsvp_id', value=rsvp_id), T.input(type="hidden", name="csrfmiddlewaretoken", value=django.middleware.csrf.get_token(django_request)), T.ul[T.li[T.input(type='radio', name='response', value='accept'), "Accept"], T.li[T.input(type='radio', name='response', value='decline'), "Decline"], T.li[T.input(type='radio', name='response', value='drop'), "Decline and cancel request"]], T.input(type='submit', value="Reply")] ] if ev.signed_up and len(ev.signed_up) > 0: results += [ T.h4["Users signed up to event"], T.ul[[[T.li[person_name(sup)] for sup in ev.signed_up]]] ] # if who._id in ev.signed_up: # pass # todo: form to back out of attending event (must rescan to mail waiting list) if with_completion: completion_table = (T.table(class_='event_completion')[T.thead[T.tr[ T.th["Name"], T.th(class_='unknown')["Unknown"], T.th(class_='no_show')["No-show"], T.th(class_='failed')["Failed"], T.th(class_='passed')["Passed"]]], T.tbody[[[ T.tr[T.th[all_people_id_to_name[id]], (T.td( class_='unknown')[result_button(id, "unknown", ( id not in ev.noshow and id not in ev.failed and id not in ev.passed))]), (T.td(class_='no_show' )[result_button(id, "noshow", id in ev.noshow)]), (T.td(class_='failed' )[result_button(id, "failed", id in ev.failed)]), (T.td(class_='passed' )[result_button(id, "passed", id in ev.passed)])] for id in ids_in_order ]]], (T.tfoot[T.tr[ T.td(colspan="2")[""], T.td( colspan="3")[T.input(type='submit', value="Record results" )]]] if completion_as_form else "")]) # todo: signup if in the future results += [ T.h4["Results"], ((T.form(action=django.urls.reverse("events:results"), method="POST") [T.input(type="hidden", name='event_id', value=ev._id), T.input(type="hidden", name="csrfmiddlewaretoken", value=django.middleware.csrf.get_token(django_request)), completion_table]) if completion_as_form else completion_table) ] return [ T.h3[ev.title.replace('_', ' ').capitalize() if ev.title else "Event"], results ]
def signup_button(event_id, who_id, button_text, django_request): return T.form(action=django.urls.reverse("events:signup"), method='POST')[T.input(type="hidden", name="event_id", value=event_id), T.input(type="hidden", name="person_id", value=who_id), T.input(type="hidden", name="csrfmiddlewaretoken", value=django.middleware.csrf.get_token(django_request)), T.button(type="submit", value="cancel_request")[button_text]]