From 6caef4c9f0cb14426e4695abbca0c749cd7e7d03 Mon Sep 17 00:00:00 2001 From: Pradeep CE (cep) Date: Jan 17 2017 19:02:42 +0000 Subject: Add Description for Tags --- diff --git a/pagure/forms.py b/pagure/forms.py index 576896f..bb57357 100644 --- a/pagure/forms.py +++ b/pagure/forms.py @@ -239,6 +239,10 @@ class DeleteIssueTagForm(PagureForm): class AddIssueTagForm(DeleteIssueTagForm): ''' Form to add a tag to a project. ''' + tag_description = wtforms.TextField( + 'tag_description', + [wtforms.validators.Optional()], + ) tag_color = wtforms.TextField( 'tag_color', [wtforms.validators.Required()], @@ -634,4 +638,3 @@ class SubscribtionForm(PagureForm): [wtforms.validators.optional()], false_values=('false', '', False, 'False', 0, '0'), ) - diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index 65c61bf..09b95f9 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -736,7 +736,7 @@ def remove_tags_obj(session, obj, tags, ticketfolder, user): def edit_issue_tags( - session, project, old_tag, new_tag, + session, project, old_tag, new_tag, new_tag_description, new_tag_color, ticketfolder, user): ''' Removes the specified tag of a project. ''' user_obj = get_user(session, user) @@ -750,12 +750,18 @@ def edit_issue_tags( 'No tag "%s" found related to this project' % (old_tag_name)) old_tag_name = old_tag.tag + old_tag_description = old_tag.tag_description old_tag_color = old_tag.tag_color - if old_tag.tag == new_tag and old_tag_color == new_tag_color: - # check for change + + # check for change + no_change_in_tag = old_tag.tag == new_tag and \ + old_tag_description == new_tag_description and \ + old_tag_color == new_tag_color + if no_change_in_tag: raise pagure.exceptions.PagureException( - 'No change. Old tag "%s(%s)" is the same as new tag "%s(%s)"' - % (old_tag, old_tag_color, new_tag, new_tag_color)) + 'No change. Old tag "%s(%s)[%s]" is the same as new tag "%s(%s)[%s]"' + % (old_tag, old_tag_description, old_tag_color, new_tag, + new_tag_description, new_tag_color)) elif old_tag.tag != new_tag: # Check if new tag already exists existing_tag = get_tag(session, new_tag, project.id) @@ -772,6 +778,7 @@ def edit_issue_tags( ).update( { model.TagColored.tag: new_tag, + model.TagColored.tag_description: new_tag_description, model.TagColored.tag_color: new_tag_color } ) @@ -789,16 +796,19 @@ def edit_issue_tags( issue, repo=issue.project, repofolder=ticketfolder) msgs = [] - msgs.append('Edited tag: %s(%s) to %s(%s)' % - (old_tag_name, old_tag_color, new_tag, new_tag_color)) + msgs.append('Edited tag: %s(%s)[%s] to %s(%s)[%s]' % + (old_tag_name, old_tag_description, old_tag_color, + new_tag, new_tag_description, new_tag_color)) pagure.lib.notify.log( project, topic='project.tag.edited', msg=dict( project=project.to_json(public=True), old_tag=old_tag.tag, + old_tag_description=old_tag_description, old_tag_color=old_tag_color, new_tag=new_tag, + new_tag_description=new_tag_description, new_tag_color=new_tag_color, agent=user_obj.username, ), @@ -1372,10 +1382,11 @@ def new_pull_request(session, branch_from, return request -def new_tag(session, tag_name, tag_color, project_id): +def new_tag(session, tag_name, tag_description, tag_color, project_id): ''' Return a new tag object ''' tagobj = model.TagColored( tag=tag_name, + tag_description=tag_description, tag_color=tag_color, project_id=project_id ) diff --git a/pagure/lib/model.py b/pagure/lib/model.py index 34d4aff..e532d6d 100644 --- a/pagure/lib/model.py +++ b/pagure/lib/model.py @@ -1089,6 +1089,7 @@ class TagColored(BASE): id = sa.Column(sa.Integer, primary_key=True) tag = sa.Column(sa.String(255), nullable=False) + tag_description = sa.Column(sa.String(255)) project_id = sa.Column( sa.Integer, sa.ForeignKey( diff --git a/pagure/templates/edit_tag.html b/pagure/templates/edit_tag.html index 6775017..5789cfa 100644 --- a/pagure/templates/edit_tag.html +++ b/pagure/templates/edit_tag.html @@ -23,6 +23,7 @@ namespace=repo.namespace) }}" > {{ form.csrf_token }} {{ render_bootstrap_field(form.tag) }} + {{ render_bootstrap_field(form.tag_description) }}
{% set formclasses = "form-control c-select"%} {% if form.tag_color.errors %} {% set formclasses = formclasses + " form-control-error" %} {% endif %} diff --git a/pagure/templates/issue.html b/pagure/templates/issue.html index 4e5a186..56120fa 100644 --- a/pagure/templates/issue.html +++ b/pagure/templates/issue.html @@ -159,7 +159,7 @@

{% for tag in issue.tags %} -   {{ tag.tag }}  {{tag.tag}} +  {{ tag.tag_description }}
\ -
\ +
\ New Tag\
\
\ + Description\ +
\ +
\ Tag Color\
\
'); @@ -1014,11 +1018,15 @@ $('#new_tag').click(function(e) { } $('#tagcolor').append( '
\ -
\ +
\ \
\
\ + \ +
\ +
\ \
\ diff --git a/pagure/ui/issues.py b/pagure/ui/issues.py index 631f579..8ccb272 100644 --- a/pagure/ui/issues.py +++ b/pagure/ui/issues.py @@ -392,6 +392,7 @@ def edit_tag(repo, tag, username=None, namespace=None): form = pagure.forms.AddIssueTagForm() if form.validate_on_submit(): new_tag = form.tag.data + new_tag_description = form.tag_description.data new_tag_color = form.tag_color.data msgs = pagure.lib.edit_issue_tags( @@ -399,6 +400,7 @@ def edit_tag(repo, tag, username=None, namespace=None): repo, tagobj, new_tag, + new_tag_description, new_tag_color, user=flask.g.fas_user.username, ticketfolder=APP.config['TICKETS_FOLDER'] @@ -418,6 +420,7 @@ def edit_tag(repo, tag, username=None, namespace=None): namespace=repo.namespace)) elif flask.request.method == 'GET': form.tag_color.data = tagobj.tag_color + form.tag_description.data = tagobj.tag_description form.tag.data = tag return flask.render_template( @@ -457,6 +460,14 @@ def update_tags(repo, username=None, namespace=None): for tag in flask.request.form.getlist('tag') if tag.strip() and tag.strip() not in seen and not seen.add(tag.strip()) ] + + seen = set() + tag_descriptions = [ + desc.strip() + for desc in flask.request.form.getlist('tag_description') + if desc.strip() and desc.strip() not in seen and not seen.add(desc.strip()) + ] + # Uniquify and order preserving seen = set() colors = [