From 1e08620981c55670a25c241a674eda902bdaf0e9 Mon Sep 17 00:00:00 2001 From: Vibhor Verma Date: Feb 21 2017 18:15:20 +0000 Subject: [PATCH 1/3] fix spelling errors and pep8 errors --- diff --git a/pagure/lib/git.py b/pagure/lib/git.py index 6156f9e..5065de5 100644 --- a/pagure/lib/git.py +++ b/pagure/lib/git.py @@ -379,7 +379,7 @@ def get_project_from_json( session, jsondata, gitfolder, docfolder, ticketfolder, requestfolder): """ From the given json blob, retrieve the project info and search for - it in the db and create the projec if it does not already exist. + it in the db and create the project if it does not already exist. """ project = None @@ -1441,7 +1441,7 @@ def diff_pull_request( def get_git_tags(project): - """ Returns the list of tags created in the git repositorie of the + """ Returns the list of tags created in the git repository of the specified project. """ repopath = pagure.get_repo_path(project) @@ -1458,7 +1458,7 @@ def get_git_tags(project): def get_git_tags_objects(project): """ Returns the list of references of the tags created in the git - repositorie the specified project. + repository the specified project. The list is sorted using the time of the commit associated to the tag """ repopath = pagure.get_repo_path(project) repo_obj = PagureRepo(repopath) diff --git a/pagure/templates/issue.html b/pagure/templates/issue.html index f2669da..47a731f 100644 --- a/pagure/templates/issue.html +++ b/pagure/templates/issue.html @@ -45,7 +45,7 @@ {% endif %}
- {{ show_initial_comment(issue, username, repo,issueid, form) }} + {{ show_initial_comment(issue, username, repo, issueid, form) }} {% if attachments %}
From cfb0b3af23a9e3fdf27b6c3da5bd1878408875c6 Mon Sep 17 00:00:00 2001 From: Vibhor Verma Date: Feb 21 2017 18:15:20 +0000 Subject: [PATCH 2/3] fix uploaded file view as image --- diff --git a/pagure/api/issue.py b/pagure/api/issue.py index 25bcce2..db28d63 100644 --- a/pagure/api/issue.py +++ b/pagure/api/issue.py @@ -10,6 +10,7 @@ import flask import datetime +import mimetypes from sqlalchemy.exc import SQLAlchemyError @@ -153,8 +154,13 @@ def api_new_issue(repo, username=None, namespace=None): filename=new_filename, ) new_filename = new_filename.split('-', 1)[1] - url = '[![%s](%s)](%s)' % ( - new_filename, filelocation, filelocation) + filetype = mimetypes.MimeTypes().guess_type(new_filename)[0] + if filetype is not None and filetype[0:5] == 'image': + url = '[![%s](%s)](%s)' % ( + new_filename, filelocation, filelocation) + else: + url = '[%s](%s)' % ( + new_filename, filelocation) issue.content = issue.content.replace('', url) SESSION.add(issue) SESSION.flush() diff --git a/pagure/static/upload.js b/pagure/static/upload.js index 387669b..106dc8e 100644 --- a/pagure/static/upload.js +++ b/pagure/static/upload.js @@ -70,8 +70,7 @@ function doUpload(csrf_token, files) { } $("#comment").val( _txt - + '[![' + data.filename + '](' + data.filelocation + ')](' - + data.filelocation + ')' + + data.url ) } setTimeout( diff --git a/pagure/templates/issue.html b/pagure/templates/issue.html index 47a731f..4dd65ae 100644 --- a/pagure/templates/issue.html +++ b/pagure/templates/issue.html @@ -98,8 +98,7 @@ Select files OR drag them into the comment field above. - + - Attach file + Attach file

{% if not type or type == 'new' %} diff --git a/pagure/ui/issues.py b/pagure/ui/issues.py index b33a7be..f08a85b 100644 --- a/pagure/ui/issues.py +++ b/pagure/ui/issues.py @@ -912,8 +912,13 @@ def new_issue(repo, username=None, namespace=None): filename=new_filename, ) new_filename = new_filename.split('-', 1)[1] - url = '[![%s](%s)](%s)' % ( - new_filename, filelocation, filelocation) + filetype = mimetypes.MimeTypes().guess_type(new_filename)[0] + if filetype is not None and filetype[0:5] == 'image': + url = '[![%s](%s)](%s)' % ( + new_filename, filelocation, filelocation) + else: + url = '[%s](%s)' % ( + new_filename, filelocation) issue.content = issue.content.replace('', url) SESSION.add(issue) SESSION.commit() @@ -1178,8 +1183,13 @@ def edit_issue(repo, issueid, username=None, namespace=None): filename=new_filename, ) new_filename = new_filename.split('-', 1)[1] - url = '[![%s](%s)](%s)' % ( - new_filename, filelocation, filelocation) + filetype = mimetypes.MimeTypes().guess_type(new_filename)[0] + if filetype is not None and filetype[0:5] == 'image': + url = '[![%s](%s)](%s)' % ( + new_filename, filelocation, filelocation) + else: + url = '[%s](%s)' % ( + new_filename, filelocation) issue.content = issue.content.replace('', url) SESSION.add(issue) SESSION.commit() @@ -1261,23 +1271,30 @@ def upload_issue(repo, issueid, username=None, namespace=None): filename=filestream.filename, filestream=filestream.stream, ) + filelocation = flask.url_for( + 'view_issue_raw_file', + repo=repo.name, + username=username, + namespace=repo.namespace, + filename=new_filename, + ) except filelock.Timeout as err: # pragma: no cover SESSION.rollback() APP.logger.exception(err) flask.flash( 'We could not save all the info, please try again', 'error') - + new_filename = new_filename.split('-', 1)[1] + filetype = mimetypes.MimeTypes().guess_type(new_filename)[0] + if filetype is not None and filetype[0:5] == 'image': + url = '[![%s](%s)](%s)' % ( + new_filename, filelocation, filelocation) + else: + url = '[%s](%s)' % ( + new_filename, filelocation) return flask.jsonify({ 'output': 'ok', - 'filename': new_filename.split('-', 1)[1], - 'filelocation': flask.url_for( - 'view_issue_raw_file', - repo=repo.name, - username=username, - namespace=repo.namespace, - filename=new_filename, - ) + 'url': url }) else: return flask.jsonify({'output': 'notok'}) From b006ef2c9a135ad76fb523c753c4cfe14560546d Mon Sep 17 00:00:00 2001 From: Vibhor Verma Date: Feb 21 2017 18:15:20 +0000 Subject: [PATCH 3/3] replace mimetypes with binaryornot methods --- diff --git a/pagure/api/issue.py b/pagure/api/issue.py index db28d63..875b3ae 100644 --- a/pagure/api/issue.py +++ b/pagure/api/issue.py @@ -10,7 +10,6 @@ import flask import datetime -import mimetypes from sqlalchemy.exc import SQLAlchemyError @@ -137,6 +136,7 @@ def api_new_issue(repo, username=None, namespace=None): # If there is a file attached, attach it. filestream = flask.request.files.get('filestream') if filestream and '' in issue.content: + file_blob = filestream.stream.read(1024) new_filename = pagure.lib.git.add_file_to_git( repo=repo, issue=issue, @@ -154,8 +154,8 @@ def api_new_issue(repo, username=None, namespace=None): filename=new_filename, ) new_filename = new_filename.split('-', 1)[1] - filetype = mimetypes.MimeTypes().guess_type(new_filename)[0] - if filetype is not None and filetype[0:5] == 'image': + filetype = is_binary_string(file_blob) + if filetype: url = '[![%s](%s)](%s)' % ( new_filename, filelocation, filelocation) else: diff --git a/pagure/ui/issues.py b/pagure/ui/issues.py index f08a85b..e210fdd 100644 --- a/pagure/ui/issues.py +++ b/pagure/ui/issues.py @@ -894,6 +894,7 @@ def new_issue(repo, username=None, namespace=None): # If there is a file attached, attach it. filestream = flask.request.files.get('filestream') if filestream and '' in issue.content: + file_blob = filestream.stream.read(1024) new_filename = pagure.lib.git.add_file_to_git( repo=repo, issue=issue, @@ -911,9 +912,9 @@ def new_issue(repo, username=None, namespace=None): namespace=repo.namespace, filename=new_filename, ) + filetype = is_binary_string(file_blob) new_filename = new_filename.split('-', 1)[1] - filetype = mimetypes.MimeTypes().guess_type(new_filename)[0] - if filetype is not None and filetype[0:5] == 'image': + if filetype: url = '[![%s](%s)](%s)' % ( new_filename, filelocation, filelocation) else: @@ -1165,6 +1166,7 @@ def edit_issue(repo, issueid, username=None, namespace=None): # If there is a file attached, attach it. filestream = flask.request.files.get('filestream') if filestream and '' in issue.content: + file_blob = filestream.stream.read(1024) new_filename = pagure.lib.git.add_file_to_git( repo=repo, issue=issue, @@ -1178,13 +1180,13 @@ def edit_issue(repo, issueid, username=None, namespace=None): filelocation = flask.url_for( 'view_issue_raw_file', repo=repo.name, - namespace=repo.namespace, username=username, + namespace=repo.namespace, filename=new_filename, ) + filetype = is_binary_string(file_blob) new_filename = new_filename.split('-', 1)[1] - filetype = mimetypes.MimeTypes().guess_type(new_filename)[0] - if filetype is not None and filetype[0:5] == 'image': + if filetype: url = '[![%s](%s)](%s)' % ( new_filename, filelocation, filelocation) else: @@ -1263,6 +1265,7 @@ def upload_issue(repo, issueid, username=None, namespace=None): if form.validate_on_submit(): filestream = flask.request.files['filestream'] try: + file_blob = filestream.stream.read(1024) new_filename = pagure.lib.git.add_file_to_git( repo=repo, issue=issue, @@ -1284,9 +1287,9 @@ def upload_issue(repo, issueid, username=None, namespace=None): flask.flash( 'We could not save all the info, please try again', 'error') + filetype = is_binary_string(file_blob) new_filename = new_filename.split('-', 1)[1] - filetype = mimetypes.MimeTypes().guess_type(new_filename)[0] - if filetype is not None and filetype[0:5] == 'image': + if filetype: url = '[![%s](%s)](%s)' % ( new_filename, filelocation, filelocation) else: