def announce_new_gig(the_gig, the_gig_url, is_edit=False, change_string=""): the_band_key = the_gig.key.parent() the_band=the_band_key.get() the_assocs = assoc.get_confirmed_assocs_of_band_key(the_band_key, include_occasional=the_gig.invite_occasionals) for an_assoc in the_assocs: if an_assoc.email_me: the_member = an_assoc.member.get() send_newgig_email(the_member, the_gig, the_band, the_gig_url, is_edit, change_string)
def make_band_cal_dirty(the_band): the_band.band_cal_feed_dirty = True the_band.pub_cal_feed_dirty = True the_assocs = assoc.get_confirmed_assocs_of_band_key(the_band.key, include_occasional=True) the_member_keys = [a.member for a in the_assocs] the_members = ndb.get_multi(the_member_keys) for m in the_members: m.cal_feed_dirty = True ndb.put_multi(the_members+[the_band])
def make_band_cal_dirty(the_band): the_band.band_cal_feed_dirty = True the_band.pub_cal_feed_dirty = True the_assocs = assoc.get_confirmed_assocs_of_band_key( the_band.key, include_occasional=True) the_member_keys = [a.member for a in the_assocs] the_members = ndb.get_multi(the_member_keys) for m in the_members: m.cal_feed_dirty = True ndb.put_multi(the_members + [the_band])
def post(self): _check_taskqueue_trust(self.request) the_params = pickle.loads(self.request.get('the_params')) the_gig_key = the_params['the_gig_key'] the_gig_url = the_params['the_gig_url'] is_edit = the_params['is_edit'] is_reminder = the_params['is_reminder'] change_string = the_params['change_string'] the_members = the_params['the_members'] the_gig = the_gig_key.get() the_band_key = the_gig_key.parent() the_assocs = assoc.get_confirmed_assocs_of_band_key( the_band_key, include_occasional=the_gig.invite_occasionals) if is_reminder and the_members: recipient_assocs = [] for a in the_assocs: if a.member in the_members: recipient_assocs.append(a) else: recipient_assocs = the_assocs logging.info('announcing gig {0} to {1} people'.format( the_gig_key, len(recipient_assocs))) the_shared_params = pickle.dumps({ 'the_gig_key': the_gig_key, 'the_band_key': the_band_key, 'the_gig_url': the_gig_url, 'is_edit': is_edit, 'is_reminder': is_reminder, 'change_string': change_string }) for an_assoc in recipient_assocs: if an_assoc.email_me: the_member_key = an_assoc.member the_member_params = pickle.dumps( {'the_member_key': the_member_key}) _safe_taskqueue_add(url='/send_new_gig_handler', params={ 'the_shared_params': the_shared_params, 'the_member_params': the_member_params }) logging.info('announced gig {0}'.format(the_gig_key)) stats.update_band_email_stats(the_band_key, len(recipient_assocs)) self.response.write(200)
def post(self): the_params = pickle.loads(self.request.get('the_params')) the_gig_key = the_params['the_gig_key'] the_gig_url = the_params['the_gig_url'] is_edit = the_params['is_edit'] is_reminder = the_params['is_reminder'] change_string = the_params['change_string'] the_members = the_params['the_members'] the_gig = the_gig_key.get() the_band_key = the_gig_key.parent() the_assocs = assoc.get_confirmed_assocs_of_band_key(the_band_key, include_occasional=the_gig.invite_occasionals) if is_reminder and the_members: recipient_assocs=[] for a in the_assocs: if a.member in the_members: recipient_assocs.append(a) else: recipient_assocs = the_assocs logging.info('announcing gig {0} to {1} people'.format(the_gig_key,len(recipient_assocs))) the_shared_params = pickle.dumps({ 'the_gig_key': the_gig_key, 'the_band_key': the_band_key, 'the_gig_url': the_gig_url, 'is_edit': is_edit, 'is_reminder': is_reminder, 'change_string': change_string }) for an_assoc in recipient_assocs: if an_assoc.email_me: the_member_key = an_assoc.member the_member_params = pickle.dumps({ 'the_member_key': the_member_key }) task = taskqueue.add( queue_name='emailqueue', url='/send_new_gig_handler', params={'the_shared_params': the_shared_params, 'the_member_params': the_member_params }) logging.info('announced gig {0}'.format(the_gig_key)) stats.update_band_email_stats(the_band_key, len(recipient_assocs)) self.response.write( 200 )
def set_section_indices(the_band): """ for every assoc in the band, set the default_section_index according to the section list in the band """ map = {} for i,s in enumerate(the_band.sections): map[s] = i map[None] = None the_assocs = assoc.get_confirmed_assocs_of_band_key(the_band.key, include_occasional=True) for a in the_assocs: a.default_section_index = map[a.default_section] ndb.put_multi(the_assocs)
def set_section_indices(the_band): """ for every assoc in the band, set the default_section_index according to the section list in the band """ map = {} for i, s in enumerate(the_band.sections): map[s] = i map[None] = None the_assocs = assoc.get_confirmed_assocs_of_band_key( the_band.key, include_occasional=True) for a in the_assocs: a.default_section_index = map[a.default_section] ndb.put_multi(the_assocs)
def get(self, *args, **kwargs): try: band_id = kwargs["band_id"] the_band_key = band.band_key_from_urlsafe(band_id) except webapp2.HTTPException: raise except: self.abort(404) # are we authorized to see the band? the_assoc = assoc.get_assoc_for_band_key_and_member_key(self.user.key, the_band_key, confirmed_only=False) if the_assoc is None: self.abort(401) the_assocs = assoc.get_confirmed_assocs_of_band_key(the_band_key, include_occasional=True) member_keys = [a.member for a in the_assocs] members = member.get_member(member_keys) info = [member.rest_member_info(m, True) for m in members] return info
def get_assocs_of_band_key_by_section_key(the_band_key, include_occasional=True): the_band = get_band(the_band_key) the_info=[] the_map={} count=0 for s in the_band.sections: the_info.append([s,[]]) the_map[s]=count count=count+1 the_info.append([None,[]]) # for 'None' the_map[None]=count the_assocs = assoc.get_confirmed_assocs_of_band_key(the_band_key, include_occasional=include_occasional) for an_assoc in the_assocs: the_info[the_map[an_assoc.default_section]][1].append(an_assoc) if the_info[the_map[None]][1] == []: the_info.pop(the_map[None]) return the_info
def get(self, *args, **kwargs): try: band_id = kwargs["band_id"] the_band_key = band.band_key_from_urlsafe(band_id) except webapp2.HTTPException: raise except: self.abort(404) # are we authorized to see the band? the_assoc = assoc.get_assoc_for_band_key_and_member_key( self.user.key, the_band_key, confirmed_only=False) if the_assoc is None: self.abort(401) the_assocs = assoc.get_confirmed_assocs_of_band_key( the_band_key, include_occasional=True) member_keys = [a.member for a in the_assocs] members = member.get_member(member_keys) info = [member.rest_member_info(m, True) for m in members] return info
def get_assocs_of_band_key_by_section_key(the_band_key, include_occasional=True): the_band = get_band(the_band_key) the_info = [] the_map = {} count = 0 for s in the_band.sections: the_info.append([s, []]) the_map[s] = count count = count + 1 the_info.append([None, []]) # for 'None' the_map[None] = count the_assocs = assoc.get_confirmed_assocs_of_band_key( the_band_key, include_occasional=include_occasional) for an_assoc in the_assocs: the_info[the_map[an_assoc.default_section]][1].append(an_assoc) if the_info[the_map[None]][1] == []: the_info.pop(the_map[None]) return the_info
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')