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 _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, *args, **kwargs): mk = kwargs['mk'] the_member_key = ndb.Key(urlsafe=mk) the_member = the_member_key.get() calfeed = None if the_member.cal_feed_dirty is False: calfeed = get_calfeed_for_key("m", the_member.key) if calfeed is None: logging.info("member cal feed is dirty") the_member.cal_feed_dirty = False the_member.put() # construct the calendar feed, since it may have changed lately calfeed = u'{0}'.format(make_cal_header(the_member.name)) the_bands = assoc.get_confirmed_bands_of_member(the_member) 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 and not a_gig.hide_from_calendar: # and not a_gig.is_archived: 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): if a_gig.is_confirmed: confstr = u'CONFIRMED!' else: confstr = u'(not confirmed)' calfeed = u'{0}{1}'.format(calfeed, \ make_event(a_gig, a_band, \ title_format=u'{0}:{{0}} {1}'.format(a_band_name, confstr))) calfeed = u'{0}{1}'.format(calfeed, make_cal_footer()) store_calfeed_for_key("m", the_member.key, calfeed) self.response.write(calfeed)
def get(self, *args, **kwargs): mk = kwargs['mk'] the_member_key = member.member_key_from_urlsafe(mk) the_member = the_member_key.get() calfeed = None if the_member.cal_feed_dirty is False: calfeed = get_calfeed_for_key("m",the_member.key) if calfeed is None: logging.info("member cal feed is dirty") the_member.cal_feed_dirty = False the_member.put() # construct the calendar feed, since it may have changed lately calfeed = u'{0}'.format(make_cal_header(the_member.name)) the_bands = assoc.get_confirmed_bands_of_member(the_member) 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 and not a_gig.hide_from_calendar: # and not a_gig.is_archived: 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): if a_gig.is_confirmed: confstr = u'CONFIRMED!' else: confstr = u'(not confirmed)' calfeed = u'{0}{1}'.format(calfeed, \ make_event(a_gig, a_band, \ title_format=u'{0}:{{0}} {1}'.format(a_band_name, confstr))) calfeed = u'{0}{1}'.format(calfeed, make_cal_footer()) store_calfeed_for_key("m",the_member.key,calfeed) self.response.write(calfeed)
def get(self, *args, **kwargs): mk = kwargs['mk'] the_member_key = ndb.Key(urlsafe=mk) the_member = the_member_key.get() limit = datetime.datetime.now() - datetime.timedelta(hours=1) if the_member.last_calfetch is not None and the_member.last_calfetch > limit: # too often - just return 503 self.response.headers.add_header("Retry-After", "3600") self.error(503) return the_member.last_calfetch = datetime.datetime.now() the_member.put() info = u'{0}'.format(make_cal_header(the_member.name)) the_bands = assoc.get_confirmed_bands_of_member(the_member) 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 and not a_gig.hide_from_calendar: # and not a_gig.is_archived: 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): if a_gig.is_confirmed: confstr = u'CONFIRMED!' else: confstr = u'(not confirmed)' info = u'{0}{1}'.format(info, \ make_event(a_gig, a_band, \ title_format=u'{0}:{{0}} {1}'.format(a_band_name, confstr))) info = u'{0}{1}'.format(info, make_cal_footer()) self.response.write(info)
def get(self): answer_str = self.request.get("c", None) if answer_str is None: return # todo figure out what to do if there's no ID passed in code = cryptoutil.decrypt_string(answer_str).strip() parts = code.split('+') member_key = member.member_key_from_urlsafe(parts[0]) gig_key = gig.gig_key_from_urlsafe(parts[1]) the_plan = plan.get_plan_for_member_key_for_gig_key( member_key, gig_key) if the_plan: if parts[2] == '0': plan.update_plan(the_plan, 5) elif parts[2] == '1': plan.update_plan(the_plan, 1) elif parts[2] == '2': plan.update_plan(the_plan, 3) # snooze! the_gig = the_plan.key.parent().get() snooze_days = 7 gig_future = the_gig.date - datetime.datetime.now() if gig_future.days < 8: snooze_days = gig_future.days - 2 if snooze_days > 0: snooze_day = datetime.datetime.now() + datetime.timedelta( days=snooze_days) # logging.info("\n\nsnooze date is {0}\n\n".format(snooze_day)) the_plan.snooze_until = snooze_day the_plan.put() # TODO if the gig is too soon, silently ignore request fo snooze - should give a message else: logging.error( "answerlink got unknown type.\ngig key:{0}\nmember_key:{1}" .format(parts[1], parts[0])) self.render_template('confirm_answer.html', []) else: logging.error( "answer link failed.\ngig key:{0}\nmember_key:{1}".format( parts[1], parts[0])) self.render_template('error.html', [])
def get(self): answer_str = self.request.get("c", None) if answer_str is None: return # todo figure out what to do if there's no ID passed in code = cryptoutil.decrypt_string(answer_str).strip() parts=code.split('+') member_key = member.member_key_from_urlsafe(parts[0]) gig_key = gig.gig_key_from_urlsafe(parts[1]) the_plan = plan.get_plan_for_member_key_for_gig_key(member_key, gig_key) if the_plan: if parts[2] == '0': plan.update_plan(the_plan,5) elif parts[2] == '1': plan.update_plan(the_plan,1) elif parts[2] == '2': plan.update_plan(the_plan,3) # snooze! the_gig = the_plan.key.parent().get() snooze_days = 7 gig_future = the_gig.date - datetime.datetime.now() if gig_future.days < 8: snooze_days = gig_future.days - 2 if snooze_days > 0: snooze_day = datetime.datetime.now() + datetime.timedelta(days = snooze_days) # logging.info("\n\nsnooze date is {0}\n\n".format(snooze_day)) the_plan.snooze_until = snooze_day the_plan.put() # TODO if the gig is too soon, silently ignore request fo snooze - should give a message else: logging.error("answerlink got unknown type.\ngig key:{0}\nmember_key:{1}".format(parts[1], parts[0])) self.render_template('confirm_answer.html', []) else: logging.error("answer link failed.\ngig key:{0}\nmember_key:{1}".format(parts[1], parts[0])) self.render_template('error.html', [])
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 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 make_archive_for_gig_key(the_gig_key): """ makes an archive for a gig - files away all the plans, then delete them """ the_gig = the_gig_key.get() the_archive_text = "" if the_gig.status == 2: # this gig was cancelled the_archive_text = "The gig was cancelled." else: the_band = the_gig_key.parent().get() the_assocs = assoc.get_confirmed_assocs_of_band_key(the_band.key) the_sections = list(the_band.sections) the_sections.append(None) the_plans = [] for the_section in the_sections: section_plans = [] for an_assoc in the_assocs: the_plan = plan.get_plan_for_member_key_for_gig_key( an_assoc.member, the_gig_key) # add the plan to the list, but only if the member's section for this gig is this section if the_plan: test_section = the_plan.section if test_section is None: test_section = an_assoc.default_section if test_section == the_section: section_plans.append([an_assoc.member, the_plan]) # when we file this away, update the member's gig-commitment stats if the_plan.value in [1, 5, 6]: an_assoc.commitment_number = an_assoc.commitment_number + 1 # whether or not there's a plan, up the number of gigs we should have committed to an_assoc.commitment_total = an_assoc.commitment_total + 1 the_plans.append((the_section, section_plans)) ndb.put_multi(the_assocs) for a_section in the_plans: if a_section[1]: the_section_key = a_section[0] if (the_section_key): the_section_name = the_section_key.get().name else: if len(the_plans) == 1: the_section_name = '' else: the_section_name = 'No Section' the_archive_text = u'{0}\n{1}'.format(the_archive_text, the_section_name) for member_plans in a_section[1]: the_member = member_plans[0].get() the_plan = member_plans[1] the_comment = u'- {0}'.format( the_plan.comment) if the_plan.comment else "" the_nickname = u' ({0})'.format( the_member.nickname) if the_member.nickname else '' the_archive_text = u'{0}\n\t{1}{2} - {3} {4}'.format( the_archive_text, the_member.name, the_nickname, plan.plan_text[the_plan.value], the_comment) the_archive_text = u'{0}\n'.format(the_archive_text) # create a document my_document = search.Document(fields=[ search.TextField(name='plans', value=the_archive_text), search.TextField(name='type', value='archive') ]) try: index = search.Index(name="gigomatic_index") result = index.put(my_document) except search.Error: logging.exception('Put failed') archive_id = result[0].id if archive_id: the_gig = the_gig_key.get() if the_gig.archive_id: delete_archive(the_gig.archive_id) the_gig.archive_id = archive_id the_gig.put() else: logging.error('made archive but did not get document id')
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)