def test_gig_trashcan(self): # Create band with member and instantiate a gig the_band, the_member = self._create_test_band_with_member() the_gig = gig.new_gig(the_band, "Parade", the_member.key) # verify that we have one gig for this band all_gigs = gig.get_gigs_for_band_keys([the_band.key]) self.assertEqual(len(all_gigs),1) # put the gig in the trash can the_gig.trashed_date = datetime.datetime.now() self.assertTrue(the_gig.is_in_trash) the_gig.put() # verify that we now have no gigs for this band all_gigs = gig.get_gigs_for_band_keys([the_band.key]) self.assertEmpty(all_gigs) # verify that we have one trashed gig trash_gigs = gig.get_old_trashed_gigs(minimum_age = None) self.assertEqual(len(trash_gigs),1) # take band out of trash the_gig.trashed_date = None self.assertFalse(the_gig.is_in_trash) the_gig.put() # verify that we have one gig for this band all_gigs = gig.get_gigs_for_band_keys([the_band.key]) self.assertEqual(len(all_gigs),1) # verify that we have no trashed gigs trash_gigs = gig.get_old_trashed_gigs(minimum_age = None) self.assertEmpty(trash_gigs)
def test_delete_trash(self): # Create band with member and instantiate a gig the_band, the_member = self._create_test_band_with_member() the_gig = gig.new_gig(the_band, "Parade", the_member.key) # verify that we have one gig for this band all_gigs = gig.get_gigs_for_band_keys([the_band.key]) self.assertEqual(len(all_gigs),1) # sweep for trashed gigs and make sure we didn't lose this one gig_handlers._do_autoarchive() # verify that we have one gig for this band all_gigs = gig.get_gigs_for_band_keys([the_band.key]) self.assertEqual(len(all_gigs),1) # put the gig in the trash can 20 days ago the_gig.trashed_date = datetime.datetime.now() - datetime.timedelta(days=20) self.assertTrue(the_gig.is_in_trash) the_gig.put() # sweep for trashed gigs and make sure we didn't lose this one gig_handlers._do_autoarchive() # verify that we now have no gigs for this band all_gigs = gig.get_gigs_for_band_keys([the_band.key]) self.assertEmpty(all_gigs) # verify that we have one trashed gig trash_gigs = gig.get_old_trashed_gigs(minimum_age = 0) self.assertEqual(len(trash_gigs),1) # verify that we have no month-old trashed gigs trash_gigs = gig.get_old_trashed_gigs(minimum_age = 30) self.assertEmpty(trash_gigs) # put the gig in the trash can 31 days ago the_gig.trashed_date = datetime.datetime.now() - datetime.timedelta(days=31) the_gig.put() # sweep for trashed gigs and make sure we didn't lose this one gig_handlers._do_autoarchive() # verify that we now have no gigs for this band all_gigs = gig.get_gigs_for_band_keys([the_band.key]) self.assertEmpty(all_gigs) # verify that we have no trashed gig trash_gigs = gig.get_old_trashed_gigs(minimum_age = 0) self.assertEmpty(trash_gigs)
def test_selective_delete(self): # Create band with member and instantiate a couple of gigs the_band, the_member = self._create_test_band_with_member() the_gig1 = gig.new_gig(the_band, "Parade1", the_member.key) the_gig2 = gig.new_gig(the_band, "Parade2", the_member.key) # verify that we have two gigs for this band all_gigs = gig.get_gigs_for_band_keys([the_band.key]) self.assertEqual(len(all_gigs),2) # verify that we have no trashed gig trash_gigs = gig.get_old_trashed_gigs(minimum_age = 0) self.assertEmpty(trash_gigs) the_gig1.trashed_date = datetime.datetime.now() - datetime.timedelta(days=20) self.assertTrue(the_gig1.is_in_trash) the_gig1.put() the_gig2.trashed_date = datetime.datetime.now() - datetime.timedelta(days=31) self.assertTrue(the_gig2.is_in_trash) the_gig2.put() # show two gigs in the trash trash_gigs = gig.get_old_trashed_gigs(minimum_age = 0) self.assertEqual(len(trash_gigs),2) # sweep the trash gig_handlers._do_autoarchive() # now should be one in the trash trash_gigs = gig.get_old_trashed_gigs(minimum_age = 0) self.assertEqual(len(trash_gigs),1)
def make_page(self, the_user): the_band_key_url = self.request.get("bk", None) if the_band_key_url is None: raise gigoexceptions.GigoException( 'no band key passed to GigArchivePage handler') else: the_band_key = band.band_key_from_urlsafe(the_band_key_url) # make sure this member is actually in the band if assoc.confirm_user_is_member( the_user.key, the_band_key) is None and the_user.is_superuser is not True: raise gigoexceptions.GigoException( 'user called GigArchivePage handler but is not member') the_band = the_band_key.get() if the_band is None: raise gigoexceptions.GigoException( 'GigArchivePage handler called without a band') the_gigs = gig.get_gigs_for_band_keys(the_band_key, show_past=True) template_args = { 'the_user': the_user, 'the_band': the_band, 'the_gigs': the_gigs, 'the_date_formatter': member.format_date_for_member } self.render_template('band_gig_archive.html', template_args)
def get(self, *args, **kwargs): bk = kwargs['bk'] the_band_key = ndb.Key(urlsafe=bk) the_band = the_band_key.get() calfeed = None if the_band.pub_cal_feed_dirty is False: calfeed = get_calfeed_for_key("p", the_band.key) if calfeed is None: logging.info("band cal feed is dirty") the_band.pub_cal_feed_dirty = False the_band.put() calfeed = u'{0}'.format(make_cal_header(the_band.name)) all_gigs = gig.get_gigs_for_band_keys(the_band_key, show_only_public=True) for a_gig in all_gigs: if a_gig.is_confirmed and not a_gig.hide_from_calendar: calfeed = u'{0}{1}'.format( calfeed, make_event(a_gig, the_band, show_url=False, force_set_time=True)) calfeed = u'{0}{1}'.format(calfeed, make_cal_footer()) store_calfeed_for_key("p", the_band.key, calfeed) self.response.write(calfeed)
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 get(self, *args, **kwargs): bk = kwargs['bk'] the_band_key = band.section_key_from_urlsafe(bk) the_band = the_band_key.get() calfeed = None if the_band.pub_cal_feed_dirty is False: calfeed = get_calfeed_for_key("p",the_band.key) if calfeed is None: logging.info("band cal feed is dirty") the_band.pub_cal_feed_dirty = False the_band.put() calfeed = u'{0}'.format(make_cal_header(the_band.name)) all_gigs = gig.get_gigs_for_band_keys(the_band_key, show_only_public=True) for a_gig in all_gigs: if a_gig.is_confirmed and not a_gig.hide_from_calendar: calfeed = u'{0}{1}'.format(calfeed, make_event(a_gig, the_band, show_url=False, force_set_time=True)) calfeed = u'{0}{1}'.format(calfeed, make_cal_footer()) store_calfeed_for_key("p",the_band.key,calfeed) self.response.write(calfeed)
def make_page(self, the_user): the_band_key_url=self.request.get("bk",None) if the_band_key_url is None: raise gigoexceptions.GigoException('no band key passed to GigArchivePage handler') else: the_band_key = band.band_key_from_urlsafe(the_band_key_url) # make sure this member is actually in the band if assoc.confirm_user_is_member(the_user.key, the_band_key) is None and the_user.is_superuser is not True: raise gigoexceptions.GigoException('user called GigArchivePage handler but is not member') the_band = the_band_key.get() if the_band is None: raise gigoexceptions.GigoException('GigArchivePage handler called without a band') the_gigs = gig.get_gigs_for_band_keys(the_band_key, show_past=True) template_args = { 'the_user' : the_user, 'the_band' : the_band, 'the_gigs' : the_gigs, 'the_date_formatter' : member.format_date_for_member } self.render_template('band_gig_archive.html', template_args)
def get(self, *args, **kwargs): bk = kwargs['bk'] the_band_key = ndb.Key(urlsafe=bk) the_band = the_band_key.get() calfeed = None if the_band.band_cal_feed_dirty is False: calfeed = get_calfeed_for_key("b", the_band.key) if calfeed is None: the_band.band_cal_feed_dirty = False the_band.put() calfeed = u'{0}'.format(make_cal_header(the_band.name)) all_gigs = gig.get_gigs_for_band_keys(the_band_key) for a_gig in all_gigs: if a_gig.is_confirmed and not a_gig.hide_from_calendar: calfeed = u'{0}{1}'.format(calfeed, make_event(a_gig, the_band)) calfeed = u'{0}{1}'.format(calfeed, make_cal_footer()) store_calfeed_for_key("b", the_band.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() 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 make_gig_feed(the_band): the_gigs = gig.get_gigs_for_band_keys(the_band.key, show_canceled=False, show_only_public=True, show_past=False, confirmed_only=True, start_date=datetime.datetime.now()) feed = u"""<?xml version="1.0" encoding="UTF-8" ?> <rss version="2.0"> <channel> """ feed = u"{0}\n<title>{1} Gigs</title>".format(feed, the_band.name) feed = u"{0}\n<link>{1}{2}</link>".format( feed, "http://gig-o-matic.appspot.com/feeds/", the_band.key.urlsafe()) feed = u"{0}\n<description>{1} Gigs</description>".format( feed, the_band.name) for a_gig in the_gigs: feed = u"{0}\n<item>".format(feed) feed = u"{0}\n<title>{1}</title>".format(feed, a_gig.title) feed = u'{0}\n<guid isPermaLink="false">{1}</guid>'.format( feed, a_gig.key.urlsafe()) if a_gig.contact: the_date = member.format_date_for_member(a_gig.contact.get(), a_gig.date, "long") else: the_date = a_gig.date if a_gig.settime: the_time = u' - {0}'.format(a_gig.settime) else: the_time = u'' if a_gig.rss_description: the_desc = a_gig.rss_description else: the_desc = '' feed = u"{0}\n<description><![CDATA[{1}{2}\n\n{3}]]></description>".format( feed, the_date, the_time, the_desc) # feed=u"{0}\n<description>{1}{2}\n\n{3}</description>".format(feed, the_date, the_time, a_gig.rss_description) feed = u"{0}\n</item>".format(feed) feed = u"{0}{1}".format(feed, """ </channel> </rss> """) return feed
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 make_band_stats(the_band_key): """ make a stats object for a band key and return it """ the_stats = get_today_stats(the_band_key) all_member_keys = assoc.get_member_keys_of_band_key(the_band_key) the_stats.number_members = len(all_member_keys) logging.info("band {0} stats: {1} members".format(the_band_key.id(), the_stats.number_members)) all_gigs = gig.get_gigs_for_band_keys(the_band_key, keys_only=True) the_stats.number_upcoming_gigs = len(all_gigs) logging.info("band {0} stats: {1} upcoming gigs".format(the_band_key.id(), the_stats.number_upcoming_gigs)) today_gigs = gig.get_gigs_for_creation_date(the_band_key, the_stats.date) the_stats.number_gigs_created_today = len(today_gigs) the_stats.put()
def get(self, *args, **kwargs): bk = kwargs['bk'] the_band_key = ndb.Key(urlsafe=bk) the_band = the_band_key.get() info = u'{0}'.format(make_cal_header(the_band.name)) all_gigs = gig.get_gigs_for_band_keys(the_band_key) for a_gig in all_gigs: if a_gig.is_confirmed and not a_gig.hide_from_calendar: info = u'{0}{1}'.format(info, make_event(a_gig, the_band)) info = u'{0}{1}'.format(info, make_cal_footer()) self.response.write(info)
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 post(self): the_band_keyurl=self.request.get('bk','0') if the_band_keyurl=='0': return # todo figure out what to do the_band_key = band.band_key_from_urlsafe(the_band_keyurl) today_date = datetime.datetime.now() the_gigs = gig.get_gigs_for_band_keys(the_band_key, start_date=today_date) the_gigs = [g for g in the_gigs if g.is_confirmed and not g.is_private] template_args = { 'the_gigs' : the_gigs, } self.render_template('band_upcoming.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) self.response.headers['Content-Type'] = 'application/x-gzip' self.response.headers[ 'Content-Disposition'] = 'attachment; filename=archive.csv' the_band_key_url = self.request.get("bk", None) if the_band_key_url is None: raise gigoexceptions.GigoException( 'no band key passed to GigArchivePage handler') else: the_band_key = band.band_key_from_urlsafe(the_band_key_url) # make sure this member is actually in the band if assoc.confirm_user_is_member( the_user.key, the_band_key) is None and the_user.is_superuser is not True: raise gigoexceptions.GigoException( 'user called GigArchivePage handler but is not member') the_band = band.get_band(the_band_key) if the_band is None: raise gigoexceptions.GigoException( 'GigArchivePage handler called without a band') the_gigs = gig.get_gigs_for_band_keys(the_band_key, show_past=True) data = "date,name,status,committed,pay" for g in the_gigs: plans = plan.get_plans_for_gig_key(g.key, keys_only=True, plan_values=[1, 2]) # num=len([p for p in plans if p.value in [1,2]]) num = len(plans) stat = 0 if (g.status and g.status in [0, 1, 2]): stat = g.status data = u"{0}\n{1},\"{2}\",{3},{4},\"{5}\"".format( data, member.format_date_for_member(the_user, g.date, 'short'), g.title, gig.Gig.status_names[stat], num, g.paid) self.response.write(data)
def post(self): the_band_keyurl = self.request.get('bk', '0') if the_band_keyurl == '0': return # todo figure out what to do the_band_key = band.band_key_from_urlsafe(the_band_keyurl) today_date = datetime.datetime.now() the_gigs = gig.get_gigs_for_band_keys(the_band_key, start_date=today_date) the_gigs = [g for g in the_gigs if g.is_confirmed and not g.is_private] template_args = { 'the_gigs': the_gigs, } self.render_template('band_upcoming.html', template_args)
def make_band_stats(the_band_key): """ make a stats object for a band key and return it """ the_stats = get_today_stats(the_band_key) all_member_keys = assoc.get_member_keys_of_band_key(the_band_key) the_stats.number_members = len(all_member_keys) logging.info("band {0} stats: {1} members".format( the_band_key.id(), the_stats.number_members)) all_gigs = gig.get_gigs_for_band_keys(the_band_key, keys_only=True) the_stats.number_upcoming_gigs = len(all_gigs) logging.info("band {0} stats: {1} upcoming gigs".format( the_band_key.id(), the_stats.number_upcoming_gigs)) today_gigs = gig.get_gigs_for_creation_date(the_band_key, the_stats.date) the_stats.number_gigs_created_today = len(today_gigs) the_stats.put()
def make_gig_feed(the_band): the_gigs = gig.get_gigs_for_band_keys(the_band.key, show_canceled=False, show_only_public=True, show_past=False, confirmed_only=True, start_date=datetime.datetime.now()) feed = u"""<?xml version="1.0" encoding="UTF-8" ?> <rss version="2.0"> <channel> """ feed=u"{0}\n<title>{1} Gigs</title>".format(feed, the_band.name) feed=u"{0}\n<link>{1}{2}</link>".format(feed, "http://www.gig-o-matic.com/feeds/",the_band.key.urlsafe()) feed=u"{0}\n<description>{1} Gigs</description>".format(feed, the_band.name) for a_gig in the_gigs: feed=u"{0}\n<item>".format(feed) feed=u"{0}\n<title>{1}</title>".format(feed, a_gig.title) feed=u'{0}\n<guid isPermaLink="false">{1}</guid>'.format(feed, a_gig.key.urlsafe()) if a_gig.contact: the_date = member.format_date_for_member(a_gig.contact.get(),a_gig.date,"long") else: the_date = a_gig.date if a_gig.settime: the_time = u' - {0}'.format(a_gig.settime) else: the_time = u'' if a_gig.rss_description: the_desc = a_gig.rss_description else: the_desc = '' feed=u"{0}\n<description><![CDATA[{1}{2}\n\n{3}]]></description>".format(feed, the_date, the_time, the_desc) # feed=u"{0}\n<description>{1}{2}\n\n{3}</description>".format(feed, the_date, the_time, a_gig.rss_description) feed=u"{0}\n</item>".format(feed) feed=u"{0}{1}".format(feed,""" </channel> </rss> """) return feed
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) self.response.headers['Content-Type'] = 'application/x-gzip' self.response.headers['Content-Disposition'] = 'attachment; filename=archive.csv' the_band_key_url=self.request.get("bk",None) if the_band_key_url is None: raise gigoexceptions.GigoException('no band key passed to GigArchivePage handler') else: the_band_key = band.band_key_from_urlsafe(the_band_key_url) # make sure this member is actually in the band if assoc.confirm_user_is_member(the_user.key, the_band_key) is None and the_user.is_superuser is not True: raise gigoexceptions.GigoException('user called GigArchivePage handler but is not member') the_band = band.get_band(the_band_key) if the_band is None: raise gigoexceptions.GigoException('GigArchivePage handler called without a band') the_gigs = gig.get_gigs_for_band_keys(the_band_key, show_past=True) data="date,name,status,committed,pay" for g in the_gigs: plans = plan.get_plans_for_gig_key(g.key, keys_only=True, plan_values=[1,2]) # num=len([p for p in plans if p.value in [1,2]]) num = len(plans) stat=0 if (g.status and g.status in [0,1,2]): stat = g.status data=u"{0}\n{1},\"{2}\",{3},{4},\"{5}\"".format(data, member.format_date_for_member(the_user, g.date, 'short'),g.title,gig.Gig.status_names[stat],num,g.paid) self.response.write(data)
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): 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 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 _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)