From 556a8ed933f3ce574f2a1550b7a2f20bd61b97f5 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 26 2014 09:10:53 +0000 Subject: Simplify the issue related url Turns out we can use the same function for both projects and forks urls Signed-off-by: Pierre-Yves Chibon --- diff --git a/progit/issues.py b/progit/issues.py index 120bbb1..93ea5f7 100644 --- a/progit/issues.py +++ b/progit/issues.py @@ -26,49 +26,55 @@ import progit.forms from progit import APP, SESSION, LOG, __get_file_in_tree, cla_required -def do_new_issue(repo, username=None): - """ Create a new issue - """ +## URLs + +@APP.route('//issue//add', + methods=('GET','POST')) +@APP.route('/fork///issue//add', + methods=('GET', 'POST')) +def add_comment_issue(repo, issueid, username=None): + ''' Add a comment to an issue. ''' repo = progit.lib.get_project(SESSION, repo, user=username) if repo is None: flask.abort(404, 'Project not found') - form = progit.forms.IssueForm() + if not repo.issue_tracker: + flask.abort(404, 'No issue tracker found for this project') + + issue = progit.lib.get_issue(SESSION, issueid) + + if issue is None: + flask.abort(404, 'Issue not found') + + form = progit.forms.AddIssueCommentForm() if form.validate_on_submit(): - title = form.title.data - content = form.content.data + comment = form.comment.data try: - message = progit.lib.new_issue( + message = progit.lib.add_issue_comment( SESSION, - repo=repo, - title=title, - content=content, + issue=issue, + comment=comment, user=flask.g.fas_user.username, ) SESSION.commit() flask.flash(message) - return flask.redirect(flask.url_for( - 'view_fork_issues', username=username, repo=repo.name)) - except progit.exceptions.ProgitException, err: - flask.flash(str(err), 'error') except SQLAlchemyError, err: # pragma: no cover SESSION.rollback() flask.flash(str(err), 'error') - return flask.render_template( - 'new_issue.html', - select='issues', - form=form, - repo=repo, - username=username, - ) + return flask.redirect(flask.url_for( + 'view_issue', username=username, repo=repo.name, issueid=issue.id)) -def do_edit_issue(repo, issueid, username=None): - """ Edit the specified issue +@APP.route('//issues') +@APP.route('/fork///issues') +def view_issues(repo, username=None): + """ List all issues associated to a repo """ + status = flask.request.args.get('status', None) + repo = progit.lib.get_project(SESSION, repo, user=username) if repo is None: @@ -77,57 +83,75 @@ def do_edit_issue(repo, issueid, username=None): if not repo.issue_tracker: flask.abort(404, 'No issue tracker found for this project') - issue = progit.lib.get_issue(SESSION, issueid) + if status is not None: + if status.lower() == 'closed': + issues = progit.lib.get_issues(SESSION, repo, closed=True) + else: + issues = progit.lib.get_issues(SESSION, repo, status=status) + else: + issues = progit.lib.get_issues(SESSION, repo, status='Open') - if issue is None: - flask.abort(404, 'Issue not found') + return flask.render_template( + 'issues.html', + select='issues', + repo=repo, + username=username, + status=status, + issues=issues, + ) - status = progit.lib.get_issue_statuses(SESSION) - form = progit.forms.IssueForm(status=status) + +@APP.route('//new_issue', methods=('GET', 'POST')) +@APP.route('/fork///new_issue', methods=('GET', 'POST')) +@cla_required +def new_issue(repo, username=None): + """ Create a new issue + """ + repo = progit.lib.get_project(SESSION, repo, user=username) + + if repo is None: + flask.abort(404, 'Project not found') + + form = progit.forms.IssueForm() if form.validate_on_submit(): title = form.title.data content = form.content.data - status = form.status.data try: - message = progit.lib.edit_issue( + message = progit.lib.new_issue( SESSION, - issue=issue, + repo=repo, title=title, content=content, - status=status, + user=flask.g.fas_user.username, ) SESSION.commit() flask.flash(message) - url = flask.url_for('view_issues', repo=repo.name) - if username: - url = flask.url_for( - 'view_fork_issues', username=username, repo=repo.name) - return flask.redirect(url) + return flask.redirect(flask.url_for( + 'view_fork_issues', username=username, repo=repo.name)) except progit.exceptions.ProgitException, err: flask.flash(str(err), 'error') except SQLAlchemyError, err: # pragma: no cover SESSION.rollback() flask.flash(str(err), 'error') - elif flask.request.method == 'GET': - form.title.data = issue.title - form.content.data = issue.content - form.status.data = issue.status return flask.render_template( 'new_issue.html', select='issues', - type='edit', form=form, repo=repo, username=username, - issue=issue, ) -def do_view_issue(repo, issueid, username=None): +@APP.route('//issue/', methods=('GET', 'POST')) +@APP.route('/fork///issue/', + methods=('GET', 'POST')) +@cla_required +def view_issue(repo, issueid, username=None): """ List all issues associated to a repo """ + repo = progit.lib.get_project(SESSION, repo, user=username) if repo is None: @@ -174,43 +198,13 @@ def do_view_issue(repo, issueid, username=None): ) -def do_view_issues(repo, username=None, status=None): - """ List all issues associated to a repo - """ - repo = progit.lib.get_project(SESSION, repo, user=username) - - if repo is None: - flask.abort(404, 'Project not found') - - if not repo.issue_tracker: - flask.abort(404, 'No issue tracker found for this project') - - if status is not None: - if status.lower() == 'closed': - issues = progit.lib.get_issues(SESSION, repo, closed=True) - else: - issues = progit.lib.get_issues(SESSION, repo, status=status) - else: - issues = progit.lib.get_issues(SESSION, repo, status='Open') - - return flask.render_template( - 'issues.html', - select='issues', - repo=repo, - username=username, - status=status, - issues=issues, - ) - - -## URLs - -@APP.route('//issue//add', - methods=('GET','POST')) -@APP.route('/fork///issue//add', +@APP.route('//issue//edit', methods=('GET', 'POST')) +@APP.route('/fork///issue//edit', methods=('GET', 'POST')) -def add_comment_issue(repo, issueid, username=None): - ''' Add a comment to an issue. ''' +@cla_required +def edit_issue(repo, issueid, username=None): + """ Edit the specified issue + """ repo = progit.lib.get_project(SESSION, repo, user=username) if repo is None: @@ -224,89 +218,43 @@ def add_comment_issue(repo, issueid, username=None): if issue is None: flask.abort(404, 'Issue not found') - form = progit.forms.AddIssueCommentForm() + status = progit.lib.get_issue_statuses(SESSION) + form = progit.forms.IssueForm(status=status) if form.validate_on_submit(): - comment = form.comment.data + title = form.title.data + content = form.content.data + status = form.status.data try: - message = progit.lib.add_issue_comment( + message = progit.lib.edit_issue( SESSION, issue=issue, - comment=comment, - user=flask.g.fas_user.username, + title=title, + content=content, + status=status, ) SESSION.commit() flask.flash(message) + url = flask.url_for( + 'view_issue', username=username, + repo=repo.name, issueid=issue.id) + return flask.redirect(url) + except progit.exceptions.ProgitException, err: + flask.flash(str(err), 'error') except SQLAlchemyError, err: # pragma: no cover SESSION.rollback() flask.flash(str(err), 'error') + elif flask.request.method == 'GET': + form.title.data = issue.title + form.content.data = issue.content + form.status.data = issue.status - return flask.redirect(flask.url_for( - 'view_issue', username=username, repo=repo.name, issueid=issue.id)) - - -@APP.route('//issues') -def view_issues(repo): - """ List all issues associated to a repo - """ - status = flask.request.args.get('status', None) - return do_view_issues(repo, status=status) - - -@APP.route('/fork///issues') -def view_fork_issues(repo, username): - """ List all issues associated to a repo - """ - status = flask.request.args.get('status', None) - return do_view_issues(repo, username=username, status=status) - - -@APP.route('//new_issue', methods=('GET', 'POST')) -@cla_required -def new_issue(repo): - """ Create a new issue - """ - return do_new_issue(repo) - - -@APP.route('/fork///new_issue', methods=('GET', 'POST')) -@cla_required -def fork_new_issue(username, repo): - """ Create a new issue - """ - return do_new_issue(repo, username=username) - - -@APP.route('//issue/', methods=('GET', 'POST')) -@cla_required -def view_issue(repo, issueid): - """ List all issues associated to a repo - """ - return do_view_issue(repo, issueid) - - -@APP.route('/fork///issue/', - methods=('GET', 'POST')) -@cla_required -def view_fork_issue(username, repo, issueid): - """ List all issues associated to a repo - """ - return do_view_issue(repo, issueid, username=username) - - -@APP.route('//issue//edit', methods=('GET', 'POST')) -@cla_required -def edit_issue(repo, issueid): - """ Edit the specified issue - """ - return do_edit_issue(repo, issueid) - - -@APP.route('/fork///issue//edit', - methods=('GET', 'POST')) -@cla_required -def fork_edit_issue(username, repo, issueid): - """ Edit the specified issue opened against a fork - """ - return do_edit_issue(repo, issueid, username=username) - + return flask.render_template( + 'new_issue.html', + select='issues', + type='edit', + form=form, + repo=repo, + username=username, + issue=issue, + ) diff --git a/progit/templates/issue.html b/progit/templates/issue.html index da68bd4..85670e6 100644 --- a/progit/templates/issue.html +++ b/progit/templates/issue.html @@ -10,21 +10,12 @@

