コード例 #1
0
ファイル: handlers.py プロジェクト: peterbe/tornado_gkc
    def post(self, _id):
        user = self.get_current_user()
        rules = self.must_find_rules(_id, user)
        if not self.can_edit_rules(rules, user):
            raise HTTPError(403, "Can't edit these rules")
        data = djangolike_request_dict(self.request.arguments)
        form = RulesForm(data)
        form.set_genre_choices(self.get_all_published_genre_choices())

        if form.validate():
            genres = []
            for id_str in form.genres.data:
                genres.append(self.db.Genre.one({"_id": ObjectId(id_str), "approved": True})._id)
            rules.name = form.name.data
            rules.no_questions = form.no_questions.data
            rules.thinking_time = form.thinking_time.data
            rules.min_no_people = form.min_no_people.data
            rules.max_no_people = form.max_no_people.data
            rules.genres = genres
            rules.notes = form.notes.data
            rules.pictures_only = form.pictures_only.data
            rules.alternatives_only = form.alternatives_only.data
            rules.save()

            edit_url = self.reverse_url("rules_edit", rules._id)

            self.push_flash_message("Rules edited!", "Rules are ready to be played")

            self.redirect(edit_url)

        else:
            self.get(_id, form=form)
コード例 #2
0
ファイル: handlers.py プロジェクト: peterbe/tornado_gkc
    def post(self):
        user = self.get_current_user()
        data = djangolike_request_dict(self.request.arguments)
        form = RulesForm(data)
        form.set_genre_choices(self.get_all_published_genre_choices())

        if form.validate():
            genres = []
            for id_str in form.genres.data:
                genres.append(self.db.Genre.one({"_id": ObjectId(id_str), "approved": True})._id)
            rules = self.db.Rules()
            rules.name = form.name.data
            rules.no_questions = form.no_questions.data
            rules.thinking_time = form.thinking_time.data
            rules.min_no_people = form.min_no_people.data
            rules.max_no_people = form.max_no_people.data
            rules.genres = genres
            rules.notes = form.notes.data
            rules.author = user._id
            rules.default = False
            rules.pictures_only = form.pictures_only.data
            rules.alternatives_only = form.alternatives_only.data
            rules.save()

            self.push_flash_message("Rules added", "Your rules are now created and ready for play!")
            goto_url = self.reverse_url("rules")

            self.redirect(goto_url)
        else:
            self.get(form=form)
コード例 #3
0
ファイル: handlers.py プロジェクト: peterbe/tornado_gkc
 def get(self, form=None):
     options = self.get_base_options()
     if form is None:
         form = RulesForm(no_questions=10, thinking_time=15, min_no_people=2, max_no_people=2)
         form.set_genre_choices(self.get_all_published_genre_choices())
     options["form"] = form
     options["page_title"] = "Add your own rules"
     self.render("rules/add.html", **options)
コード例 #4
0
 def get(self, form=None):
     options = self.get_base_options()
     if form is None:
         form = RulesForm(
             no_questions=10,
             thinking_time=15,
             min_no_people=2,
             max_no_people=2,
         )
         form.set_genre_choices(self.get_all_published_genre_choices())
     options['form'] = form
     options['page_title'] = "Add your own rules"
     self.render("rules/add.html", **options)
コード例 #5
0
 def get(self, _id, form=None):
     options = self.get_base_options()
     rules = self.must_find_rules(_id, options['user'])
     if not self.can_edit_rules(rules, options['user']):
         raise HTTPError(403, "Can't edit these rules")
     options['rules'] = rules
     if form is None:
         initial = dict(rules)
         #initial['spell_correct'] = question.spell_correct
         #initial['genre'] = question.genre.name
         form = RulesForm(**initial)
         form.set_genre_choices(self.get_all_published_genre_choices())
     options['form'] = form
     options['page_title'] = "Edit rules"
     self.render('rules/edit.html', **options)
コード例 #6
0
ファイル: handlers.py プロジェクト: peterbe/tornado_gkc
 def get(self, _id, form=None):
     options = self.get_base_options()
     rules = self.must_find_rules(_id, options["user"])
     if not self.can_edit_rules(rules, options["user"]):
         raise HTTPError(403, "Can't edit these rules")
     options["rules"] = rules
     if form is None:
         initial = dict(rules)
         # initial['spell_correct'] = question.spell_correct
         # initial['genre'] = question.genre.name
         form = RulesForm(**initial)
         form.set_genre_choices(self.get_all_published_genre_choices())
     options["form"] = form
     options["page_title"] = "Edit rules"
     self.render("rules/edit.html", **options)
コード例 #7
0
    def post(self, _id):
        user = self.get_current_user()
        rules = self.must_find_rules(_id, user)
        if not self.can_edit_rules(rules, user):
            raise HTTPError(403, "Can't edit these rules")
        data = djangolike_request_dict(self.request.arguments)
        form = RulesForm(data)
        form.set_genre_choices(self.get_all_published_genre_choices())

        if form.validate():
            genres = []
            for id_str in form.genres.data:
                genres.append(
                    self.db.Genre.one({
                        '_id': ObjectId(id_str),
                        'approved': True
                    })._id)
            rules.name = form.name.data
            rules.no_questions = form.no_questions.data
            rules.thinking_time = form.thinking_time.data
            rules.min_no_people = form.min_no_people.data
            rules.max_no_people = form.max_no_people.data
            rules.genres = genres
            rules.notes = form.notes.data
            rules.pictures_only = form.pictures_only.data
            rules.alternatives_only = form.alternatives_only.data
            rules.save()

            edit_url = self.reverse_url('rules_edit', rules._id)

            self.push_flash_message("Rules edited!",
                                    "Rules are ready to be played")

            self.redirect(edit_url)

        else:
            self.get(_id, form=form)
コード例 #8
0
    def post(self):
        user = self.get_current_user()
        data = djangolike_request_dict(self.request.arguments)
        form = RulesForm(data)
        form.set_genre_choices(self.get_all_published_genre_choices())

        if form.validate():
            genres = []
            for id_str in form.genres.data:
                genres.append(
                    self.db.Genre.one({
                        '_id': ObjectId(id_str),
                        'approved': True
                    })._id)
            rules = self.db.Rules()
            rules.name = form.name.data
            rules.no_questions = form.no_questions.data
            rules.thinking_time = form.thinking_time.data
            rules.min_no_people = form.min_no_people.data
            rules.max_no_people = form.max_no_people.data
            rules.genres = genres
            rules.notes = form.notes.data
            rules.author = user._id
            rules.default = False
            rules.pictures_only = form.pictures_only.data
            rules.alternatives_only = form.alternatives_only.data
            rules.save()

            self.push_flash_message(
                "Rules added",
                "Your rules are now created and ready for play!")
            goto_url = self.reverse_url('rules')

            self.redirect(goto_url)
        else:
            self.get(form=form)