def post(self, club_id): # check credentials if not(check_admin(club_id)): add_notify("Error", "You do not have the appropriate permissions") self.redirect("/") return user = users.get_current_user() club = Club.get_by_key_name(club_id) email = get_email(user) # add emails email_block = self.request.get("newemails") emails_raw = [e for e in re.split("[\s\,\n]", email_block) if e] emails = [normalize_email(e) for e in emails_raw] emails = [e for e in emails if e] for email in emails: # add a suffix email = normalize_email(email) # use a hash for emails, assume it is unique email_key = generate_hash(email)[:10] email_obj, made = get_or_make(Email, email_key) if not(made): logging.info("Email already in the system") continue email_obj.email = email email_obj.id = email_key email_obj.put() # make sure this pair is unique query = EmailToClub.all() query.filter('email =', email_obj) query.filter('club =', club) join = query.get() if not(join): join = EmailToClub(email=email_obj, club=club) join.put() # create message if emails: add_notify("Notice", "Emails added") if len(emails) != len(emails_raw): add_notify("Notice", "Not all emails added") self.redirect("/club/%s" % club.slug)
def post(self): # check there's someone signed in user = users.get_current_user() if not(user): add_notify("Error", "You do not have the appropriate permissions") self.redirect("/") return # get associated email email_query = Email.all() email_query.filter("user = "******"Error", "You do not have the appropriate permissions") self.redirect("/") return # basic sanity check clubname = self.request.get("name") if not(clubname): add_notify("Error", "Please enter a club name") self.redirect("/") return # convert to slug clubslug = slugify(clubname) # basics of get_or_insert, with insertion club, made = get_or_make(Club, clubslug) if not(made): # generate an error add_notify("Error", "That particular club name is taken. Sorry!") self.redirect("/") return # make a club, add current user as an admin club.name = clubname club.slug = clubslug club.put() join = EmailToClub(email=email, club=club, admin=True) join.put() club_url = "/club/%s" % clubslug self.redirect(club_url)