diff --git a/pagure/templates/new_issue.html b/pagure/templates/new_issue.html
index e03f36f..54dd49c 100644
--- a/pagure/templates/new_issue.html
+++ b/pagure/templates/new_issue.html
@@ -150,19 +150,14 @@
{% if authenticated and form %}
$(document).ready(function() {
// Set up the handler for the file input box.
- $("#file-picker").on("change", function() {
+ $("#file-picker").on("change", function(evt) {
+ var files = evt.target.files;
//doUpload("{{ form.csrf_token.current_token }}", this.files);
var _txt = $("#issue_content").val();
if (_txt) {
_txt += '\n';
}
- var _loc = "{{ url_for('view_issue_raw_file',
- repo=repo.name,
- username=username,
- namespace=repo.namespace,
- filename='') }}" + this.file;
-
- $("#issue_content").val(_txt + '');
+ $("#issue_content").val(_txt + '\n'.repeat(files.length));
});
// List username in @ drop-down
diff --git a/pagure/ui/issues.py b/pagure/ui/issues.py
index d7eaf13..76033a6 100644
--- a/pagure/ui/issues.py
+++ b/pagure/ui/issues.py
@@ -899,32 +899,38 @@ def new_issue(repo, username=None, namespace=None):
ticketfolder=APP.config['TICKETS_FOLDER'],
)
SESSION.commit()
+
# If there is a file attached, attach it.
- filestream = flask.request.files.get('filestream')
- if filestream and '' in issue.content:
- new_filename = pagure.lib.add_attachment(
- repo=repo,
- issue=issue,
- attachmentfolder=APP.config['ATTACHMENTS_FOLDER'],
- user=user_obj,
- filename=filestream.filename,
- filestream=filestream.stream,
- )
- # Replace the tag in the comment with the link
- # to the actual image
- filelocation = flask.url_for(
- 'view_issue_raw_file',
- repo=repo.name,
- username=username,
- namespace=repo.namespace,
- filename=new_filename,
- )
- new_filename = new_filename.split('-', 1)[1]
- url = '[](%s)' % (
- new_filename, filelocation, filelocation)
- issue.content = issue.content.replace('', url)
- SESSION.add(issue)
- SESSION.commit()
+ form = pagure.forms.UploadFileForm()
+ if form.validate_on_submit():
+ streams = flask.request.files.getlist('filestream')
+ n_img = issue.content.count('')
+ if n_img == len(streams):
+ for filestream in streams:
+ new_filename = pagure.lib.add_attachment(
+ repo=repo,
+ issue=issue,
+ attachmentfolder=APP.config['ATTACHMENTS_FOLDER'],
+ user=user_obj,
+ filename=filestream.filename,
+ filestream=filestream.stream,
+ )
+ # Replace the tag in the comment with the
+ # link to the actual image
+ filelocation = flask.url_for(
+ 'view_issue_raw_file',
+ repo=repo.name,
+ username=username,
+ namespace=repo.namespace,
+ filename=new_filename,
+ )
+ new_filename = new_filename.split('-', 1)[1]
+ url = '[](%s)' % (
+ new_filename, filelocation, filelocation)
+ issue.content = issue.content.replace(
+ '', url, 1)
+ SESSION.add(issue)
+ SESSION.commit()
return flask.redirect(flask.url_for(
'.view_issue', username=username, repo=repo.name,