def forget_band_from_key(the_band_key): # delete all assocs the_assoc_keys = assoc.get_assocs_of_band_key(the_band_key, confirmed_only=False, keys_only=True) ndb.delete_multi(the_assoc_keys) # delete the sections the_section_keys = get_section_keys_of_band_key(the_band_key) ndb.delete_multi(the_section_keys) # delete the gigs the_gigs = gig.get_gigs_for_band_keys(the_band_key, num=None, start_date=None) the_gig_keys = [a_gig.key for a_gig in the_gigs] # delete the plans for a_gig_key in the_gig_keys: plan_keys = plan.get_plans_for_gig_key(a_gig_key, keys_only=True) ndb.delete_multi(plan_keys) ndb.delete_multi(the_gig_keys) stats.delete_band_stats(the_band_key) # delete the band the_band_key.delete()
def post(self): """ return the members for a band """ the_user = self.user the_band_key_str = self.request.get('bk', '0') if the_band_key_str == '0': return # todo figure out what to do the_band_key = band.band_key_from_urlsafe(the_band_key_str) assocs = assoc.get_assocs_of_band_key(the_band_key=the_band_key, confirmed_only=True) the_members = member.get_member([a.member for a in assocs]) the_members = sorted(the_members, key=lambda member: member.lower_name) # now sort the assocs to be in the same order as the member list assocs = sorted(assocs, key=lambda a: [m.key for m in the_members].index(a.member)) assoc_info = [] the_user_is_band_admin = False for i in range(0, len(assocs)): a = assocs[i] m = the_members[i] if a.default_section: s = a.default_section.get().name else: s = None assoc_info.append({ 'name': (m.nickname if m.nickname else m.name), 'is_confirmed': a.is_confirmed, 'is_band_admin': a.is_band_admin, 'is_occasional': a.is_occasional, 'member_key': a.member, 'section': s, 'is_multisectional': a.is_multisectional, 'assoc': a }) if a.member == the_user.key: the_user_is_band_admin = a.is_band_admin the_section_keys = band.get_band(the_band_key).sections the_sections = band.get_sections_from_keys(the_section_keys) template_args = { 'the_band_key': the_band_key, 'the_assocs': assoc_info, 'the_sections': the_sections, 'the_user_is_band_admin': the_user_is_band_admin, 'the_date_formatter': member.format_date_for_member, } self.render_template('band_members.html', template_args)
def _make_page(self, the_user): the_gig_keyurl = self.request.get("gk", '0') the_printall = self.request.get("printall", '1') if (the_gig_keyurl == '0'): return # todo what else to do? else: the_gig_key = gig.gig_key_from_urlsafe(the_gig_keyurl) the_gig = the_gig_key.get() the_band_key = the_gig_key.parent() the_assocs = assoc.get_assocs_of_band_key(the_band_key, confirmed_only=True, keys_only=False) the_plans = [] if the_printall == '1': printall = True else: printall = False need_empty_section = False for the_assoc in the_assocs: a_member_key = the_assoc.member the_plan = plan.get_plan_for_member_key_for_gig_key( a_member_key, the_gig_key) if the_plan.section == None and the_assoc.default_section == None: need_empty_section = True info_block = {} info_block['the_gig_key'] = the_gig.key info_block['the_plan_key'] = the_plan.key info_block['the_member_key'] = a_member_key info_block['the_band_key'] = the_band_key info_block['the_assoc'] = the_assoc if the_plan.section is not None: info_block['the_section'] = the_plan.section else: info_block['the_section'] = the_assoc.default_section the_plans.append(info_block) the_section_keys = band.get_section_keys_of_band_key(the_band_key) if need_empty_section: the_section_keys.append(None) template_args = { 'the_gig': the_gig, 'the_plans': the_plans, 'the_section_keys': the_section_keys, 'printall': printall } self.render_template('print_planlist.html', template_args)
def get(self): the_user = self.user the_band_keyurl = self.request.get('bk', '0') the_band_key = band.band_key_from_urlsafe(the_band_keyurl) if not is_authorized_to_edit_band(the_band_key, the_user): raise gigoexceptions.GigoException( 'user {0} trying to download users for band {1}'.format( self.user.key.urlsafe(), the_band_key.urlsafe())) self.response.headers['Content-Type'] = 'application/x-gzip' self.response.headers[ 'Content-Disposition'] = 'attachment; filename=members.csv' the_assocs = assoc.get_assocs_of_band_key(the_band_key) the_member_keys = [a.member for a in the_assocs] the_members = member.get_member(the_member_keys) section_keys = band.get_section_keys_of_band_key(the_band_key) sections = band.get_sections_from_keys(section_keys) section_map = {} for s in sections: section_map[s.key] = s.name member_section_map = {} member_data = {} for a in the_assocs: if a.default_section: section = section_map[a.default_section] else: section = '' if a.created: datestr = a.created.strftime('%m/%Y') else: datestr = '' member_data[a.member] = [section, datestr, a.commitment_number] data = "name,nickname,email,phone,section,joined,attended" for m in the_members: nick = m.nickname if m.nickname is None: nick = '' memdat = member_data[m.key] data = u"{0}\n{1},{2},{3},{4},{5},{6},{7}".format( data, m.name, nick, m.email_address, m.phone, memdat[0], memdat[1], memdat[2]) self.response.write(data)
def _make_page(self, the_user): the_gig_keyurl = self.request.get("gk", '0') the_printall = self.request.get("printall", '1') if (the_gig_keyurl == '0'): return # todo what else to do? else: the_gig_key = gig.gig_key_from_urlsafe(the_gig_keyurl) the_gig = the_gig_key.get() the_band_key = the_gig_key.parent() the_assocs = assoc.get_assocs_of_band_key(the_band_key, confirmed_only=True, keys_only=False) the_plans = [] if the_printall=='1': printall = True else: printall = False need_empty_section = False for the_assoc in the_assocs: a_member_key = the_assoc.member the_plan = plan.get_plan_for_member_key_for_gig_key(a_member_key, the_gig_key) if the_plan.section==None and the_assoc.default_section==None: need_empty_section = True info_block={} info_block['the_gig_key'] = the_gig.key info_block['the_plan_key'] = the_plan.key info_block['the_member_key'] = a_member_key info_block['the_band_key'] = the_band_key info_block['the_assoc'] = the_assoc if the_plan.section is not None: info_block['the_section'] = the_plan.section else: info_block['the_section'] = the_assoc.default_section the_plans.append(info_block) the_section_keys = band.get_section_keys_of_band_key(the_band_key) if need_empty_section: the_section_keys.append(None) template_args = { 'the_gig' : the_gig, 'the_plans' : the_plans, 'the_section_keys' : the_section_keys, 'printall' : printall } self.render_template('print_planlist.html', template_args)
def post(self): """ return the members for a band """ the_user = self.user the_band_key_str=self.request.get('bk','0') if the_band_key_str == '0': return # todo figure out what to do the_band_key = band.band_key_from_urlsafe(the_band_key_str) assocs = assoc.get_assocs_of_band_key(the_band_key=the_band_key, confirmed_only=True) the_members = member.get_member([a.member for a in assocs]) the_members = sorted(the_members,key=lambda member: member.lower_name) # now sort the assocs to be in the same order as the member list assocs = sorted(assocs,key=lambda a: [m.key for m in the_members].index(a.member)) assoc_info=[] the_user_is_band_admin = False for i in range(0,len(assocs)): a=assocs[i] m=the_members[i] if a.default_section: s = a.default_section.get().name else: s = None assoc_info.append( {'name':(m.nickname if m.nickname else m.name), 'is_confirmed':a.is_confirmed, 'is_band_admin':a.is_band_admin, 'is_occasional':a.is_occasional, 'member_key':a.member, 'section':s, 'is_multisectional':a.is_multisectional, 'assoc':a} ) if a.member == the_user.key: the_user_is_band_admin = a.is_band_admin the_section_keys = band.get_band(the_band_key).sections the_sections = band.get_sections_from_keys(the_section_keys) template_args = { 'the_band_key' : the_band_key, 'the_assocs' : assoc_info, 'the_sections' : the_sections, 'the_user_is_band_admin' : the_user_is_band_admin, } self.render_template('band_members.html', template_args)
def get(self): the_user = self.user the_band_keyurl = self.request.get('bk', '0') the_band_key = ndb.Key(urlsafe=the_band_keyurl) if not is_authorized_to_edit_band(the_band_key, the_user): return self.response.headers['Content-Type'] = 'application/x-gzip' self.response.headers[ 'Content-Disposition'] = 'attachment; filename=members.csv' the_assocs = assoc.get_assocs_of_band_key(the_band_key) the_member_keys = [a.member for a in the_assocs] the_members = ndb.get_multi(the_member_keys) section_keys = get_section_keys_of_band_key(the_band_key) sections = ndb.get_multi(section_keys) section_map = {} for s in sections: section_map[s.key] = s.name member_section_map = {} for a in the_assocs: if a.default_section: member_section_map[a.member] = section_map[a.default_section] else: member_section_map[a.member] = '' data = "name,nickname,email,phone,section" for m in the_members: nick = m.nickname if m.nickname is None: nick = '' sec = member_section_map[m.key] data = u"{0}\n{1},{2},{3},{4},{5}".format(data, m.name, nick, m.email_address, m.phone, sec) self.response.write(data)
def get(self): the_user = self.user the_band_keyurl=self.request.get('bk','0') the_band_key = band.band_key_from_urlsafe(the_band_keyurl) if not is_authorized_to_edit_band(the_band_key, the_user): raise gigoexceptions.GigoException('user {0} trying to download emails for band {1}'.format(self.user.key.urlsafe(),the_band_key.urlsafe())) the_assocs = assoc.get_assocs_of_band_key(the_band_key) the_member_keys = [a.member for a in the_assocs] the_members = member.get_member(the_member_keys) the_emails = [x.email_address for x in the_members if x.email_address is not None] template_args = { 'the_band' : band.get_band(the_band_key), 'the_emails' : ', '.join(the_emails) } self.render_template('band_emails.html', template_args)
def get(self): the_user = self.user the_band_keyurl=self.request.get('bk','0') the_band_key = band.band_key_from_urlsafe(the_band_keyurl) if not is_authorized_to_edit_band(the_band_key, the_user): raise gigoexceptions.GigoException('user {0} trying to download users for band {1}'.format(self.user.key.urlsafe(),the_band_key.urlsafe())) self.response.headers['Content-Type'] = 'application/x-gzip' self.response.headers['Content-Disposition'] = 'attachment; filename=members.csv' the_assocs = assoc.get_assocs_of_band_key(the_band_key) the_member_keys = [a.member for a in the_assocs] the_members = member.get_member(the_member_keys) section_keys = band.get_section_keys_of_band_key(the_band_key) sections = band.get_sections_from_keys(section_keys) section_map={} for s in sections: section_map[s.key] = s.name member_section_map={} for a in the_assocs: if a.default_section: member_section_map[a.member] = section_map[a.default_section] else: member_section_map[a.member] = '' data="name,nickname,email,phone,section" for m in the_members: nick = m.nickname if m.nickname is None: nick='' sec = member_section_map[m.key] data=u"{0}\n{1},{2},{3},{4},{5}".format(data,m.name,nick,m.email_address,m.phone,sec) self.response.write(data)
def get(self): the_user = self.user the_band_keyurl = self.request.get('bk', '0') the_band_key = band.band_key_from_urlsafe(the_band_keyurl) if not is_authorized_to_edit_band(the_band_key, the_user): raise gigoexceptions.GigoException( 'user {0} trying to download emails for band {1}'.format( self.user.key.urlsafe(), the_band_key.urlsafe())) the_assocs = assoc.get_assocs_of_band_key(the_band_key) the_member_keys = [a.member for a in the_assocs] the_members = member.get_member(the_member_keys) the_emails = [ x.email_address for x in the_members if x.email_address is not None ] template_args = { 'the_band': band.get_band(the_band_key), 'the_emails': ', '.join(the_emails) } self.render_template('band_emails.html', template_args)
def forget_band_from_key(the_band_key): # delete all assocs the_assoc_keys = assoc.get_assocs_of_band_key(the_band_key, confirmed_only=False, keys_only=True) ndb.delete_multi(the_assoc_keys) # delete the sections the_section_keys = get_section_keys_of_band_key(the_band_key) ndb.delete_multi(the_section_keys) # delete the gigs the_gigs = gig.get_gigs_for_band_keys(the_band_key, num=None, start_date=None) the_gig_keys = [a_gig.key for a_gig in the_gigs] # delete the plans for a_gig_key in the_gig_keys: plan_keys = plan.get_plans_for_gig_key(a_gig_key, keys_only = True) ndb.delete_multi(plan_keys) ndb.delete_multi(the_gig_keys) stats.delete_band_stats(the_band_key) # delete the band the_band_key.delete()
def _makeInfoPageInfo(the_user, the_gig, the_band_key): gig_key = the_gig.key the_assocs = assoc.get_assocs_of_band_key(the_band_key, confirmed_only=True, keys_only=False) # get all the plans for this gig - might actually not be any yet. all_plans = plan.get_plans_for_gig_key(gig_key, keys_only=False) # now, for each associated member, find or make a plan the_plans = [] the_new_plans = [] # in case we need to make new ones the_plan_counts = {} for i in range(len(plan.plan_text)): the_plan_counts[i] = 0 need_empty_section = False for the_assoc in the_assocs: a_member_key = the_assoc.member new_plan = False for p in all_plans: if p.member == a_member_key: the_plan = p break else: # no plan? make a new one planval = 0 if (the_gig.default_to_attending): planval = 1 the_plan = plan.Plan(parent=gig_key, member=a_member_key, value=planval, comment="", section=None) the_new_plans.append(the_plan) new_plan = True if (not the_assoc.is_occasional) or \ (the_assoc.is_occasional and the_plan.value != 0) or \ (a_member_key == the_user.key) or \ the_user.is_superuser: if the_plan.section == None and the_assoc.default_section == None: need_empty_section = True info_block = {} info_block['the_gig_key'] = the_gig.key info_block['the_plan'] = the_plan info_block['the_member_key'] = a_member_key info_block['the_band_key'] = the_band_key info_block['the_assoc'] = the_assoc if the_plan.section is not None: info_block['the_section'] = the_plan.section else: info_block['the_section'] = the_assoc.default_section the_plans.append(info_block) the_plan_counts[the_plan.value] += 1 if the_new_plans: ndb.put_multi(the_new_plans) the_section_keys = band.get_section_keys_of_band_key(the_band_key) the_sections = ndb.get_multi(the_section_keys) if need_empty_section: the_sections.append(None) if len(the_section_keys) == 0: band_has_sections = False else: band_has_sections = True return the_plans, the_plan_counts, the_sections, band_has_sections
def _make_page(self, the_user): # find the gig we're interested in gig_key_str = self.request.get("gk", None) if gig_key_str is None: self.response.write('no gig key passed in!') return # todo figure out what to do if there's no ID passed in gig_key = ndb.Key(urlsafe=gig_key_str) the_gig = gig_key.get() if the_gig is None: template_args = {} self.render_template('no_gig_found.html', template_args) return # todo figure out what to do if we didn't find it the_comment_text = None if the_gig.comment_id: the_comment_text = gigcomment.get_comment(the_gig.comment_id) if not the_gig.is_archived: the_band_key = the_gig.key.parent() the_assocs = assoc.get_assocs_of_band_key(the_band_key, confirmed_only=True, keys_only=False) # get all the plans for this gig - might actually not be any yet. all_plans = plan.get_plans_for_gig_key(gig_key, keys_only=False) # now, for each associated member, find or make a plan the_plans = [] the_new_plans = [] # in case we need to make new ones the_plan_counts = {} for i in range(len(plan.plan_text)): the_plan_counts[i] = 0 need_empty_section = False for the_assoc in the_assocs: a_member_key = the_assoc.member new_plan = False for p in all_plans: if p.member == a_member_key: the_plan = p break else: the_plan = plan.Plan(parent=gig_key, member=a_member_key, value=0, comment="", section=None) the_new_plans.append(the_plan) new_plan = True if (not the_assoc.is_occasional) or \ (the_assoc.is_occasional and the_plan.value != 0) or \ (a_member_key == the_user.key) or \ the_user.is_superuser: if the_plan.section == None and the_assoc.default_section == None: need_empty_section = True info_block = {} info_block['the_gig_key'] = the_gig.key info_block['the_plan'] = the_plan info_block['the_member_key'] = a_member_key info_block['the_band_key'] = the_band_key info_block['the_assoc'] = the_assoc if the_plan.section is not None: info_block['the_section'] = the_plan.section else: info_block['the_section'] = the_assoc.default_section the_plans.append(info_block) the_plan_counts[the_plan.value] += 1 if the_new_plans: ndb.put_multi(the_new_plans) the_section_keys = band.get_section_keys_of_band_key(the_band_key) the_sections = ndb.get_multi(the_section_keys) if need_empty_section: the_sections.append(None) if len(the_section_keys) == 0: band_has_sections = False else: band_has_sections = True # is the current user a band admin? the_user_is_band_admin = assoc.get_admin_status_for_member_for_band_key( the_user, the_band_key) the_band = the_band_key.get() user_can_edit = can_edit_gig(the_user, the_gig, the_band) user_can_create = can_edit_gig(the_user, None, the_band) datestr = member.format_date_for_member(the_user, the_gig.date, format="long") if the_gig.enddate: enddatestr = u' - {0}'.format( member.format_date_for_member(the_user, the_gig.enddate, format="long")) else: enddatestr = '' template_args = { 'gig': the_gig, 'date_str': datestr, 'enddate_str': enddatestr, 'the_plans': the_plans, 'the_sections': the_sections, 'comment_text': the_comment_text, 'band_has_sections': band_has_sections, 'the_user_is_band_admin': the_user_is_band_admin, 'user_can_edit': user_can_edit, 'user_can_create': user_can_create, 'the_plan_counts': the_plan_counts } self.render_template('gig_info.html', template_args) else: # this is an archived gig the_archived_plans = gigarchive.get_archived_plans( the_gig.archive_id) template_args = { 'gig': the_gig, 'archived_plans': the_archived_plans, 'comment_text': the_comment_text } self.render_template('gig_archived_info.html', template_args)
def _makeInfoPageInfo(the_user, the_gig, the_band_key): gig_key = the_gig.key the_assocs = assoc.get_assocs_of_band_key(the_band_key, confirmed_only=True, keys_only=False) # get all the plans for this gig - might actually not be any yet. all_plans = plan.get_plans_for_gig_key(gig_key, keys_only=False) # now, for each associated member, find or make a plan the_plans = [] the_new_plans = [] # in case we need to make new ones the_plan_counts={} for i in range(len(plan.plan_text)): the_plan_counts[i]=0 need_empty_section = False for the_assoc in the_assocs: a_member_key = the_assoc.member new_plan = False for p in all_plans: if p.member == a_member_key: the_plan = p break else: # no plan? make a new one planval = 0 if ( the_gig.default_to_attending ): planval = 1 the_plan = plan.Plan(parent=gig_key, member=a_member_key, value=planval, comment="", section=None) the_new_plans.append(the_plan) new_plan = True if (not the_assoc.is_occasional) or \ (the_assoc.is_occasional and the_plan.value != 0) or \ (a_member_key == the_user.key) or \ the_user.is_superuser: if the_plan.section==None and the_assoc.default_section==None: need_empty_section = True info_block={} info_block['the_gig_key'] = the_gig.key info_block['the_plan'] = the_plan info_block['the_member_key'] = a_member_key info_block['the_band_key'] = the_band_key info_block['the_assoc'] = the_assoc if the_plan.section is not None: info_block['the_section'] = the_plan.section else: info_block['the_section'] = the_assoc.default_section the_plans.append(info_block) the_plan_counts[the_plan.value] += 1 if the_new_plans: ndb.put_multi(the_new_plans) the_section_keys = band.get_section_keys_of_band_key(the_band_key) the_sections = ndb.get_multi(the_section_keys) if need_empty_section: the_sections.append(None) if len(the_section_keys)==0: band_has_sections = False else: band_has_sections = True return the_plans, the_plan_counts, the_sections, band_has_sections
def _make_page(self, the_user): # find the gig we're interested in gig_key_str = self.request.get("gk", None) if gig_key_str is None: self.response.write('no gig key passed in!') return # todo figure out what to do if there's no ID passed in gig_key = ndb.Key(urlsafe=gig_key_str) the_gig = gig_key.get() if the_gig is None: template_args = {} self.render_template('no_gig_found.html', template_args) return # todo figure out what to do if we didn't find it the_comment_text = None if the_gig.comment_id: the_comment_text = gigcomment.get_comment(the_gig.comment_id) if not the_gig.is_archived: the_band_key = the_gig.key.parent() the_assocs = assoc.get_assocs_of_band_key(the_band_key, confirmed_only=True, keys_only=False) the_plans = [] need_empty_section = False for the_assoc in the_assocs: a_member_key = the_assoc.member the_plan = plan.get_plan_for_member_key_for_gig_key(a_member_key, gig_key) if (not the_assoc.is_occasional) or \ (the_assoc.is_occasional and the_plan.value != 0) or \ (a_member_key == the_user.key) or \ the_user.is_superuser: if the_plan.section==None and the_assoc.default_section==None: need_empty_section = True info_block={} info_block['the_gig_key'] = the_gig.key info_block['the_plan_key'] = the_plan.key info_block['the_member_key'] = a_member_key info_block['the_band_key'] = the_band_key info_block['the_assoc'] = the_assoc if the_plan.section is not None: info_block['the_section'] = the_plan.section else: info_block['the_section'] = the_assoc.default_section the_plans.append(info_block) the_section_keys = band.get_section_keys_of_band_key(the_band_key) the_sections = ndb.get_multi(the_section_keys) if need_empty_section: the_sections.append(None) if len(the_section_keys)==0: band_has_sections = False else: band_has_sections = True # is the current user a band admin? user_is_band_admin = assoc.get_admin_status_for_member_for_band_key(the_user, the_band_key) user_can_edit = False if user_is_band_admin or the_user.is_superuser: user_can_edit = True elif the_band_key.get().anyone_can_manage_gigs: user_can_edit = True datestr = member.format_date_for_member(the_user, the_gig.date, format="long") if the_gig.enddate: enddatestr = u' - {0}'.format(member.format_date_for_member(the_user, the_gig.enddate, format="long")) else: enddatestr = '' template_args = { 'gig' : the_gig, 'date_str' : datestr, 'enddate_str' : enddatestr, 'the_plans' : the_plans, 'the_sections' : the_sections, 'comment_text' : the_comment_text, 'band_has_sections' : band_has_sections, 'user_is_band_admin' : user_is_band_admin, 'user_can_edit' : user_can_edit } self.render_template('gig_info.html', template_args) else: # this is an archived gig the_archived_plans = gigarchive.get_archived_plans(the_gig.archive_id) template_args = { 'gig' : the_gig, 'archived_plans' : the_archived_plans, 'comment_text' : the_comment_text } self.render_template('gig_archived_info.html', template_args)