def post(self, dj_key): dj = Dj.get(dj_key) if (dj is None) or (self.request.get("submit") != "Edit DJ" and self.request.get("submit") != "Delete DJ"): self.session.add_flash( "There was an error processing your request. Please try again.") elif self.request.get("submit") == "Edit DJ": fullname = self.request.get("fullname") email = self.request.get("email") username = self.request.get("username") password = self.request.get("password") if password is not None: if not password == self.request.get("confirm"): self.session.add_flash("New passwords do not match.") self.redirect("/dj/djs") return # Edit the dj dj = Dj.put(fullname=fullname, email=email, username=username, password=password,) self.session.add_flash(fullname + " has been successfully edited.") elif self.request.get("submit") == "Delete DJ": dj.delete() self.session.add_flash(fullname + " has been successfully deleted.") self.redirect("/dj/djs/")
def get(self): dj = Dj.get(self.dj_key) template_values = { 'session': self.session, 'flash': self.flashes, 'dj': dj, 'posts': BlogPost.get_last(1), } self.response.out.write( template.render(get_path("dj_self.html"), template_values))
def get(self): permissions = Permission.get_all() template_values = { 'permissions': [{ 'key': p.key, 'title': p.title, 'dj_list': [Dj.get(d) for d in p.dj_list], } for p in permissions], 'session': self.session, 'flash': self.flashes, 'posts': BlogPost.get_last(num=2), } self.response.out.write( template.render(get_path("dj_permissions.html"), template_values))
def get(self, slug): program = Program.get_by_slug(slug) if not program: self.session.add_flash("Invalid program slug specified.") self.redirect("/") return template_values = { 'session': self.session, 'flash': self.flashes, 'program': program, 'djs' : tuple(Dj.get(program.dj_list) if program.dj_list else None), } self.response.out.write( template.render(get_path("show.html"), template_values))
def post(self): dj_key = ndb.Key(urlsafe=self.request.get("dj_key")) dj = Dj.get(dj_key) if not dj: self.session.add_flash( "An error occurred processing your request. Please try again.") self.redirect("/dj/myself") return dj.fullname = self.request.get("fullname") email = self.request.get("email") if email[-1] == "@": email += "bowdoin.edu" if "@" not in email: email += "@bowdoin.edu" duplicate_dj_key = Dj.get_key_by_email(email) if duplicate_dj_key and duplicate_dj_key != dj.key: error = True self.session.add_flash( "The email specified is already in use by another DJ. " "Please enter a unique one.") dj.email = email username = self.request.get("username") duplicate_dj_key = Dj.get_key_by_username() if duplicate_dj_key and duplicate_dj_key != dj.key: error = True self.session.add_flash( "The username specified is already in use by another DJ. " "Please choose another.") dj.username = username if error: self.redirect("/dj/myself") return if self.request.get("password"): if not self.request.get("password") == self.request.get("confirm"): self.session.add_flash("New passwords do not match.") self.redirect("/dj/myself") return else: dj.password = self.request.get("password") dj.put() self.session.add_flash("You have successfully updated your profile.") self.redirect("/dj/")
def get(self, program_key): program = Program.get(program_key) if not program: self.session.add_flash( "Unable to find program (" + program_key + "). Please try again.") self.redirect("/dj/programs/") else: new_programs = Program.get(num=5) template_values = { 'program_djs': [Dj.get(dj) for dj in program.dj_list], 'program': program, 'session': self.session, 'flash': self.flashes, 'new_programs': new_programs } self.response.out.write( template.render(get_path("dj_manage_programs.html"), template_values))
def get(self, slug): program = models.getProgramBySlug(slug) posts = models.getLastPosts(1) if not program: self.session.add_flash("Invalid program slug specified.") self.redirect("/") return template_values = { 'session': self.session, 'flash': self.flashes, 'program': program, 'djs' : (tuple(Dj.get(dj) for dj in program.dj_list) if program.dj_list else None), 'posts': posts, } self.response.out.write( template.render(get_path("show.html"), template_values))
def post(self): self.response.headers['Content-Type'] = 'text/json' dj_key = self.request.get("dj_key") dj = Dj.get(dj_key) errors = ""; if not dj: errors = "Unable to find DJ. " permission_key = self.request.get("permission_key") permission = Permission.get(keys=permission_key) if not permission: errors = "Unable to find permission." if errors: self.response.out.write(json.dumps({ 'err': errors, })) return action = self.request.get("action") if action == "add": if permission.has_dj(dj): errors = ("%s is already in the %s permission list."% (dj.fullname, permission.title)) else: permission.add_dj(dj) status = ("Successfully added %s to %s permission list."% (dj.fullname, permission.title)) if action == "remove": if dj.key not in permission.dj_list: errors = (dj.fullname + " was not in the " + permission.title + " permission list.") else: permission.remove_dj(dj.key) status = ("Successfully removed " + dj.fullname + " from " + permission.title + " permission list.") if errors: self.response.out.write(json.dumps({ 'err': errors, })) else: permission.put() self.response.out.write(json.dumps({ 'err': '', 'msg': status }))
def get(self, dj_key): dj = Dj.get(dj_key) # TODO: CRITICAL: CRITICAL: Don't show every goddamn DJ dj_list = [] # Seriously screw this crap #dj_list = cache.getAllDjs() if not dj: self.session.add_flash( "The DJ specified (" + dj_key + ") does not exist. Please try again.") self.redirect("/dj/djs/") else: template_values = { 'dj_list': dj_list, 'dj': dj, 'session': self.session, 'flash': self.flashes, 'posts': BlogPost.get_last(num=3), } self.response.out.write( template.render(get_path("dj_manage_djs.html"), template_values))