def _comp_photo(self, user): photo_title = self.request.get('photo-title') comp_id = int(self.request.get('comp-id')) comp = Competition.get_by_id(comp_id) usercomp = UserComp(user=user.key, comp=comp.key) usercomp.put() return {'competition': comp.key, 'title': photo_title}
def get(self, comp_id=0): """Show the competition page.""" user_id, user = self.get_user() comp_id = int(comp_id) comp = Competition.get_by_id(comp_id) if comp is None: self.redirect("/competitions") return month_str = MONTHS[comp.month] data = { "user": user, "comp": comp, "year": comp.year, "month": month_str, "page_title": comp.title, "page_subtitle": comp.get_status(), "description": comp.description, } if comp.status == OPEN: self.view_open(user, comp_id, comp, data) elif comp.status == SCORING: user_comp = self.get_usercomp(user, comp) self.view_scoring(user, comp_id, comp, user_comp, data) else: # completed self.view_complete(user, comp_id, comp, data)
def post(self, comp_id=0): """A user is submitting scores.""" user_id, user = self.get_user() comp_id = int(comp_id) comp = Competition.get_by_id(comp_id) if not user or not comp: # stop some unauthorised post submissions. self.redirect("/competitions") return results = self.parse_scores(self.request.POST) for photo_id, score in results.iteritems(): photo = Photo.get_by_id(photo_id) # photo = self.get_photo(photo_id) new_score = Scores(photo=photo.key, user_from=user.key, score=score) new_score.put() # record that user has submitted scores for this comp usercomp = self.get_usercomp(user, comp) usercomp.submitted_scores = True usercomp.put() self.redirect("/competition/%d" % (comp_id))
def get(self, comp_id): user_id, user = self.get_user() if not user or not user.admin: self.redirect("/") return comp_id = int(comp_id) comp = Competition.get_by_id(comp_id) data = {"user": user, "page_title": "Delete Competition", "comp_id": comp_id, "comp": comp} self.render("competition-delete.html", **data)
def get(self, comp_id): # should check for logged in user cookie user_id, user = self.get_user() if not user or not user.admin: self.redirect("/") return self.response.content_type = "text/csv" comp_id = int(comp_id) comp = Competition.get_by_id(comp_id) logging.info(comp) self.write(csv_scores(comp))
def get(self, comp_id): "Show the competition modification page for a particular competition." user_id, user = self.get_user() if not user or not user.admin: self.redirect("/") return comp_id = int(comp_id) comp = Competition.get_by_id(comp_id) if not comp: self.redirect("/competition/admin") return data = self._data(comp, user) self.render("competition-modify.html", **data)
def post(self, comp_id): """ Delete a competition, photographs, comments """ user_id, user = self.get_user() if not user or not user.admin: self.redirect("/") return comp_id = int(comp_id) comp = Competition.get_by_id(comp_id) logging.info("Deleting comp: %s" % comp) comp.delete() self.redirect("/competition/admin")
def post(self, comp_id): """Modify a competition.""" user_id, user = self.get_user() if not user or not user.admin: self.redirect("/") return new_title = self.request.get("comp-title") new_description = self.request.get("comp-description") new_status = int(self.request.get("comp-status")) comp_id = int(comp_id) comp = Competition.get_by_id(comp_id) if not new_title: self.report_error(comp, "Error - blank title.") return logging.info("updating competition: status %d, new status: %d", comp.status, new_status) successful_update, error = self._successful_update(comp, new_status) if successful_update: self._update_competition(comp, new_title, new_description, new_status) else: self._report_error(comp, user, error)