Issue #{{ issue.id }}

- {% if username %} -
- {% else %} - - {% endif %}
  • - {% if '/fork/' in request.url %} - - {% else %} - - {% endif %} Edit
  • {{ render_field_in_list(form.status) }} diff --git a/progit/templates/issues.html b/progit/templates/issues.html index ff9a6d5..4fe2877 100644 --- a/progit/templates/issues.html +++ b/progit/templates/issues.html @@ -14,31 +14,19 @@ Issues {% if status and status != 'Open' %} - {% if '/fork/' in request.url %} - - {% else %} - - {% endif %} - (Open) + + (Open) {% else %} - {% if '/fork/' in request.url %} - - {% else %} - - {% endif %} - (Closed) + + (Closed) {% endif %} - {% if '/fork/' in request.url %} - - {% else %} - - {% endif %} - + + @@ -48,13 +36,8 @@ {% for issue in issues %}
  • #{{ issue.id }} - {% if '/fork/' in request.url %} - - {% else %} - - {% endif %} {{ issue.title }} Opened by diff --git a/progit/templates/new_issue.html b/progit/templates/new_issue.html index 2476e03..eef44dd 100644 --- a/progit/templates/new_issue.html +++ b/progit/templates/new_issue.html @@ -16,21 +16,12 @@
    {% if not type or type == 'new' %} - {% if '/fork/' in request.url %} - - {% else %} - - {% endif %} + {% elif type and type == 'edit' %} - {% if '/fork/' in request.url %} - - {% else %} - - {% endif %} {% endif %} diff --git a/progit/templates/repo_master.html b/progit/templates/repo_master.html index a1c6ee1..7ca5fef 100644 --- a/progit/templates/repo_master.html +++ b/progit/templates/repo_master.html @@ -63,13 +63,8 @@ {% if repo.issue_tracker %}
  • - {% if '/fork/' in request.url %} - - {% else %} - - {% endif %} - Issues + Issues
  • {% endif %}