def post(self): """Create a new competition.""" user_id, user = self.get_user() if not user or not user.admin: self.redirect("/") title = self.request.get("comp-title") description = self.request.get("comp-description") month = int(self.request.get("comp-month")) year = int(self.request.get("comp-year")) errors = [] if not title: errors.append("You forgot to give this competition a title.") comp = Competition.get_by_title_date(title, month, year) if comp: errors.append( "A competition already exists with this title (%s), month (%s), " "and year (%d)" % (title, MONTHS[month], year) ) if errors: data = {"errors": errors, "page_title": "New Competition", "user": user, "months": MONTHS} self.render("competition-new.html", **data) return # no errors so create new competiton start = date(year, month, 1) end = date(year, month, monthrange(year, month)[1]) new_comp = Competition(title=title, description=description, month=month, year=year, start=start, end=end) new_comp.put() self.redirect("/competition/admin")
def _create_competitions(self): comp1 = Competition( title='May photographs', description='', year=2012, month=5, start=date(2012, 5, 1), end=date(2012, 5, 31), finished=True, status=2 ) comp1.put() comp2 = Competition( title='June photographs', description='', year=2012, month=6, start=date(2012, 6, 1), end=date(2012, 6, 30), finished=False, status=1 ) comp2.put() return (comp1, comp2)