def post(self): """ post handler - wants an ak and sk """ the_user = self.user the_section_keyurl = self.request.get('sk', '0') the_member_keyurl = self.request.get('mk', '0') the_band_keyurl = self.request.get('bk', '0') if the_section_keyurl == '0' or the_member_keyurl == '0' or the_band_keyurl == '0': raise Exception("Section, member and band must all be specified.") the_section_key = band.section_key_from_urlsafe(the_section_keyurl) the_member_key = member.member_key_from_urlsafe(the_member_keyurl) the_band_key = band.band_key_from_urlsafe(the_band_keyurl) oktochange = False if (the_user.key == the_member_key or the_user.is_superuser): oktochange = True else: the_assoc = assoc.get_assoc_for_band_key_and_member_key( the_user.key, the_band_key) if the_assoc is not None and the_assoc.is_band_admin: oktochange = True if (oktochange): assoc.set_default_section(the_member_key, the_band_key, the_section_key)
def get(self): """ post handler - wants a mk """ the_member_keyurl=self.request.get('mk','0') the_do=self.request.get('do','') if the_member_keyurl=='0': return # todo figure out what to do if the_do=='': return # todo figure out what to do the_member_key = member.member_key_from_urlsafe(the_member_keyurl) the_member=the_member_key.get() # todo - make sure the user is a superuser if (the_do=='0'): the_member.is_betatester=False elif (the_do=='1'): the_member.is_betatester=True else: return # todo figure out what to do the_member.put() return self.redirect('/member_admin')
def post(self): """ post handler - wants an ak and sk """ the_user = self.user the_section_keyurl=self.request.get('sk','0') the_member_keyurl=self.request.get('mk','0') the_band_keyurl=self.request.get('bk','0') if the_section_keyurl=='0' or the_member_keyurl=='0' or the_band_keyurl=='0': raise Exception("Section, member and band must all be specified.") the_section_key = band.section_key_from_urlsafe(the_section_keyurl) the_member_key = member.member_key_from_urlsafe(the_member_keyurl) the_band_key = band.band_key_from_urlsafe(the_band_keyurl) oktochange=False if (the_user.key == the_member_key or the_user.is_superuser): oktochange=True else: the_assoc = assoc.get_assoc_for_band_key_and_member_key(the_user.key, the_band_key) if the_assoc is not None and the_assoc.is_band_admin: oktochange=True if (oktochange): assoc.set_default_section(the_member_key, the_band_key, the_section_key)
def get(self): """ post handler - wants a mk """ the_member_keyurl = self.request.get('mk', '0') the_do = self.request.get('do', '') if the_member_keyurl == '0': return # todo figure out what to do if the_do == '': return # todo figure out what to do the_member_key = member.member_key_from_urlsafe(the_member_keyurl) the_member = the_member_key.get() # todo - make sure the user is a superuser if (the_do == '0'): the_member.is_betatester = False elif (the_do == '1'): the_member.is_betatester = True else: return # todo figure out what to do the_member.put() return self.redirect('/member_admin')
def get(self): """ handles the 'confirm member' button in the band info page """ the_user = self.user the_member_keyurl=self.request.get('mk','0') the_band_keyurl=self.request.get('bk','0') if the_member_keyurl == '0' or the_band_keyurl == '0': return # todo what to do? the_member_key = member.member_key_from_urlsafe(the_member_keyurl) the_band_key = band.band_key_from_urlsafe(the_band_keyurl) if not is_authorized_to_edit_band(the_band_key,the_user): return the_member = member.get_member(the_member_key) assoc.confirm_member_for_band_key(the_member, the_band_key) # if the user happens to be logged in, invalidate his cached list of bands and # bands for which he can edit gigs the_member.invalidate_member_bandlists(self, the_member_key) the_band = band.get_band(the_band_key) goemail.send_band_accepted_email(the_member.email_address, the_band) return self.redirect('/band_info.html?bk={0}'.format(the_band_keyurl))
def get(self): """ handler - wants a mk """ if not self.user.is_superuser: raise MemberError( "Cannot verify user because {0} is not a superuser".format( self.user.name)) the_member_keyurl = self.request.get('mk', '0') if the_member_keyurl == '0': raise MemberError( "Cannot verify user because no member key passed in, user={0}". format(self.user.name)) the_member_key = member.member_key_from_urlsafe(the_member_keyurl) the_member = the_member_key.get() if the_member is None: raise MemberError( "Cannot verify user because no member found, user={0}".format( self.user.name)) the_member.verified = True the_member.put() return self.redirect( '/member_info.html?mk={0}'.format(the_member_keyurl))
def get(self): """ handles the 'confirm member' button in the band info page """ the_user = self.user the_member_keyurl = self.request.get('mk', '0') the_band_keyurl = self.request.get('bk', '0') if the_member_keyurl == '0' or the_band_keyurl == '0': return # todo what to do? the_member_key = member.member_key_from_urlsafe(the_member_keyurl) the_band_key = band.band_key_from_urlsafe(the_band_keyurl) if not is_authorized_to_edit_band(the_band_key, the_user): return the_member = member.get_member(the_member_key) assoc.confirm_member_for_band_key(the_member, the_band_key) # if the user happens to be logged in, invalidate his cached list of bands and # bands for which he can edit gigs the_member.invalidate_member_bandlists(self, the_member_key) the_band = band.get_band(the_band_key) goemail.send_band_accepted_email(the_member.email_address, the_band) return self.redirect('/band_info.html?bk={0}'.format(the_band_keyurl))
def get(self, *args, **kwargs): try: member_id = kwargs["member_id"] the_member = member.member_key_from_urlsafe(member_id).get() except: self.abort(404) # are we authorized to see the member? TODO return member.rest_member_info(the_member, include_id=False)
def post(self): """ post handler - wants a mk """ the_member_keyurl = self.request.get('mk', '0') if the_member_keyurl == '0': return # todo figure out what to do the_member_key = member.member_key_from_urlsafe(the_member_keyurl) the_bands = self.user.get_band_list(self, the_member_key) template_args = {'the_bands': the_bands} self.render_template('navbar_bandlist.html', template_args)
def post(self): member_key_urlsafe = self.request.get('mk', None) if member_key_urlsafe: the_member = member.member_key_from_urlsafe( member_key_urlsafe).get() else: raise ValueError('illegal member key to MemberTestEmail') _safe_taskqueue_add(url='/member_test_email_handler', params={'the_address': the_member.email_address}) self.response.write(200)
def post(self): """ post handler for welcome page """ the_member_keystr=self.request.get("mk",'0') if the_member_keystr=='0': return # todo what to do if it's not passed in? the_member_key = member.member_key_from_urlsafe(the_member_keystr) if the_member_key: member.set_seen_welcome_for_member_key(the_member_key) else: return # todo what to do?
def post(self): """ post handler - wants a mk """ the_member_keyurl=self.request.get('mk','0') if the_member_keyurl=='0': return # todo figure out what to do the_member_key = member.member_key_from_urlsafe(the_member_keyurl) the_manage_bands = self.user.get_add_gig_band_list(self, the_member_key) template_args = { 'the_bands' : the_manage_bands } self.render_template('navbar_addgigbandlist.html', template_args)
def post(self): """ post handler for welcome page """ the_member_keystr = self.request.get("mk", '0') if the_member_keystr == '0': return # todo what to do if it's not passed in? the_member_key = member.member_key_from_urlsafe(the_member_keystr) if the_member_key: member.set_seen_welcome_for_member_key(the_member_key) else: return # todo what to do?
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.headers['Access-Control-Allow-Origin'] = '*' 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): 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 post(self): """ post handler - wants an ak and sk """ the_member_keyurl=self.request.get('mk','0') the_band_keyurl=self.request.get('bk','0') the_do=self.request.get('do','') if the_band_keyurl=='0' or the_member_keyurl=='0': raise Exception("Band or member not specified") if the_do=='': return the_band_key = band.band_key_from_urlsafe(the_band_keyurl) the_member_key = member.member_key_from_urlsafe(the_member_keyurl) assoc.set_multi(the_member_key, the_band_key, (the_do=='true'))
def post(self): """ post handler - wants an ak and sk """ the_member_keyurl = self.request.get('mk', '0') the_band_keyurl = self.request.get('bk', '0') the_do = self.request.get('do', '') if the_band_keyurl == '0' or the_member_keyurl == '0': raise Exception("Band or member not specified") if the_do == '': return the_band_key = band.band_key_from_urlsafe(the_band_keyurl) the_member_key = member.member_key_from_urlsafe(the_member_keyurl) assoc.set_multi(the_member_key, the_band_key, (the_do == 'true'))
def get(self): """ handler - wants a mk """ if not self.user.is_superuser: raise MemberError("Cannot verify user because {0} is not a superuser".format(self.user.name)) the_member_keyurl=self.request.get('mk','0') if the_member_keyurl=='0': raise MemberError("Cannot verify user because no member key passed in, user={0}".format(self.user.name)) the_member_key = member.member_key_from_urlsafe(the_member_keyurl) the_member = the_member_key.get() if the_member is None: raise MemberError("Cannot verify user because no member found, user={0}".format(self.user.name)) the_member.verified = True the_member.put() return self.redirect('/member_info.html?mk={0}'.format(the_member_keyurl))
def get(self): """ post handler - wants a mk """ the_member_keyurl=self.request.get('mk','0') if the_member_keyurl=='0': return # todo figure out what to do the_member_key = member.member_key_from_urlsafe(the_member_keyurl) # The only way to get here is to manually paste your key into the url; # someone doing that is a troublemaker. if not self.user.is_superuser: raise MemberError("Cannot delete user because {0} is not a superuser".format(self.user.name)) if (self.user.key != the_member_key): member.forget_member_from_key(the_member_key) else: print 'cannot delete yourself, people' return self.redirect('/member_admin')
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): """ post handler - wants an ak """ the_user = self.user the_member_keyurl=self.request.get('mk','0') the_band_keyurl=self.request.get('bk','0') if the_member_keyurl=='0' or the_band_keyurl=='0': return # todo figure out what to do the_member_key = member.member_key_from_urlsafe(the_member_keyurl) the_band_key = band.band_key_from_urlsafe(the_band_keyurl) if not is_authorized_to_edit_band(the_band_key,the_user): return # find the association between band and member the_assoc=assoc.get_assoc_for_band_key_and_member_key(the_member_key, the_band_key) assoc.delete_association_from_key(the_assoc.key) gig.reset_gigs_for_contact_key(the_member_key, the_band_key) return self.redirect('/band_info.html?bk={0}'.format(the_band_keyurl))
def get(self): """ post handler - wants a mk """ the_member_keyurl = self.request.get('mk', '0') if the_member_keyurl == '0': return # todo figure out what to do the_member_key = member.member_key_from_urlsafe(the_member_keyurl) # The only way to get here is to manually paste your key into the url; # someone doing that is a troublemaker. if not self.user.is_superuser: raise MemberError( "Cannot delete user because {0} is not a superuser".format( self.user.name)) if (self.user.key != the_member_key): member.forget_member_from_key(the_member_key) else: print 'cannot delete yourself, people' return self.redirect('/member_admin')
def get(self): """ post handler - wants an ak """ the_user = self.user the_member_keyurl = self.request.get('mk', '0') the_band_keyurl = self.request.get('bk', '0') if the_member_keyurl == '0' or the_band_keyurl == '0': return # todo figure out what to do the_member_key = member.member_key_from_urlsafe(the_member_keyurl) the_band_key = band.band_key_from_urlsafe(the_band_keyurl) if not is_authorized_to_edit_band(the_band_key, the_user): return # find the association between band and member the_assoc = assoc.get_assoc_for_band_key_and_member_key( the_member_key, the_band_key) assoc.delete_association_from_key(the_assoc.key) gig.reset_gigs_for_contact_key(the_member_key, the_band_key) return self.redirect('/band_info.html?bk={0}'.format(the_band_keyurl))
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 = member.member_key_from_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] 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) options = { '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()), 'color': colors[cindex], } if cindex == 0: options['textColor'] = '#000000' options['borderColor'] = '#aaaaaa' events.append(options) 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 = member.member_key_from_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] 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) options= { '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()), 'color':colors[cindex], } if cindex == 0: options['textColor'] = '#000000' options['borderColor'] = '#aaaaaa' events.append(options) testevent=json.dumps(events) self.response.write( testevent )
def post(self): """post handler - if we are edited by the template, handle it here and redirect back to info page""" the_gig_key = self.request.get("gk", '0') if (the_gig_key == '0'): the_gig = None else: the_gig = gig.gig_key_from_urlsafe(the_gig_key).get() edit_date_change = False edit_time_change = False edit_status_change = False edit_detail_change = False # first, get the band gig_is_new = False gig_band_keyurl = self.request.get("gig_band", None) if gig_band_keyurl is not None and gig_band_keyurl != '': the_band = band.band_key_from_urlsafe(gig_band_keyurl).get() if the_gig is None: the_gig = gig.new_gig(title="tmp", the_band=the_band, creator=self.user.key) gig_is_new = True # are we authorized to edit a gig for this band? ok_band_list = self.user.get_add_gig_band_list(self, self.user.key) if not the_band.key in [x.key for x in ok_band_list]: logging.error(u'user {0} trying to edit a gig for band {1}'.format( self.user.key.urlsafe(), the_band.key.urlsafe())) return self.redirect('/') # now get the info gig_title = self.request.get("gig_title", None) if gig_title is not None and gig_title != '': the_gig.title = gig_title gig_contact = self.request.get("gig_contact", None) if gig_contact is not None and gig_contact != '': the_gig.contact = member.member_key_from_urlsafe(gig_contact) gig_details = self.request.get("gig_details", None) if gig_details is not None: the_gig.details = gig_details gig_setlist = self.request.get("gig_setlist", None) if gig_setlist is not None: the_gig.setlist = gig_setlist gig_rssdescription = self.request.get("gig_rssdescription", None) if gig_rssdescription is not None: the_gig.rss_description = gig_rssdescription gig_date = self.request.get("gig_date", None) if gig_date is not None and gig_date != '': old_date = the_gig.date the_gig.date = datetime.datetime.combine( babel.dates.parse_date(gig_date, locale=self.user.preferences.locale), datetime.time(0, 0, 0)) if old_date != the_gig.date: edit_date_change = True # todo validate form entry so date isn't bogus gig_enddate = self.request.get("gig_enddate", None) old_enddate = the_gig.enddate if gig_enddate is not None and gig_enddate != '': the_gig.enddate = datetime.datetime.combine( babel.dates.parse_date(gig_enddate, locale=self.user.preferences.locale), datetime.time(0, 0, 0)) else: the_gig.enddate = None if old_enddate != the_gig.enddate: edit_date_change = True gig_call = self.request.get("gig_call", '') if gig_call is not None: if the_gig.calltime != gig_call: the_gig.set_calltime(gig_call) edit_time_change = True gig_set = self.request.get("gig_set", '') if gig_set is not None: if the_gig.settime != gig_set: the_gig.set_settime(gig_set) edit_time_change = True gig_end = self.request.get("gig_end", '') if gig_end is not None: if the_gig.endtime != gig_end: the_gig.set_endtime(gig_end) edit_time_change = True gig_address = self.request.get("gig_address", '') if gig_address is not None: the_gig.address = gig_address gig_dress = self.request.get("gig_dress", '') if gig_dress is not None: the_gig.dress = gig_dress gig_paid = self.request.get("gig_paid", '') if gig_paid is not None: the_gig.paid = gig_paid gig_leader = self.request.get("gig_leader", '') if gig_leader is not None: the_gig.leader = gig_leader gig_postgig = self.request.get("gig_postgig", '') if gig_postgig is not None: the_gig.postgig = gig_postgig gig_status = self.request.get("gig_status", '0') old_status = the_gig.status the_gig.status = int(gig_status) if old_status != the_gig.status: edit_status_change = True gig_invite_occasionals = self.request.get("gig_invite_occasionals", None) if (gig_invite_occasionals): the_gig.invite_occasionals = True else: the_gig.invite_occasionals = False gig_hide_from_calendar = self.request.get("gig_hide_from_calendar", None) if (gig_hide_from_calendar): the_gig.hide_from_calendar = True else: the_gig.hide_from_calendar = False gig_private = self.request.get("gig_private", None) if (gig_private): the_gig.is_private = True else: the_gig.is_private = False gig_default_to_attending = self.request.get("default_to_attend", None) if (gig_default_to_attending): logging.info("\n\nattending!\n\n") the_gig.default_to_attending = True the_gig.put() # Is this a series? is_series = self.request.get("newgig_isseries", False) if is_series: number_to_copy = int(self.request.get("newgig_seriescount", 1)) - 1 period = self.request.get("newgig_seriesperiod", None) last_date = the_gig.date if period == 'day': delta = datetime.timedelta(days=1) elif period == 'week': delta = datetime.timedelta(weeks=1) else: day_of_month = last_date.day if the_gig.enddate: end_delta = the_gig.enddate - the_gig.date else: end_delta = None newgigs = [] for i in range(0, number_to_copy): copy_gig = clone.clone_entity(the_gig, gig.Gig) if period == 'day' or period == 'week': last_date = last_date + delta else: # figure out what the next month is if last_date.month < 12: mo = last_date.month + 1 yr = last_date.year else: mo = 1 yr = last_date.year + 1 # figure out last day of next month nextmonth = last_date.replace(month=mo, day=1, year=yr) nextnextmonth = (nextmonth + datetime.timedelta(days=35)).replace( day=1) lastday = (nextnextmonth - datetime.timedelta(days=1)).day if lastday < day_of_month: day_of_gig = lastday else: day_of_gig = day_of_month last_date = last_date.replace(month=mo, day=day_of_gig, year=yr) copy_gig.date = last_date if end_delta is not None: copy_gig.enddate = copy_gig.date + end_delta newgigs.append(copy_gig) if newgigs: ndb.put_multi(newgigs) gig_notify = self.request.get("gig_notifymembers", None) if gig_notify is not None: if gig_is_new: goemail.announce_new_gig(the_gig, self.uri_for( 'gig_info', _full=True, gk=the_gig.key.urlsafe()), is_edit=False) else: if edit_time_change or edit_date_change or edit_status_change: change_strings = [] if edit_time_change: change_strings.append(_('Time')) if edit_date_change: change_strings.append(_('Date')) if edit_status_change: change_strings.append(_('Status')) change_str = ', '.join(change_strings) else: change_str = _('Details') goemail.announce_new_gig(the_gig, self.uri_for( 'gig_info', _full=True, gk=the_gig.key.urlsafe()), is_edit=True, change_string=change_str) if (the_band.rss_feed): rss.make_rss_feed_for_band(the_band) band.make_band_cal_dirty(the_band) return self.redirect(\ '/gig_info.html?&gk={0}'.format(the_gig.key.urlsafe()))
def post(self): """post handler - if we are edited by the template, handle it here and redirect back to info page""" the_gig_key = self.request.get("gk", '0') if (the_gig_key == '0'): the_gig = None else: the_gig = gig.gig_key_from_urlsafe(the_gig_key).get() edit_date_change = False edit_time_change = False edit_status_change = False edit_detail_change = False # first, get the band gig_is_new = False gig_band_keyurl = self.request.get("gig_band", None) if gig_band_keyurl is not None and gig_band_keyurl != '': the_band = band.band_key_from_urlsafe(gig_band_keyurl).get() if the_gig is None: the_gig = gig.new_gig(title="tmp", the_band=the_band, creator=self.user.key) gig_is_new = True # are we authorized to edit a gig for this band? ok_band_list = self.user.get_add_gig_band_list(self, self.user.key) if not the_band.key in [x.key for x in ok_band_list]: logging.error(u'user {0} trying to edit a gig for band {1}'.format(self.user.key.urlsafe(),the_band.key.urlsafe())) return self.redirect('/') # now get the info gig_title = self.request.get("gig_title", None) if gig_title is not None and gig_title != '': the_gig.title = gig_title gig_contact = self.request.get("gig_contact", None) if gig_contact is not None and gig_contact != '': the_gig.contact = member.member_key_from_urlsafe(gig_contact) gig_details = self.request.get("gig_details", None) if gig_details is not None: the_gig.details = gig_details gig_setlist = self.request.get("gig_setlist", None) if gig_setlist is not None: the_gig.setlist = gig_setlist gig_rssdescription = self.request.get("gig_rssdescription", None) if gig_rssdescription is not None: the_gig.rss_description = gig_rssdescription gig_date = self.request.get("gig_date", None) if gig_date is not None and gig_date != '': old_date = the_gig.date the_gig.date = datetime.datetime.combine(babel.dates.parse_date(gig_date,locale=self.user.preferences.locale),datetime.time(0,0,0)) if old_date != the_gig.date: edit_date_change = True # todo validate form entry so date isn't bogus gig_enddate = self.request.get("gig_enddate", None) old_enddate = the_gig.enddate if gig_enddate is not None and gig_enddate != '': the_gig.enddate = datetime.datetime.combine(babel.dates.parse_date(gig_enddate,locale=self.user.preferences.locale),datetime.time(0,0,0)) else: the_gig.enddate = None if old_enddate != the_gig.enddate: edit_date_change = True gig_call = self.request.get("gig_call", '') if gig_call is not None: if the_gig.calltime != gig_call: the_gig.set_calltime(gig_call) edit_time_change = True gig_set = self.request.get("gig_set", '') if gig_set is not None: if the_gig.settime != gig_set: the_gig.set_settime(gig_set) edit_time_change = True gig_end = self.request.get("gig_end", '') if gig_end is not None: if the_gig.endtime != gig_end: the_gig.set_endtime(gig_end) edit_time_change = True gig_address = self.request.get("gig_address", '') if gig_address is not None: the_gig.address = gig_address gig_dress = self.request.get("gig_dress", '') if gig_dress is not None: the_gig.dress = gig_dress gig_paid = self.request.get("gig_paid", '') if gig_paid is not None: the_gig.paid = gig_paid gig_leader = self.request.get("gig_leader", '') if gig_leader is not None: the_gig.leader = gig_leader gig_postgig = self.request.get("gig_postgig", '') if gig_postgig is not None: the_gig.postgig = gig_postgig gig_status = self.request.get("gig_status", '0') old_status = the_gig.status the_gig.status = int(gig_status) if old_status != the_gig.status: edit_status_change = True gig_invite_occasionals=self.request.get("gig_invite_occasionals",None) if (gig_invite_occasionals): the_gig.invite_occasionals = True else: the_gig.invite_occasionals = False gig_hide_from_calendar=self.request.get("gig_hide_from_calendar",None) if (gig_hide_from_calendar): the_gig.hide_from_calendar = True else: the_gig.hide_from_calendar = False gig_private=self.request.get("gig_private",None) if (gig_private): the_gig.is_private = True else: the_gig.is_private = False gig_default_to_attending = self.request.get("default_to_attend",None) if (gig_default_to_attending): logging.info("\n\nattending!\n\n") the_gig.default_to_attending = True the_gig.put() # Is this a series? is_series = self.request.get("newgig_isseries", False) if is_series: number_to_copy = int(self.request.get("newgig_seriescount",1)) - 1 period = self.request.get("newgig_seriesperiod",None) last_date = the_gig.date if period == 'day': delta = datetime.timedelta(days=1) elif period == 'week': delta = datetime.timedelta(weeks=1) else: day_of_month = last_date.day if the_gig.enddate: end_delta = the_gig.enddate - the_gig.date else: end_delta = None newgigs=[] for i in range(0, number_to_copy): copy_gig = clone.clone_entity(the_gig, gig.Gig) if period == 'day' or period == 'week': last_date = last_date + delta else: # figure out what the next month is if last_date.month< 12: mo = last_date.month+1 yr = last_date.year else: mo = 1 yr = last_date.year+1 # figure out last day of next month nextmonth = last_date.replace(month=mo, day=1, year=yr) nextnextmonth = (nextmonth + datetime.timedelta(days=35)).replace(day=1) lastday=(nextnextmonth - datetime.timedelta(days=1)).day if lastday < day_of_month: day_of_gig = lastday else: day_of_gig = day_of_month last_date = last_date.replace(month=mo, day=day_of_gig, year=yr) copy_gig.date = last_date if end_delta is not None: copy_gig.enddate = copy_gig.date + end_delta newgigs.append(copy_gig) if newgigs: ndb.put_multi(newgigs) gig_notify = self.request.get("gig_notifymembers", None) if gig_notify is not None: if gig_is_new: goemail.announce_new_gig(the_gig, self.uri_for('gig_info', _full=True, gk=the_gig.key.urlsafe()), is_edit=False) else: if edit_time_change or edit_date_change or edit_status_change: change_strings=[] if edit_time_change: change_strings.append(_('Time')) if edit_date_change: change_strings.append(_('Date')) if edit_status_change: change_strings.append(_('Status')) change_str = ', '.join(change_strings) else: change_str = _('Details') goemail.announce_new_gig(the_gig, self.uri_for('gig_info', _full=True, gk=the_gig.key.urlsafe()), is_edit=True, change_string=change_str) if (the_band.rss_feed): rss.make_rss_feed_for_band(the_band) band.make_band_cal_dirty(the_band) return self.redirect(\ '/gig_info.html?&gk={0}'.format(the_gig.key.urlsafe()))