Ejemplo n.º 1
0
 def post(self):
     """Create a new idea for the current user"""
     if is_admin():
         idea_ns.abort(403, 'Admin is not allowed to create ideas')
     json_data = request.get_json(force=True)
     if idea_title_exists(json_data['title']):
         idea_ns.abort(409, "Idea already exists")
     future_idea = save_idea_by_json(json_data, g.current_user)
     return marshal(future_idea.as_dict(), idea), 201, {'Location': '{}/{}'.format(request.url, future_idea.id)}
Ejemplo n.º 2
0
 def put(self, idea_id):
     """Update the idea with the selected idea_id"""
     if is_admin():
         idea_ns.abort(403, 'Admin is not allowed to modify ideas')
     if not idea_exists(idea_id):
         idea_ns.abort(404, 'Idea not found')
     check_for_idea_ownership(get_idea(idea_id))
     json_data = request.get_json(force=True)
     if idea_title_exists(json_data['title']):
         idea_ns.abort(409, "Idea already exists")
     edit_idea_by_json(idea_id, json_data)
     return '', 204
Ejemplo n.º 3
0
def show_idea(idea_title):
    if not current_user.is_authenticated:
        return redirect(url_for('login'))
    if not idea_title_exists(idea_title):
        abort(404)
    show_all = True
    idea = get_idea_by_title(idea_title)
    if current_user.id != idea.author.id:
        show_all = False
    upvote = False
    downvote = False
    if vote_exists(current_user.id, idea.id):
        vote = get_vote(current_user.id, idea.id)
        upvote = vote.value == 1
        downvote = vote.value == -1
    return render_template('idea/show_idea.html',
                           title='Edit Idea',
                           idea=idea,
                           show_all=show_all,
                           upvote=upvote,
                           downvote=downvote)
Ejemplo n.º 4
0
def edit_idea(idea_title):
    if not current_user.is_authenticated:
        return redirect(url_for('login'))
    if not idea_title_exists(idea_title):
        abort(404)
    idea_to_edit = get_idea_by_title(idea_title)
    if current_user.id != idea_to_edit.author.id:
        abort(403)
    form = EditIdeaForm(title=idea_to_edit.title,
                        description=idea_to_edit.description,
                        category=idea_to_edit.category,
                        tags=idea_to_edit.tags)
    if form.validate_on_submit():
        if request.method == 'POST':
            edit_idea_by_form(idea_to_edit.id, form)
            flash('Your idea has been edited!', 'info')
            return redirect(url_for('show_idea',
                                    idea_title=idea_to_edit.title))
    return render_template('idea/edit-idea.html',
                           title='Edit Idea',
                           form=form,
                           idea=idea_to_edit)
Ejemplo n.º 5
0
 def validate_title(self, title):
     if idea_title_exists(title.data):
         raise ValidationError('This idea already exists!')
Ejemplo n.º 6
0
 def test_idea_title_exists(self):
     self.addTestModels()
     self.assertTrue(idea_title_exists(self.testIdea.title))
     self.assertFalse(idea_title_exists('Some Idea Title'))