def post(self, this_id=None): self.tv["current_page"] = "DEVELOPER" if this_id: developer = Developer.get_by_id(normalize_id(this_id)) else: developer = Developer(id=self.request.get("CODE").strip()) developer.name = self.request.get("developer_name").strip() developer.contacts = self.request.get("developer_contact").strip() developer.put() self.redirect("/developer?success=successfully added!")
def edit_game(game_slug): game = db.session.query(Game).filter(Game.slug==game_slug).one() no_perm = no_permission(game.user_id) if no_perm: return no_perm error = None form = GameFormEdit() if form.validate_on_submit(): game.game_title = form.game_title.data game.creator_type = form.creator_type.data game.description = form.description_.data game.age_rating_id = form.age_rating_id.data words = form.words.data words = words.replace(",", "") words = words.replace(".", "") try: words = int(re.search(r'(0|(-?[1-9][0-9]*))', words).group(0)) except: # Catch exception if re.search returns None words = 0 if not words: words = 0 game.words = words playtime = 0 if form.playtime.data: try: playtime = float(form.playtime.data) except TypeError: try: playtime = int(re.search(r'(0|(-?[1-9][0-9]*))', form.playtime.data).group(0)) except TypeError: # Catch exception if re.search returns None playtime = 0 #playtime = float(form.playtime.data) if form.playtime_unit.data == 'hours': playtime = playtime * 60 game.playtime = int(math.ceil(playtime)) else: #game.playtime = 0 #game.playtime = form.playtime.data game.playtime = playtime if game.words == 0: game.words_estimate = playtime*200 else: game.words_estimate = game.words #save new creator if it doesn't exists: developer_name = form.creator.data developer_name = developer_name.replace("'", "") developer = Developer.query.filter(Developer.name==developer_name).first() if not developer: if form.creator_type.data=='person': type=1 person = Person('') db.session.add(person) db.session.commit() developer = Developer (developer_name, type, g.user.id, person_id=person.id) if form.creator_type.data=='group': type=2 group = Group('') db.session.add(group) db.session.commit() developer = Developer (developer_name, type, g.user.id, group_id=group.id) db.session.add(developer) game.developer_id = developer.id #save homepage link to link_game table: li = LinkGame.query.filter_by(game_id=game.id).first() if not li.url==form.homepage_link_url.data: db.session.delete(li) li = LinkGame(game_id=game.id, url=form.homepage_link_url.data, name = 'Home Page', link_type_id = '1') db.session.add(li) categories = [] for category in game.categories: if not category.category_id in form.categories.data: ca = CategoryGame.query.filter_by(id=category.id).first() db.session.delete(ca) categories.append(category.category_id) for category in form.categories.data: if not category in categories: db.session.add(CategoryGame(category_id=category, game_id=game.id)) game.approved = False; db.session.commit() flash('Release data was saved.') return redirect(url_for('game_details', game_slug=game_slug)) else: form.game_title.data = game.game_title form.homepage_link_url.data = game.link.url form.description_.data = game.description form.age_rating_id.data = game.age_rating_id form.words.data = game.words form.playtime.data = game.playtime form.categories.data = [] for category in game.categories: form.categories.data.append(category.category_id) dev = db.session.query(Developer).filter(Developer.id==game.developer_id).one() if dev.type==1: form.creator_type.data = "person" else: form.creator_type.data = "group" form.creator.data = dev.name developers = '[' for developer in Developer.query.filter(Developer.id>0).order_by(Developer.type): developer.name = developer.name.replace("'", "") developers += '"'+developer.name+'",' developers = developers[:-1] developers += ']' return render_template('add_game.html', navigation=return_navigation(), site_data=site_data(), form=form, developers=developers, edit=True)