From e8b9d042c5603c8e65daa71aabd37907d489be60 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Apr 12 2016 08:58:22 +0000 Subject: [PATCH 1/25] Store project's priorities and the priority status of issues --- diff --git a/pagure/lib/model.py b/pagure/lib/model.py index 50fd549..b316b5a 100644 --- a/pagure/lib/model.py +++ b/pagure/lib/model.py @@ -284,6 +284,7 @@ class Project(BASE): sa.Integer, sa.ForeignKey('projects.id', onupdate='CASCADE'), nullable=True) + _priorities = sa.Column(sa.Text, nullable=True) date_created = sa.Column(sa.DateTime, nullable=False, default=datetime.datetime.utcnow) @@ -369,6 +370,23 @@ class Project(BASE): self._settings = json.dumps(settings) @property + def priorities(self): + """ Return the dict stored as string in the database as an actual + dict object. + """ + priorities = {} + + if self._priorities: + priorities = json.loads(self._priorities) + + return priorities + + @priorities.setter + def priorities(self, priorities): + ''' Ensures the priorities are properly saved. ''' + self._priorities = json.dumps(priorities) + + @property def open_requests(self): ''' Returns the number of open pull-requests for this project. ''' return BASE.metadata.bind.query( @@ -485,6 +503,7 @@ class Issue(BASE): default='Open', nullable=False) private = sa.Column(sa.Boolean, nullable=False, default=False) + priority = sa.Column(sa.Integer, nullable=True, default=None) date_created = sa.Column(sa.DateTime, nullable=False, default=datetime.datetime.utcnow) From 36fb65be1cd9f4c2cd02c8fa4dfd1d110b075396 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Apr 12 2016 08:58:22 +0000 Subject: [PATCH 2/25] Add an alembic migration file for storing the priorities --- diff --git a/alembic/versions/496f7a700f2e_add_priorities.py b/alembic/versions/496f7a700f2e_add_priorities.py new file mode 100644 index 0000000..21c7ca7 --- /dev/null +++ b/alembic/versions/496f7a700f2e_add_priorities.py @@ -0,0 +1,37 @@ +"""Add priorities + +Revision ID: 496f7a700f2e +Revises: 4cae55a80a42 +Create Date: 2016-03-24 12:19:34.298752 + +""" + +# revision identifiers, used by Alembic. +revision = '496f7a700f2e' +down_revision = '4cae55a80a42' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + ''' Add the column _priorities to the table projects + and the column priority to the table issues. + ''' + op.add_column( + 'projects', + sa.Column('_priorities', sa.Text, nullable=True) + ) + + op.add_column( + 'issues', + sa.Column('priority', sa.Integer, nullable=True, default=None) + ) + + +def downgrade(): + ''' Drop the column _priorities from the table projects + and the column priority from the table issues. + ''' + op.drop_column('projects', '_priorities') + op.drop_column('issues', 'priority') From 123c2d36f18a22ddc5103eca8b5bbb7aff9a3872 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Apr 12 2016 08:58:22 +0000 Subject: [PATCH 3/25] Allow adjusting the priority when editing an issue --- diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index a680848..c319cea 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -1156,7 +1156,8 @@ def new_pull_request(session, branch_from, def edit_issue(session, issue, ticketfolder, user, - title=None, content=None, status=None, private=False): + title=None, content=None, status=None, + priority=None, private=False): ''' Edit the specified issue. ''' user_obj = __get_user(session, user) @@ -1178,6 +1179,9 @@ def edit_issue(session, issue, ticketfolder, user, if status and status != issue.status: issue.status = status edit.append('status') + if priority and priority != issue.priority: + issue.priority = priority + edit.append('priority') if private in [True, False] and private != issue.private: issue.private = private edit.append('private') From 8d019f9e3ab2b23949b76c0848168e42d21f95f4 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Apr 12 2016 08:58:22 +0000 Subject: [PATCH 4/25] Allow filtering by priorities when searching issues --- diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index c319cea..7d7689f 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -1503,6 +1503,7 @@ def get_project(session, name, user=None): def search_issues( session, repo, issueid=None, issueuid=None, status=None, closed=False, tags=None, assignee=None, author=None, private=None, + priority=None, count=False): ''' Retrieve one or more issues associated to a project with the given criterias. @@ -1542,6 +1543,8 @@ def search_issues( If user name is specified: private tickets reported by that user are included. :type private: False, None or str + :kwarg priority: the priority of the issues to search + :type priority: int or None :kwarg count: a boolean to specify if the method should return the list of Issues or just do a COUNT query. :type count: boolean @@ -1575,6 +1578,10 @@ def search_issues( query = query.filter( model.Issue.status != 'Open' ) + if priority: + query = query.filter( + model.Issue.priority == priority + ) if tags is not None and tags != []: if isinstance(tags, basestring): tags = [tags] From ca0eec172bc7af607a0e0d8f8194ca33d60589fe Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Apr 12 2016 08:58:22 +0000 Subject: [PATCH 5/25] Add new endpoint saving the project's priorities in the settings' page --- diff --git a/pagure/templates/settings.html b/pagure/templates/settings.html index 929c2ce..b9d11e0 100644 --- a/pagure/templates/settings.html +++ b/pagure/templates/settings.html @@ -278,7 +278,7 @@ add group

- +