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 GigTrashcanPage handler') else: the_band_key = band.band_key_from_urlsafe(the_band_key_url) # make sure this member is actually a band admin if not assoc.get_admin_status_for_member_for_band_key( the_user, the_band_key) and not the_user.is_superuser: raise gigoexceptions.GigoException( 'user called GigTrashcanPage handler but is not admin') the_band = the_band_key.get() if the_band is None: raise gigoexceptions.GigoException( 'GigTrashcanPage handler calledd without a band') the_gigs = gig.get_trashed_gigs_for_band_key(the_band_key) 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_trashcan.html', template_args)
def get(self): """ post handler - wants an ak """ the_assoc_keyurl = self.request.get('ak', '0') if the_assoc_keyurl == '0': return # todo figure out what to do the_assoc_key = assoc.assoc_key_from_urlsafe(the_assoc_keyurl) the_assoc = the_assoc_key.get() # make sure we're a band admin or a superuser if not (self.user.is_superuser or assoc.get_admin_status_for_member_for_band_key( self.user, the_assoc.band)): return self.redirect('/') the_band_key = the_assoc.band the_member_key = the_assoc.member assoc.delete_association_from_key(the_assoc_key) invites = assoc.get_inviting_assoc_keys_from_member_key(the_member_key) if invites is None or (len(invites) == 1 and invites[0] == the_assoc_key): logging.error('removed last invite from member; deleteing') member.forget_member_from_key(the_member_key) return self.redirect('/band_info.html?bk={0}'.format( the_band_key.urlsafe()))
def get(self): topic_key_str = self.request.get("tk", None) if topic_key_str is None: logging.error('no topic key in ForumTopicHandler') return self.redirect('/') the_topic_key = ndb.Key(urlsafe=topic_key_str) the_topic = the_topic_key.get() the_band_key = the_topic_key.parent().parent() # is the current user a band admin? user_is_band_admin = assoc.get_admin_status_for_member_for_band_key( self.user, the_band_key) if not (user_is_band_admin or member.member_is_superuser(self.user)): logging.error( "non-admin trying to toggle topic state in TopicToggleOpenHandler" ) return self.redirect('/') the_topic.open = not the_topic.open the_topic.put() return self.redirect('/forum_topic?tk={0}'.format(topic_key_str))
def get(self): """ post handler - wants an ak """ the_assoc_keyurl=self.request.get('ak','0') if the_assoc_keyurl=='0': return # todo figure out what to do the_assoc_key = assoc.assoc_key_from_urlsafe(the_assoc_keyurl) the_assoc = the_assoc_key.get() # make sure we're a band admin or a superuser if not (self.user.is_superuser or assoc.get_admin_status_for_member_for_band_key(self.user, the_assoc.band)): return self.redirect('/') the_band_key = the_assoc.band the_member_key = the_assoc.member assoc.delete_association_from_key(the_assoc_key) invites = assoc.get_inviting_assoc_keys_from_member_key(the_member_key) if invites is None or (len(invites)==1 and invites[0]==the_assoc_key): logging.error('removed last invite from member; deleteing') forget_member_from_key(the_member_key) return self.redirect('/band_info.html?bk={0}'.format(the_band_key.urlsafe()))
def is_authorized_to_edit_band(the_band_key, the_user): if assoc.get_admin_status_for_member_for_band_key( the_user, the_band_key) or the_user.is_superuser: return True else: logging.error( "Non-authorized user tried to access admin function - user key {0}" .format(the_user.key.urlsafe())) return False
def _make_page(self,the_user,the_band=None): """ produce the info page """ # find the band we're interested in if the_band is None: band_key_str = self.request.get("bk", None) if band_key_str is None: self.response.write('no band key passed in!') return # todo figure out what to do if there's no ID passed in the_band_key = band.band_key_from_urlsafe(band_key_str) the_band = band.get_band(the_band_key) if the_band is None: self.response.write('did not find a band!') return # todo figure out what to do if we didn't find it if the_user is None: the_user_is_associated = False the_user_is_confirmed = False the_user_admin_status = False the_user_is_superuser = False else: the_user_is_associated = assoc.get_associated_status_for_member_for_band_key(the_user, the_band_key) the_user_is_confirmed = assoc.get_confirmed_status_for_member_for_band_key(the_user, the_band_key) the_user_admin_status = assoc.get_admin_status_for_member_for_band_key(the_user, the_band_key) the_user_is_superuser = member.member_is_superuser(the_user) if the_user_admin_status or the_user_is_superuser: the_pending = assoc.get_pending_members_from_band_key(the_band_key) the_invited_assocs = assoc.get_invited_member_assocs_from_band_key(the_band_key) the_invited = [(x.key, member.get_member(x.member).name) for x in the_invited_assocs] else: the_pending = [] the_invited = [] member_links=None if the_band.member_links: member_links=[] link_list = the_band.member_links.split('\n') for l in link_list: link_info = l.split(':',1) if len(link_info) == 2: member_links.append([link_info[0].strip(), link_info[1].strip()]) template_args = { 'the_band' : the_band, 'the_user_is_associated': the_user_is_associated, 'the_user_is_confirmed': the_user_is_confirmed, 'the_user_is_band_admin': the_user_admin_status, 'the_pending_members': the_pending, 'the_invited_members': the_invited, 'the_member_links': member_links, 'num_sections': len(the_band.sections) } self.render_template('band_info.html', template_args)
def post(self): """ return the sections for a band """ the_user = self.user the_band_key_str = self.request.get('bk', '0') if the_band_key_str == '0': return # todo figure out what to do the_band_key = band.band_key_from_urlsafe(the_band_key_str) the_band = band.get_band(the_band_key) the_section_index_str = self.request.get('ski', None) if the_section_index_str is None: the_section is None else: if the_section_index_str == 'None': the_section = None the_section_key = None else: the_section_key = the_band.sections[int(the_section_index_str)] the_section = the_section_key.get() the_assocs = assoc.get_assocs_of_band_key_for_section_key( the_band_key, the_section_key) if the_section is None and len(the_assocs) == 0: self.response.write("None") return member_keys = [a.member for a in the_assocs] the_members = member.get_member(member_keys) # make sure members and assocs are in the right order the_members = sorted(the_members, key=lambda m: member_keys.index(m.key)) someone_is_new = False the_user_is_band_admin = assoc.get_admin_status_for_member_for_band_key( the_user, the_band_key) template_args = { 'the_band': the_band, 'the_section': the_section, 'the_assocs': the_assocs, 'the_members': the_members, 'has_sections': the_band.sections and len(the_band.sections) > 0, 'the_user_is_band_admin': the_user_is_band_admin, 'someone_is_new': someone_is_new } self.render_template('band_sections.html', template_args)
def post(self): """ return the sections for a band """ the_user = self.user the_band_key_str=self.request.get('bk','0') if the_band_key_str=='0': return # todo figure out what to do the_band_key = band.band_key_from_urlsafe(the_band_key_str) the_band = band.get_band(the_band_key) the_section_index_str = self.request.get('ski',None) if the_section_index_str is None: the_section is None else: if the_section_index_str == 'None': the_section = None the_section_key = None else: the_section_key = the_band.sections[int(the_section_index_str)] the_section = the_section_key.get() the_assocs = assoc.get_assocs_of_band_key_for_section_key(the_band_key, the_section_key) if the_section is None and len(the_assocs)==0: self.response.write("None") return member_keys = [a.member for a in the_assocs] the_members = member.get_member(member_keys) # make sure members and assocs are in the right order the_members = sorted(the_members, key=lambda m: member_keys.index(m.key)) someone_is_new = False the_user_is_band_admin = assoc.get_admin_status_for_member_for_band_key(the_user, the_band_key) template_args = { 'the_band' : the_band, 'the_section' : the_section, 'the_assocs' : the_assocs, 'the_members' : the_members, 'has_sections' : the_band.sections and len(the_band.sections) > 0, 'the_user_is_band_admin' : the_user_is_band_admin, 'someone_is_new' : someone_is_new } self.render_template('band_sections.html', template_args)
def post(self): """post handler - if we are edited by the template, handle it here and redirect back to info page""" the_user = self.user the_band_key_url=self.request.get("bk",None) if the_band_key_url is None: self.response.write('did not find a band!') return # todo figure out what to do if we didn't find it the_band_key = band.band_key_from_urlsafe(the_band_key_url) if not assoc.get_admin_status_for_member_for_band_key(the_user, the_band_key) and not the_user.is_superuser: return self.redirect('/band_info.html?bk={0}'.format(the_band.key.urlsafe())) return self.redirect('/band_info.html?bk={0}'.format(the_band.key.urlsafe()))
def can_edit_gig(the_user, the_gig=None, the_band=None): authorized = False if the_user.is_superuser: authorized = True elif the_gig and the_gig.contact == the_user.key: authorized = True elif the_gig is None and the_band and the_band.anyone_can_create_gigs: authorized = True elif the_gig is not None and the_band and the_band.anyone_can_manage_gigs: authorized = True elif the_band and assoc.get_admin_status_for_member_for_band_key(the_user, the_band.key): authorized = True return authorized
def can_edit_gig(the_user, the_gig=None, the_band=None): authorized = False if the_user.is_superuser: authorized = True elif the_gig and the_gig.contact == the_user.key: authorized = True elif the_gig is None and the_band and the_band.anyone_can_create_gigs: authorized = True elif the_gig is not None and the_band and the_band.anyone_can_manage_gigs: authorized = True elif the_band and assoc.get_admin_status_for_member_for_band_key(the_user, the_band.key): authorized = True return authorized
def get_add_gig_band_list(cls, req, the_member_key): """ check to see if this is in the session - if so, just use it """ if 'member_addgigbandlist' in req.session.keys() and not req.member_cache_is_dirty(the_member_key): the_manage_bands = req.session['member_addgigbandlist'] else: band_keys=assoc.get_band_keys_of_member_key(the_member_key, confirmed_only=True) the_bands = ndb.get_multi(band_keys) the_manage_bands = [] for b in the_bands: if b.anyone_can_manage_gigs or \ req.user.is_superuser or \ assoc.get_admin_status_for_member_for_band_key(req.user, b.key): the_manage_bands.append(b) req.session['member_addgigbandlist'] = the_manage_bands return the_manage_bands
def post(self): """post handler - if we are edited by the template, handle it here and redirect back to info page""" the_user = self.user the_band_key_url = self.request.get("bk", None) if the_band_key_url is None: self.response.write('did not find a band!') return # todo figure out what to do if we didn't find it the_band_key = band.band_key_from_urlsafe(the_band_key_url) if not assoc.get_admin_status_for_member_for_band_key( the_user, the_band_key) and not the_user.is_superuser: return self.redirect('/band_info.html?bk={0}'.format( the_band.key.urlsafe())) return self.redirect('/band_info.html?bk={0}'.format( the_band.key.urlsafe()))
def get(self): topic_key_str = self.request.get("tk", None) if topic_key_str is None: logging.error('no topic key in ForumTopicHandler') return self.redirect('/') the_topic_key = ndb.Key(urlsafe=topic_key_str) the_topic = the_topic_key.get() the_forum_key = the_topic_key.parent() the_forum = the_forum_key.get() the_band_key = the_forum_key.parent() if the_band_key: the_band = the_band_key.get() # is the current user a band admin? user_is_forum_admin = assoc.get_admin_status_for_member_for_band_key( self.user, the_band_key) or self.user.is_superuser else: the_band = None user_is_forum_admin = self.user.is_superuser the_gig = the_topic.parent_gig topic_count = get_forumpost_count_from_topic_key(the_topic.key) num_pages = int(math.ceil(topic_count * 1.0 / global_page_size)) last_str = self.request.get("last", None) if last_str == "1": the_last = "1" else: the_last = "0" template_args = { 'the_forum': the_forum, 'the_topic_name': searchtext.get_search_text(the_topic.text_id), 'the_topic': the_topic, 'num_pages': num_pages, 'the_gig': the_gig, 'the_last': the_last, 'user_is_forum_admin': user_is_forum_admin } self.render_template('forum_topic.html', template_args)
def make_page(self, the_user): the_band_key_url = self.request.get("bk", None) if the_band_key_url is None: return else: the_band_key = band.band_key_from_urlsafe(the_band_key_url) the_band = band.get_band(the_band_key) if the_band is None: self.response.write('did not find a band!') return # todo figure out what to do if we didn't find it if not assoc.get_admin_status_for_member_for_band_key( the_user, the_band_key) and not the_user.is_superuser: return self.redirect('/band_info.html?bk={0}'.format( the_band.key.urlsafe())) template_args = {'the_band': the_band} self.render_template('band_invite.html', template_args)
def make_page(self, the_user): the_band_key_url=self.request.get("bk",None) if the_band_key_url is None: return else: the_band_key = band.band_key_from_urlsafe(the_band_key_url) the_band = band.get_band(the_band_key) if the_band is None: self.response.write('did not find a band!') return # todo figure out what to do if we didn't find it if not assoc.get_admin_status_for_member_for_band_key(the_user, the_band_key) and not the_user.is_superuser: return self.redirect('/band_info.html?bk={0}'.format(the_band.key.urlsafe())) template_args = { 'the_band' : the_band } self.render_template('band_invite.html', template_args)
def get_add_gig_band_list(cls, req, the_member_key): """ check to see if this is in the session - if so, just use it """ if hasattr(req,'session') is False: return [] if 'member_addgigbandlist' in req.session.keys() and not req.member_cache_is_dirty(the_member_key): the_manage_bands = req.session['member_addgigbandlist'] else: band_keys=assoc.get_band_keys_of_member_key(the_member_key, confirmed_only=True) the_bands = ndb.get_multi(band_keys) the_manage_bands = [] for b in the_bands: if b.anyone_can_create_gigs or \ req.user.is_superuser or \ assoc.get_admin_status_for_member_for_band_key(req.user, b.key): the_manage_bands.append(b) req.session['member_addgigbandlist'] = the_manage_bands return the_manage_bands
def make_page(self, the_user): # make sure I'm an admin or a superuser the_user_is_superuser = member.member_is_superuser(the_user) if self.request.get("new", None) is not None: # creating a new band if not the_user_is_superuser: return self.redirect('/') the_band = None is_new = True else: is_new = False the_band_key_str = self.request.get("bk", '0') if the_band_key_str == '0': return else: the_band_key = band.band_key_from_urlsafe(the_band_key_str) the_user_admin_status = assoc.get_admin_status_for_member_for_band_key( the_user, the_band_key) if not the_user_admin_status and not the_user_is_superuser: return self.redirect('/') the_band = band.get_band(the_band_key) if the_band is None: self.response.write('did not find a band!') return # todo figure out what to do if we didn't find it template_args = { 'the_band': the_band, 'timezones': pytz.common_timezones, 'newmember_is_active': is_new, 'is_new': is_new } self.render_template('band_edit.html', template_args)
def make_page(self, the_user): # make sure I'm an admin or a superuser the_user_is_superuser = member.member_is_superuser(the_user) if self.request.get("new",None) is not None: # creating a new band if not the_user_is_superuser: return self.redirect('/') the_band=None is_new=True else: is_new=False the_band_key_str=self.request.get("bk", '0') if the_band_key_str == '0': return else: the_band_key = band.band_key_from_urlsafe(the_band_key_str) the_user_admin_status = assoc.get_admin_status_for_member_for_band_key(the_user, the_band_key) if not the_user_admin_status and not the_user_is_superuser: return self.redirect('/') the_band = band.get_band(the_band_key) if the_band is None: self.response.write('did not find a band!') return # todo figure out what to do if we didn't find it template_args = { 'the_band': the_band, 'timezones': pytz.common_timezones, 'newmember_is_active': is_new, 'is_new': is_new } self.render_template('band_edit.html', template_args)
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 GigTrashcanPage handler') else: the_band_key = band.band_key_from_urlsafe(the_band_key_url) # make sure this member is actually a band admin if not assoc.get_admin_status_for_member_for_band_key(the_user, the_band_key) and not the_user.is_superuser: raise gigoexceptions.GigoException('user called GigTrashcanPage handler but is not admin') the_band = the_band_key.get() if the_band is None: raise gigoexceptions.GigoException('GigTrashcanPage handler calledd without a band') the_gigs = gig.get_trashed_gigs_for_band_key(the_band_key) 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_trashcan.html', template_args)
def post(self): """ return the sections for a band """ the_user = self.user the_band_key_str = self.request.get('bk', '0') if the_band_key_str == '0': return # todo figure out what to do the_band_key = ndb.Key(urlsafe=the_band_key_str) the_band = the_band_key.get() the_section_index_str = self.request.get('ski', None) if the_section_index_str is None: the_section is None else: if the_section_index_str == 'None': the_section = None the_section_key = None else: the_section_key = the_band.sections[int(the_section_index_str)] the_section = the_section_key.get() the_assocs = assoc.get_assocs_of_band_key_for_section_key( the_band_key, the_section_key) if the_section is None and len(the_assocs) == 0: self.response.write("None") return member_keys = [a.member for a in the_assocs] the_members = ndb.get_multi(member_keys) # make sure members and assocs are in the right order the_members = sorted(the_members, key=lambda m: member_keys.index(m.key)) # someone_is_new = False # lately = datetime.datetime.now() - datetime.timedelta(days=4) # for a_section in the_members_by_section: # if a_section[1]: # for a in a_section[1]: # if a.created and a.created > lately: # a.is_new=True # someone_is_new = True someone_is_new = False the_user_is_band_admin = assoc.get_admin_status_for_member_for_band_key( the_user, the_band_key) template_args = { 'the_band': the_band, 'the_section': the_section, 'the_assocs': the_assocs, 'the_members': the_members, 'has_sections': the_band.sections and len(the_band.sections) > 0, 'the_user_is_band_admin': the_user_is_band_admin, 'someone_is_new': someone_is_new } self.render_template('band_sections.html', template_args)
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 = gig.gig_key_from_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_plans, the_plan_counts, the_sections, band_has_sections = _makeInfoPageInfo( the_user, the_gig, the_band_key) # is the current user a band admin? the_user_is_band_admin = assoc.get_admin_status_for_member_for_band_key( the_user, the_band_key) the_band = the_band_key.get() user_can_edit = gig.can_edit_gig(the_user, the_gig, the_band) user_can_create = gig.can_edit_gig(the_user, None, the_band) 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 = '' if the_gig.address: if the_gig.address.startswith('http'): address_link = the_gig.address else: address_link = u"http://maps.google.com?q={0}".format( the_gig.address.replace(' ', '+')) else: address_link = '' 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, 'the_user_is_band_admin': the_user_is_band_admin, 'user_can_edit': user_can_edit, 'user_can_create': user_can_create, 'the_plan_counts': the_plan_counts, 'address_link': address_link } 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)
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) # get all the plans for this gig - might actually not be any yet. all_plans = plan.get_plans_for_gig_key(gig_key, keys_only=False) # now, for each associated member, find or make a plan the_plans = [] the_new_plans = [] # in case we need to make new ones the_plan_counts = {} for i in range(len(plan.plan_text)): the_plan_counts[i] = 0 need_empty_section = False for the_assoc in the_assocs: a_member_key = the_assoc.member new_plan = False for p in all_plans: if p.member == a_member_key: the_plan = p break else: the_plan = plan.Plan(parent=gig_key, member=a_member_key, value=0, comment="", section=None) the_new_plans.append(the_plan) new_plan = True 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'] = the_plan 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_plan_counts[the_plan.value] += 1 if the_new_plans: ndb.put_multi(the_new_plans) 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? the_user_is_band_admin = assoc.get_admin_status_for_member_for_band_key( the_user, the_band_key) the_band = the_band_key.get() user_can_edit = can_edit_gig(the_user, the_gig, the_band) user_can_create = can_edit_gig(the_user, None, the_band) 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, 'the_user_is_band_admin': the_user_is_band_admin, 'user_can_edit': user_can_edit, 'user_can_create': user_can_create, 'the_plan_counts': the_plan_counts } 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)
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 = gig.gig_key_from_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_plans, the_plan_counts, the_sections, band_has_sections = _makeInfoPageInfo(the_user, the_gig, the_band_key) # is the current user a band admin? the_user_is_band_admin = assoc.get_admin_status_for_member_for_band_key(the_user, the_band_key) the_band = the_band_key.get() user_can_edit = gig.can_edit_gig(the_user, the_gig, the_band) user_can_create = gig.can_edit_gig(the_user, None, the_band) 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, 'the_user_is_band_admin' : the_user_is_band_admin, 'user_can_edit' : user_can_edit, 'user_can_create' : user_can_create, 'the_plan_counts' : the_plan_counts } 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)
def post(self): the_user = self.user 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) the_band = band.get_band(the_band_key) out='' if not assoc.get_admin_status_for_member_for_band_key(the_user, the_band_key) and not the_user.is_superuser: out='not admin' the_email_blob = self.request.get('e','') # remove commas and stuff the_email_blob = the_email_blob.replace(',',' ') the_email_blob = the_email_blob.replace('\n',' ') the_emails = the_email_blob.split(' ') ok_email = [] not_ok_email = [] for e in the_emails: if e: e=e.lower() if goemail.validate_email(e): ok_email.append(e) else: not_ok_email.append(e) # ok, now we have a list of good email addresses (or, at least, well-formed email addresses # for each one, create a new member (if there isn't one already) for e in ok_email: existing_member = member.get_member_from_email(e) # logging.info("existing_member:{0}".format(existing_member)) if existing_member: # make sure this person isn't already a member of this band; if not, send invite if not assoc.get_associated_status_for_member_for_band_key(existing_member, the_band_key): # create assoc for this member - they're already on the gig-o # send email letting them know they're in the band assoc.new_association(existing_member, the_band, confirm=True) goemail.send_new_band_via_invite_email(the_band, existing_member, the_band.new_member_message) else: # create assoc for this member - but because they're not verified, will just show up as 'invited' # logging.info("creating new member") user_data = member.create_new_member(email=e, name='', password='******') # logging.info("creating new member: {0}".format(user_data)) the_user = user_data[1] if the_user: assoc.new_association(the_user, the_band, confirm=True, invited=True) # send email inviting them to the gig-o token = self.user_model.create_invite_token(the_user.get_id()) verification_url = self.uri_for('inviteverification', type='i', user_id=the_user.get_id(), signup_token=token, _full=True) goemail.send_gigo_invite_email(the_band, the_user, verification_url) # set the new users's locale to be the same as mine by default. if the_user.preferences.locale != self.user.preferences.locale: the_user.preferences.locale = self.user.preferences.locale the_user.put() else: logging.error("Tried to create new invited member, but failed!") template_args = { 'the_band_keyurl' : the_band_keyurl, 'the_ok' : ok_email, 'the_not_ok' : not_ok_email } self.render_template('band_invite_result.html', template_args)
def is_authorized_to_edit_band(the_band_key, the_user): if assoc.get_admin_status_for_member_for_band_key(the_user, the_band_key) or the_user.is_superuser: return True else: logging.error("Non-authorized user tried to access admin function - user key {0}".format(the_user.key.urlsafe())) return False
def _make_page(self, the_user, the_band=None): """ produce the info page """ # find the band we're interested in if the_band is None: band_key_str = self.request.get("bk", None) if band_key_str is None: self.response.write('no band key passed in!') return # todo figure out what to do if there's no ID passed in the_band_key = band.band_key_from_urlsafe(band_key_str) the_band = band.get_band(the_band_key) if the_band is None: self.response.write('did not find a band!') return # todo figure out what to do if we didn't find it if the_user is None: the_user_is_associated = False the_user_is_confirmed = False the_user_admin_status = False the_user_is_superuser = False else: the_user_is_associated = assoc.get_associated_status_for_member_for_band_key( the_user, the_band_key) the_user_is_confirmed = assoc.get_confirmed_status_for_member_for_band_key( the_user, the_band_key) the_user_admin_status = assoc.get_admin_status_for_member_for_band_key( the_user, the_band_key) the_user_is_superuser = member.member_is_superuser(the_user) if the_user_admin_status or the_user_is_superuser: the_pending = assoc.get_pending_members_from_band_key(the_band_key) the_invited_assocs = assoc.get_invited_member_assocs_from_band_key( the_band_key) the_invited = [(x.key, member.get_member(x.member).name) for x in the_invited_assocs] else: the_pending = [] the_invited = [] member_links = None if the_band.member_links: member_links = [] link_list = the_band.member_links.split('\n') for l in link_list: link_info = l.split(':', 1) if len(link_info) == 2: member_links.append( [link_info[0].strip(), link_info[1].strip()]) template_args = { 'the_band': the_band, 'the_user_is_associated': the_user_is_associated, 'the_user_is_confirmed': the_user_is_confirmed, 'the_user_is_band_admin': the_user_admin_status, 'the_pending_members': the_pending, 'the_invited_members': the_invited, 'the_member_links': member_links, 'num_sections': len(the_band.sections) } self.render_template('band_info.html', template_args)
def post(self): forum_key_str = self.request.get("fk", None) if forum_key_str is None: logging.error('no forum key in ForumAllTopicsHandler') return self.redirect('/') the_forum_key = ndb.Key(urlsafe=forum_key_str) if the_forum_key is None: return # the_page_str = self.request.get("page", None) if the_page_str is None: the_page = 1 else: try: the_page = int(the_page_str) except ValueError: the_page = 1 the_num_pages_str = self.request.get("np", None) # number of pages if the_num_pages_str is None: the_num_pages = 1 else: try: the_num_pages = int(the_num_pages_str) except ValueError: the_num_pages = 1 the_topics = get_forumtopics_for_forum_key(the_forum_key, page=the_page) the_topic_titles = [] for a_topic in the_topics: the_txt = searchtext.get_search_text(a_topic.text_id) if a_topic.parent_gig is None: the_topic_titles.append(the_txt) else: the_topic_titles.append('{0}: {1}'.format(_("Gig"), the_txt)) # is the current user a forum admin? user_is_forum_admin = False forum_parent_key = the_forum_key.parent() if forum_parent_key: forum_parent = forum_parent_key.get() if type(forum_parent) is Band: user_is_forum_admin = assoc.get_admin_status_for_member_for_band_key( self.user, forum_parent.key) else: # if there's no parent, this is a public forum and only superuser can edit if self.user.is_superuser: user_is_forum_admin = True template_args = { 'the_forum_key_str': forum_key_str, 'user_is_forum_admin': user_is_forum_admin, 'the_topic_titles': the_topic_titles, 'the_topics': the_topics, 'the_date_formatter': member.format_date_for_member, 'the_page': the_page, 'the_num_pages': the_num_pages } self.render_template('forum_topics.html', template_args)
def post(self): the_user = self.user 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) the_band = band.get_band(the_band_key) out = '' if not assoc.get_admin_status_for_member_for_band_key( the_user, the_band_key) and not the_user.is_superuser: out = 'not admin' the_email_blob = self.request.get('e', '') # remove commas and stuff the_email_blob = the_email_blob.replace(',', ' ') the_email_blob = the_email_blob.replace('\n', ' ') the_emails = the_email_blob.split(' ') ok_email = [] not_ok_email = [] for e in the_emails: if e: e = e.lower() if goemail.validate_email(e): ok_email.append(e) else: not_ok_email.append(e) # ok, now we have a list of good email addresses (or, at least, well-formed email addresses # for each one, create a new member (if there isn't one already) for e in ok_email: existing_member = member.get_member_from_email(e) # logging.info("existing_member:{0}".format(existing_member)) if existing_member: # make sure this person isn't already a member of this band; if not, send invite if not assoc.get_associated_status_for_member_for_band_key( existing_member, the_band_key): # create assoc for this member - they're already on the gig-o # send email letting them know they're in the band assoc.new_association(existing_member, the_band, confirm=True) goemail.send_new_band_via_invite_email( the_band, existing_member, the_band.new_member_message) else: # create assoc for this member - but because they're not verified, will just show up as 'invited' # logging.info("creating new member") user_data = member.create_new_member(email=e, name='', password='******') # logging.info("creating new member: {0}".format(user_data)) the_user = user_data[1] if the_user: assoc.new_association(the_user, the_band, confirm=True, invited=True) # send email inviting them to the gig-o token = self.user_model.create_invite_token( the_user.get_id()) verification_url = self.uri_for('inviteverification', type='i', user_id=the_user.get_id(), signup_token=token, _full=True) goemail.send_gigo_invite_email(the_band, the_user, verification_url) # set the new users's locale to be the same as mine by default. if the_user.preferences.locale != self.user.preferences.locale: the_user.preferences.locale = self.user.preferences.locale the_user.put() else: logging.error( "Tried to create new invited member, but failed!") template_args = { 'the_band_keyurl': the_band_keyurl, 'the_ok': ok_email, 'the_not_ok': not_ok_email } self.render_template('band_invite_result.html', template_args)
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)