From e24ada56e1790d307d4ab04ce22e33fcfef28e70 Mon Sep 17 00:00:00 2001 From: Mark Reynolds Date: Dec 15 2016 14:29:50 +0000 Subject: [PATCH 1/7] Issue 1645 - Apply suggested changes: - Use jinja comments instead html comment in _formhelper.html - Remove "Goto" from comment link - Use None instead of "" for the commit id of the initial description --- diff --git a/pagure/lib/model.py b/pagure/lib/model.py index 73b7b7e..c44b604 100644 --- a/pagure/lib/model.py +++ b/pagure/lib/model.py @@ -751,7 +751,7 @@ class Issue(BASE): link, filename, display_name = extract_info(line) attachments.append( (link, filename, display_name, - self.date_created.strftime('%Y-%m-%d %H:%M:%S'), "")) + self.date_created.strftime('%Y-%m-%d %H:%M:%S'), None)) if self.comments: # Check the comments for attachments for comment in self.comments: diff --git a/pagure/templates/_formhelper.html b/pagure/templates/_formhelper.html index c612eff..dc770c9 100644 --- a/pagure/templates/_formhelper.html +++ b/pagure/templates/_formhelper.html @@ -219,15 +219,16 @@
{% for attachment in attachments %} - + {# attachment[0] = link + attachment[1] = file name + attachment[2] = display name + attachment[3] = date + attachment[4] = comment id + #} {{ attachment[2] }} - {{ attachment[3] }} - {% if attachment[4] != "" %} - Goto Comment + {% if attachment[4] is not None %} + {% else %} From Issue description {% endif %} From 874d7827427b6c4fd39d62ce8479b90f5b56189f Mon Sep 17 00:00:00 2001 From: Mark Reynolds Date: Dec 15 2016 15:19:05 +0000 Subject: [PATCH 2/7] Issue 1645 - fix jinja error --- diff --git a/pagure/templates/_formhelper.html b/pagure/templates/_formhelper.html index dc770c9..1505b76 100644 --- a/pagure/templates/_formhelper.html +++ b/pagure/templates/_formhelper.html @@ -227,7 +227,7 @@ #} {{ attachment[2] }} - {{ attachment[3] }} - {% if attachment[4] is not None %} + {% if attachment[4] is not none %} {% else %} From Issue description From 4c8ab17fe1af0410ba7562c291094a2cfbab51f6 Mon Sep 17 00:00:00 2001 From: Mark Reynolds Date: Dec 15 2016 15:50:01 +0000 Subject: [PATCH 3/7] Issue 1645 - Attachments should be downloadable This fix adds a download button, and truncates the attachement file name if it's too long. https://pagure.io/pagure/issue/1645 --- diff --git a/pagure/lib/model.py b/pagure/lib/model.py index f7cfbac..73b7b7e 100644 --- a/pagure/lib/model.py +++ b/pagure/lib/model.py @@ -715,19 +715,32 @@ class Issue(BASE): @property def attachments(self): - ''' Return a list of attachment tuples: (LINK, DATE, COMMENT_ID) ''' + ''' Return a list of attachment tuples: (LINK, FILENAME, DISPLAY_NAME, + DATE) ''' + + def extract_info(text): + ''' Return a tuple containing the link, file name, and the + "display" file name from the markdown attachment link ''' + pattern_md = re.compile('^\[\!(.*)\]') + pattern_link = re.compile('\(([^)]+)\)') + pattern_file = re.compile('\[([^]]+)\]') - def extract_md_link(text): - pattern = re.compile('^\[\!(.*)\]') try: - result = pattern.search(text).group(1) - if result is None: + md_link = pattern_md.search(text).group(1) + link = pattern_link.search(md_link).group(1) + filename = pattern_file.search(md_link).group(1) + if md_link is None or link is None or filename is None: # No match, return the original string - result = text + return (text, text, text) + if len(filename) > 50: + # File name is too long to display, truncate it. + display_name = filename[:50] + "..." + else: + display_name = filename except: # Search failed, return the original string - result = text - return result + return (text, text, text) + return (link, filename, display_name) attachments = [] if self.content: @@ -735,10 +748,10 @@ class Issue(BASE): lines = self.content.split('\n') for line in lines: if line and line != "" and line.startswith("[!["): - link = extract_md_link(line) + link, filename, display_name = extract_info(line) attachments.append( - (link, self.date_created.strftime('%Y-%m-%d %H:%M:%S'), - "")) + (link, filename, display_name, + self.date_created.strftime('%Y-%m-%d %H:%M:%S'), "")) if self.comments: # Check the comments for attachments for comment in self.comments: @@ -749,9 +762,9 @@ class Issue(BASE): lines = comment_text.split('\n') for line in lines: if line and line != "" and line.startswith("[!["): - link = extract_md_link(line) + link, filename, display_name = extract_info(line) attachments.append( - (link, + (link, filename, display_name, comment.date_created.strftime('%Y-%m-%d %H:%M:%S'), str(comment.id))) return attachments diff --git a/pagure/templates/_formhelper.html b/pagure/templates/_formhelper.html index 8f73a3c..c612eff 100644 --- a/pagure/templates/_formhelper.html +++ b/pagure/templates/_formhelper.html @@ -219,14 +219,23 @@ From 5300badb90ff65da7b80f503632b87d6298cc447 Mon Sep 17 00:00:00 2001 From: Mark Reynolds Date: Dec 15 2016 15:50:01 +0000 Subject: [PATCH 4/7] Issue 1645 - Apply suggested changes: - Use jinja comments instead html comment in _formhelper.html - Remove "Goto" from comment link - Use None instead of "" for the commit id of the initial description --- diff --git a/pagure/lib/model.py b/pagure/lib/model.py index 73b7b7e..c44b604 100644 --- a/pagure/lib/model.py +++ b/pagure/lib/model.py @@ -751,7 +751,7 @@ class Issue(BASE): link, filename, display_name = extract_info(line) attachments.append( (link, filename, display_name, - self.date_created.strftime('%Y-%m-%d %H:%M:%S'), "")) + self.date_created.strftime('%Y-%m-%d %H:%M:%S'), None)) if self.comments: # Check the comments for attachments for comment in self.comments: diff --git a/pagure/templates/_formhelper.html b/pagure/templates/_formhelper.html index c612eff..dc770c9 100644 --- a/pagure/templates/_formhelper.html +++ b/pagure/templates/_formhelper.html @@ -219,15 +219,16 @@
{% for attachment in attachments %} - + {# attachment[0] = link + attachment[1] = file name + attachment[2] = display name + attachment[3] = date + attachment[4] = comment id + #} {{ attachment[2] }} - {{ attachment[3] }} - {% if attachment[4] != "" %} - Goto Comment + {% if attachment[4] is not None %} + {% else %} From Issue description {% endif %} From d29de26650a09768eae9d15cd011653820a2002a Mon Sep 17 00:00:00 2001 From: Mark Reynolds Date: Dec 15 2016 15:50:01 +0000 Subject: [PATCH 5/7] Issue 1645 - fix jinja error --- diff --git a/pagure/templates/_formhelper.html b/pagure/templates/_formhelper.html index dc770c9..1505b76 100644 --- a/pagure/templates/_formhelper.html +++ b/pagure/templates/_formhelper.html @@ -227,7 +227,7 @@ #} {{ attachment[2] }} - {{ attachment[3] }} - {% if attachment[4] is not None %} + {% if attachment[4] is not none %} {% else %} From Issue description From 40df4c97ae5e7d6b919883ceb7dfd7efed240fa9 Mon Sep 17 00:00:00 2001 From: Mark Reynolds Date: Dec 15 2016 19:37:50 +0000 Subject: [PATCH 7/7] Issue 1645 - Fix html typo --- diff --git a/pagure/templates/_formhelper.html b/pagure/templates/_formhelper.html index 1505b76..0a548f5 100644 --- a/pagure/templates/_formhelper.html +++ b/pagure/templates/_formhelper.html @@ -228,7 +228,7 @@ {{ attachment[2] }} - {{ attachment[3] }} {% if attachment[4] is not none %} - + Comment {% else %} From Issue description {% endif %} diff --git a/pagure/ui/issues.py b/pagure/ui/issues.py index 3e0f94d..d5da2ae 100644 --- a/pagure/ui/issues.py +++ b/pagure/ui/issues.py @@ -16,6 +16,7 @@ import flask import os +import datetime from collections import defaultdict from math import ceil