def _make_page(self,the_user): """ construct page for grid view """ # find the bands this member is associated with if not the_user.is_superuser: the_assocs = assoc.get_confirmed_assocs_of_member(the_user) the_band_keys = [a.band for a in the_assocs] else: the_band_keys = band.get_all_bands(keys_only=True) if the_band_keys is None or len(the_band_keys)==0: return self.redirect('/member_info.html?mk={0}'.format(the_user.key.urlsafe())) # find the band we're interested in band_key_str=self.request.get("bk", None) if band_key_str is None: the_band_key = the_band_keys[0] else: the_band_key = ndb.Key(urlsafe=band_key_str) month_str=self.request.get("m",None) year_str=self.request.get("y",None) if month_str==None or year_str==None: start_date = datetime.datetime.now().replace(day=1) else: delta=0 delta_str=self.request.get("d",None) if delta_str != None: delta=int(delta_str) year=int(year_str) month=int(month_str) month=month+delta if month>12: month = 1 year = year+1 if month<1: month=12 year = year-1 start_date = datetime.datetime(year=year, month=month, day=1) end_date = start_date if (end_date.month < 12): end_date = end_date.replace(month = end_date.month + 1, day = 1) else: end_date = end_date.replace(year = end_date.year + 1, month=1, day=1) show_canceled=True if the_user.preferences and the_user.preferences.hide_canceled_gigs: show_canceled=False the_gigs = gig.get_gigs_for_band_key_for_dates(the_band_key, start_date, end_date, get_canceled=show_canceled) the_member_assocs = band.get_assocs_of_band_key_by_section_key(the_band_key, include_occasional=False) the_plans = {} for section in the_member_assocs: for an_assoc in section[1]: member_key=an_assoc.member member_plans = {} for a_gig in the_gigs: the_plan = plan.get_plan_for_member_key_for_gig_key(the_member_key=member_key, the_gig_key=a_gig.key) if the_plan is not None: member_plans[a_gig.key] = the_plan.value the_plans[member_key] = member_plans template_args = { 'all_band_keys' : the_band_keys, 'the_band_key' : the_band_key, 'the_member_assocs_by_section' : the_member_assocs, 'the_month_string' : member.format_date_for_member(the_user, start_date, 'month'), 'the_month' : start_date.month, 'the_year' : start_date.year, 'the_date_formatter' : member.format_date_for_member, 'the_gigs' : the_gigs, 'the_plans' : the_plans, 'grid_is_active' : True } self.render_template('grid.html', template_args)
def _make_page(self,the_user): """ construct page for agenda view """ # find the bands this member is associated with the_assocs = assoc.get_confirmed_assocs_of_member(the_user) the_band_keys = [a.band for a in the_assocs] if the_band_keys is None or len(the_band_keys)==0: return self.redirect('/member_info.html?mk={0}'.format(the_user.key.urlsafe())) if the_user.show_long_agenda: num_to_put_in_upcoming=1000 else: num_to_put_in_upcoming=5 show_canceled=True if the_user.preferences and the_user.preferences.hide_canceled_gigs: show_canceled=False all_gigs=[] for bk in the_band_keys: b = bk.get() today_date = datetime.datetime.combine(datetime.datetime.now(tz=pytz.timezone(b.timezone)), datetime.time(0,0,0)) # the_gigs = gig.get_gigs_for_bands(the_bands, num=num_to_put_in_upcoming, start_date=today_date) some_gigs = gig.get_gigs_for_band_keys(bk, show_canceled=show_canceled, start_date=today_date) all_gigs = all_gigs + some_gigs all_gigs = sorted(all_gigs, key=lambda gig: gig.date) upcoming_plans = [] weighin_plans = [] if all_gigs: for i in range(0, len(all_gigs)): a_gig = all_gigs[i] the_plan = plan.get_plan_for_member_for_gig(the_user, a_gig) info_block={} info_block['the_gig_key'] = a_gig.key info_block['the_plan_key'] = the_plan.key info_block['the_member_key'] = the_user.key a_band_key = a_gig.key.parent() a_band = None for test_band_key in the_band_keys: if test_band_key == a_band_key: a_band_key = test_band_key break if a_band_key == None: logging.error('agenda.MainPage error: no band for gig') continue info_block['the_band'] = a_band_key.get() info_block['the_assoc'] = assoc.get_assoc_for_band_key_and_member_key(the_user.key, a_band_key) if the_plan.section is None: info_block['the_section'] = info_block['the_assoc'].default_section else: info_block['the_section'] = the_plan.section if num_to_put_in_upcoming and i<num_to_put_in_upcoming and (the_plan.value or a_gig.status == 2): #include gigs for which we've weighed in or have been cancelled upcoming_plans.append( info_block ) else: if (the_plan.value == 0 ): weighin_plans.append( info_block ) number_of_bands = len(the_band_keys) template_args = { 'upcoming_plans' : upcoming_plans, 'weighin_plans' : weighin_plans, 'show_band' : number_of_bands>1, 'long_agenda' : the_user.show_long_agenda, 'the_date_formatter' : member.format_date_for_member, 'agenda_is_active' : True, 'colors' : colors } self.render_template('agenda.html', template_args)
def post(self): the_user = self.user start_date=datetime.datetime.strptime( self.request.get('start'), "%Y-%m-%d" ) end_date=datetime.datetime.strptime( self.request.get('end'), "%Y-%m-%d" )+datetime.timedelta(days=1) the_member_keyurl=self.request.get('mk',0) if the_member_keyurl==0: return # todo figure out what to do the_member_key=ndb.Key(urlsafe=the_member_keyurl) the_member = the_member_key.get() the_assocs = assoc.get_confirmed_assocs_of_member(the_member) the_band_keys = [a.band for a in the_assocs] the_bands = ndb.get_multi(the_band_keys) cindices={} for a in the_assocs: cindices[a.band]=a.color gigs = [] for a_band in the_bands: a_band_name = a_band.shortname if a_band.shortname else a_band.name all_gigs = gig.get_gigs_for_band_keys(a_band.key, show_past=True) for a_gig in all_gigs: if not a_gig.is_canceled: the_plan = plan.get_plan_for_member_key_for_gig_key(the_member_key, a_gig.key) if the_plan: # check member preferences # include gig if member wants to see all, or if gig is confirmed if a_gig.is_confirmed or the_member.preferences.calendar_show_only_confirmed == False: # incude gig if member wants to see all, or if has registered as maybe or definitely: if (the_plan.value > 0 and the_plan.value <= 3) or \ (the_member.preferences.calendar_show_only_committed == False): gigs.append(a_gig) events=[] the_band_keys = [b.key for b in the_bands] num_bands = len(the_band_keys) for a_gig in gigs: band_key=a_gig.key.parent() # cindex = the_band_keys.index(band_key) % len(colors) cindex = cindices[band_key] the_title = a_gig.title if num_bands > 1: the_band = band_key.get() if the_band.shortname: the_title = u'{0}:\n{1}'.format(the_band.shortname, the_title) else: the_title = u'{0}:\n{1}'.format(the_band.name, the_title) events.append({ 'title':the_title, 'start':str(a_gig.date.date()), 'end': str(a_gig.enddate+datetime.timedelta(days=1)) if a_gig.enddate else None, 'url':'/gig_info.html?gk={0}'.format(a_gig.key.urlsafe()), 'borderColor':colors[cindex] }) testevent=json.dumps(events) self.response.write( testevent )
def post(self): the_user = self.user start_date=datetime.datetime.strptime( self.request.get('start'), "%Y-%m-%d" ) end_date=datetime.datetime.strptime( self.request.get('end'), "%Y-%m-%d" )+datetime.timedelta(days=1) the_member_keyurl=self.request.get('mk',0) if the_member_keyurl==0: return # todo figure out what to do the_member_key=ndb.Key(urlsafe=the_member_keyurl) the_member = the_member_key.get() the_assocs = assoc.get_confirmed_assocs_of_member(the_member) the_band_keys = [a.band for a in the_assocs] # the_bands = ndb.get_multi(the_band_keys) cindices={} for a in the_assocs: cindices[a.band]=a.color gigs = [] all_gigs = gig.get_gigs_for_band_keys(the_band_keys, show_past=True, start_date=start_date, end_date=end_date) for a_gig in all_gigs: if not a_gig.is_canceled and not a_gig.hide_from_calendar: the_plan = plan.get_plan_for_member_key_for_gig_key(the_member_key, a_gig.key) if the_plan: # check member preferences # include gig if member wants to see all, or if gig is confirmed if a_gig.is_confirmed or the_member.preferences.calendar_show_only_confirmed == False: # incude gig if member wants to see all, or if has registered as maybe or definitely: if (the_plan.value > 0 and the_plan.value <= 3) or \ (the_member.preferences.calendar_show_only_committed == False): gigs.append(a_gig) events=[] num_bands = len(the_band_keys) band_names={} for a_gig in gigs: band_key=a_gig.key.parent() # cindex = the_band_keys.index(band_key) % len(colors) cindex = cindices[band_key] the_title = a_gig.title if num_bands > 1: if band_key in band_names.keys(): the_band_name = band_names[band_key] else: the_band = band_key.get() if the_band.shortname: the_band_name = the_band.shortname else: the_band_name = the_band.name band_names[band_key] = the_band_name the_title = u'{0}:\n{1}'.format(the_band_name, the_title) events.append({ 'title':the_title, 'start':str(a_gig.date.date()), 'end': str(a_gig.enddate+datetime.timedelta(days=1)) if a_gig.enddate else None, 'url':'/gig_info.html?gk={0}'.format(a_gig.key.urlsafe()), 'borderColor':colors[cindex] }) testevent=json.dumps(events) self.response.write( testevent )
def _get_agenda_contents_for_member(the_user): # find the bands this member is associated with the_assocs = assoc.get_confirmed_assocs_of_member(the_user, include_hidden=False) the_band_keys = [a.band for a in the_assocs] if the_band_keys is None or len(the_band_keys) == 0: raise Exception("no agenda") if the_user.show_long_agenda: num_to_put_in_upcoming = 1000 else: num_to_put_in_upcoming = 5 show_canceled = True if the_user.preferences and the_user.preferences.hide_canceled_gigs: show_canceled = False all_gigs = gig.get_sorted_gigs_from_band_keys( the_band_keys=the_band_keys, include_canceled=show_canceled) upcoming_plans = [] weighin_plans = [] if all_gigs: for i in range(0, len(all_gigs)): a_gig = all_gigs[i] the_plan = plan.get_plan_for_member_for_gig(the_user, a_gig) info_block = {} info_block['the_gig'] = a_gig info_block['the_plan'] = the_plan info_block['the_member'] = the_user a_band_key = a_gig.key.parent() a_band = None for test_band_key in the_band_keys: if test_band_key == a_band_key: a_band_key = test_band_key break if a_band_key == None: logging.error('agenda.MainPage error: no band for gig') continue info_block['the_band'] = a_band_key.get() info_block[ 'the_assoc'] = assoc.get_assoc_for_band_key_and_member_key( the_user.key, a_band_key) if the_plan.section is None: if info_block['the_assoc']: info_block['the_section_key'] = info_block[ 'the_assoc'].default_section else: logging.error( 'agenda page: plan exists but no assoc: {0}'.format( the_plan.key.urlsafe())) info_block['the_section_key'] = None else: info_block['the_section_key'] = the_plan.section if num_to_put_in_upcoming and i < num_to_put_in_upcoming and ( the_plan.value or a_gig.status == 2 ): #include gigs for which we've weighed in or have been cancelled upcoming_plans.append(info_block) else: if (the_plan.value == 0): weighin_plans.append(info_block) number_of_bands = len(the_band_keys) return (upcoming_plans, weighin_plans, number_of_bands)
def _make_page(self, the_user): """ construct page for grid view """ # find the bands this member is associated with if not the_user.is_superuser: the_assocs = assoc.get_confirmed_assocs_of_member(the_user) the_band_keys = [a.band for a in the_assocs] else: the_band_keys = band.get_all_bands(keys_only=True) if the_band_keys is None or len(the_band_keys) == 0: return self.redirect('/member_info.html?mk={0}'.format( the_user.key.urlsafe())) # find the band we're interested in band_key_str = self.request.get("bk", None) if band_key_str is None: the_band_key = the_band_keys[0] else: the_band_key = ndb.Key(urlsafe=band_key_str) month_str = self.request.get("m", None) year_str = self.request.get("y", None) if month_str == None or year_str == None: start_date = datetime.datetime.now().replace(day=1) else: delta = 0 delta_str = self.request.get("d", None) if delta_str != None: delta = int(delta_str) year = int(year_str) month = int(month_str) month = month + delta if month > 12: month = 1 year = year + 1 if month < 1: month = 12 year = year - 1 start_date = datetime.datetime(year=year, month=month, day=1) end_date = start_date if (end_date.month < 12): end_date = end_date.replace(month=end_date.month + 1, day=1) else: end_date = end_date.replace(year=end_date.year + 1, month=1, day=1) show_canceled = True if the_user.preferences and the_user.preferences.hide_canceled_gigs: show_canceled = False the_gigs = gig.get_gigs_for_band_key_for_dates( the_band_key, start_date, end_date, get_canceled=show_canceled) all_plans = [] for g in the_gigs: all_plans.append(plan.get_plans_for_gig_key(g.key)) the_member_assocs = band.get_assocs_of_band_key_by_section_key( the_band_key, include_occasional=False) the_plans = {} for section in the_member_assocs: for an_assoc in section[1]: member_key = an_assoc.member member_plans = {} for i in range(0, len(the_gigs)): gig_plans = all_plans[i] for p in gig_plans: if p.member == member_key: member_plans[p.key.parent()] = p.value break the_plans[member_key] = member_plans # the_plans = {} # for section in the_member_assocs: # for an_assoc in section[1]: # member_key=an_assoc.member # member_plans = {} # for a_gig in the_gigs: # the_plan = plan.get_plan_for_member_key_for_gig_key(the_member_key=member_key, the_gig_key=a_gig.key, keys_only=True) # if the_plan is not None: # member_plans[a_gig.key] = the_plan.get().value # the_plans[member_key] = member_plans template_args = { 'all_band_keys': the_band_keys, 'the_band_key': the_band_key, 'the_member_assocs_by_section': the_member_assocs, 'the_month_string': member.format_date_for_member(the_user, start_date, 'month'), 'the_month': start_date.month, 'the_year': start_date.year, 'the_date_formatter': member.format_date_for_member, 'the_gigs': the_gigs, 'the_plans': the_plans, 'grid_is_active': True } self.render_template('grid.html', template_args)
def _make_page(self, the_user): """ construct page for grid view """ # find the bands this member is associated with if not the_user.is_superuser: the_assocs = assoc.get_confirmed_assocs_of_member(the_user) the_band_keys = [a.band for a in the_assocs] else: the_band_keys = band.get_all_bands(keys_only=True) if the_band_keys is None or len(the_band_keys) == 0: return self.redirect('/member_info.html?mk={0}'.format(the_user.key.urlsafe())) # find the band we're interested in band_key_str = self.request.get("bk", None) if band_key_str is None: the_band_key = the_band_keys[0] else: the_band_key = ndb.Key(urlsafe=band_key_str) month_str = self.request.get("m", None) year_str = self.request.get("y", None) if month_str == None or year_str == None: start_date = datetime.datetime.now().replace(day=1) else: delta = 0 delta_str = self.request.get("d", None) if delta_str != None: delta = int(delta_str) year = int(year_str) month = int(month_str) month = month + delta if month > 12: month = 1 year = year + 1 if month < 1: month = 12 year = year - 1 start_date = datetime.datetime(year=year, month=month, day=1) end_date = start_date if (end_date.month < 12): end_date = end_date.replace(month=end_date.month + 1, day=1) else: end_date = end_date.replace(year=end_date.year + 1, month=1, day=1) show_canceled = True # if the_user.preferences and the_user.preferences.hide_canceled_gigs: # show_canceled = False the_gigs = gig.get_all_gig_dates_for_band(the_band_key) gig_date_counts={} for g in the_gigs: ut = '{0}-{1}'.format(g.date.year, g.date.month) if ut in gig_date_counts.keys(): gig_date_counts[ut] += 1 else: gig_date_counts[ut] = 1 template_args = { 'all_band_keys': the_band_keys, 'the_band_key': the_band_key, 'the_month_string': member.format_date_for_member(the_user, start_date, 'month'), 'the_month': start_date.month, 'the_year': start_date.year, 'has_gigs': len(the_gigs) > 0, 'date_counts': gig_date_counts, 'grid_is_active': True } self.render_template('grid_new.html', template_args)
def _get_agenda_contents_for_member(the_user): # find the bands this member is associated with the_assocs = assoc.get_confirmed_assocs_of_member(the_user, include_hidden=False) the_band_keys = [a.band for a in the_assocs] if the_band_keys is None or len(the_band_keys)==0: raise Exception("no agenda") if the_user.show_long_agenda: num_to_put_in_upcoming=1000 else: num_to_put_in_upcoming=5 show_canceled=True if the_user.preferences and the_user.preferences.hide_canceled_gigs: show_canceled=False all_gigs = gig.get_sorted_gigs_from_band_keys(the_band_keys=the_band_keys, include_canceled=show_canceled) upcoming_plans = [] weighin_plans = [] if all_gigs: for i in range(0, len(all_gigs)): a_gig = all_gigs[i] the_plan = plan.get_plan_for_member_for_gig(the_user, a_gig) info_block={} info_block['the_gig'] = a_gig info_block['the_plan'] = the_plan info_block['the_member'] = the_user a_band_key = a_gig.key.parent() a_band = None for test_band_key in the_band_keys: if test_band_key == a_band_key: a_band_key = test_band_key break if a_band_key == None: logging.error('agenda.MainPage error: no band for gig') continue info_block['the_band'] = a_band_key.get() info_block['the_assoc'] = assoc.get_assoc_for_band_key_and_member_key(the_user.key, a_band_key) if the_plan.section is None: if info_block['the_assoc']: info_block['the_section_key'] = info_block['the_assoc'].default_section else: logging.error('agenda page: plan exists but no assoc: {0}'.format(the_plan.key.urlsafe())) info_block['the_section_key'] = None else: info_block['the_section_key'] = the_plan.section if num_to_put_in_upcoming and i<num_to_put_in_upcoming and (the_plan.value or a_gig.status == 2): #include gigs for which we've weighed in or have been cancelled upcoming_plans.append( info_block ) else: if (the_plan.value == 0 ): weighin_plans.append( info_block ) number_of_bands = len(the_band_keys) return (upcoming_plans, weighin_plans, number_of_bands)