Exemple #1
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)
Exemple #2
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)
Exemple #3
0
    def post(self):
        user = self.get_current_user()
        if not self.is_admin_user(user):
            raise HTTPError(403, "Not admin user")

        data = djangolike_request_dict(self.request.arguments)
        form = PostForm(data)
        if form.validate():
            message = form.message.data
            next_url = self.get_argument('next_url', None)
            #self.finish(message)
            #return
            access_token = settings.TWITTER_KWISSLE_ACCESS_TOKENS[0]
            self.twitter_request(
                "/statuses/update",
                post_args={"status": message},
                access_token=access_token,
                callback=self.async_callback(lambda x: self._on_post(x, next_url=next_url)),
                next_url=next_url)
        else:
            self.get(form=form)
Exemple #4
0
    def post(self):
        user = self.get_current_user()
        if not self.is_admin_user(user):
            raise HTTPError(403, "Not admin user")

        data = djangolike_request_dict(self.request.arguments)
        form = PostForm(data)
        if form.validate():
            message = form.message.data
            next_url = self.get_argument('next_url', None)
            #self.finish(message)
            #return
            access_token = settings.TWITTER_KWISSLE_ACCESS_TOKENS[0]
            self.twitter_request(
                "/statuses/update",
                post_args={"status": message},
                access_token=access_token,
                callback=self.async_callback(
                    lambda x: self._on_post(x, next_url=next_url)),
                next_url=next_url)
        else:
            self.get(form=form)
Exemple #5
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)
Exemple #6
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)