From 7a68a3051808a68165b6bb341e8647912b88f2ac Mon Sep 17 00:00:00 2001
From: Loic Dachary <loic@dachary.org>
Date: Thu, 28 Jan 2016 15:10:03 +0700
Subject: [PATCH] Fix #928 - cleanup to avoid duplicated get_upload_file_limits
Signed-off-by: Loic Dachary <loic@dachary.org>
---
mediagoblin/gmg_commands/addmedia.py | 5 +----
mediagoblin/gmg_commands/batchaddmedia.py | 5 +----
mediagoblin/plugins/api/views.py | 3 ---
mediagoblin/plugins/piwigo/views.py | 5 +----
mediagoblin/submit/lib.py | 4 +---
mediagoblin/submit/views.py | 1 -
6 files changed, 4 insertions(+), 19 deletions(-)
diff --git a/mediagoblin/gmg_commands/addmedia.py b/mediagoblin/gmg_commands/addmedia.py
index 8cbfc80..9685d5a 100644
a
|
b
|
def addmedia(args):
|
85 | 85 | print("Can't find a file with filename '%s'" % args.filename) |
86 | 86 | return |
87 | 87 | |
88 | | upload_limit, max_file_size = get_upload_file_limits(user) |
89 | | |
90 | 88 | def maybe_unicodeify(some_string): |
91 | 89 | # this is kinda terrible |
92 | 90 | if some_string is None: |
… |
… |
def addmedia(args):
|
103 | 101 | title=maybe_unicodeify(args.title), |
104 | 102 | description=maybe_unicodeify(args.description), |
105 | 103 | license=maybe_unicodeify(args.license), |
106 | | tags_string=maybe_unicodeify(args.tags) or u"", |
107 | | upload_limit=upload_limit, max_file_size=max_file_size) |
| 104 | tags_string=maybe_unicodeify(args.tags) or u"") |
108 | 105 | except FileUploadLimit: |
109 | 106 | print("This file is larger than the upload limits for this site.") |
110 | 107 | except UserUploadLimit: |
diff --git a/mediagoblin/gmg_commands/batchaddmedia.py b/mediagoblin/gmg_commands/batchaddmedia.py
index 2ad7e39..274d72b 100644
a
|
b
|
def batchaddmedia(args):
|
73 | 73 | username=args.username))) |
74 | 74 | return |
75 | 75 | |
76 | | upload_limit, max_file_size = get_upload_file_limits(user) |
77 | 76 | temp_files = [] |
78 | 77 | |
79 | 78 | if os.path.isfile(args.metadata_path): |
… |
… |
def batchaddmedia(args):
|
87 | 86 | |
88 | 87 | abs_metadata_filename = os.path.abspath(metadata_path) |
89 | 88 | abs_metadata_dir = os.path.dirname(abs_metadata_filename) |
90 | | upload_limit, max_file_size = get_upload_file_limits(user) |
91 | 89 | |
92 | 90 | def maybe_unicodeify(some_string): |
93 | 91 | # this is kinda terrible |
… |
… |
FAIL: Local file {filename} could not be accessed.
|
159 | 157 | description=maybe_unicodeify(description), |
160 | 158 | license=maybe_unicodeify(license), |
161 | 159 | metadata=json_ld_metadata, |
162 | | tags_string=u"", |
163 | | upload_limit=upload_limit, max_file_size=max_file_size) |
| 160 | tags_string=u"") |
164 | 161 | print(_(u"""Successfully submitted {filename}! |
165 | 162 | Be sure to look at the Media Processing Panel on your website to be sure it |
166 | 163 | uploaded successfully.""".format(filename=filename))) |
diff --git a/mediagoblin/plugins/api/views.py b/mediagoblin/plugins/api/views.py
index 2334106..fdd22ac 100644
a
|
b
|
def post_entry(request):
|
52 | 52 | _log.debug('File field not found') |
53 | 53 | raise BadRequest() |
54 | 54 | |
55 | | upload_limit, max_file_size = get_upload_file_limits(request.user) |
56 | | |
57 | 55 | callback_url = request.form.get('callback_url') |
58 | 56 | if callback_url: |
59 | 57 | callback_url = six.text_type(callback_url) |
… |
… |
def post_entry(request):
|
66 | 64 | description=six.text_type(request.form.get('description')), |
67 | 65 | license=six.text_type(request.form.get('license', '')), |
68 | 66 | tags_string=six.text_type(request.form.get('tags', '')), |
69 | | upload_limit=upload_limit, max_file_size=max_file_size, |
70 | 67 | callback_url=callback_url) |
71 | 68 | |
72 | 69 | return json_response(get_entry_serializable(entry, request.urlgen)) |
diff --git a/mediagoblin/plugins/piwigo/views.py b/mediagoblin/plugins/piwigo/views.py
index ab741a7..30c7ffa 100644
a
|
b
|
def pwg_images_addSimple(request):
|
128 | 128 | if not check_file_field(request, 'image'): |
129 | 129 | raise BadRequest() |
130 | 130 | |
131 | | upload_limit, max_file_size = get_upload_file_limits(request.user) |
132 | | |
133 | 131 | try: |
134 | 132 | entry = submit_media( |
135 | 133 | mg_app=request.app, user=request.user, |
136 | 134 | submitted_file=request.files['image'], |
137 | 135 | filename=request.files['image'].filename, |
138 | 136 | title=six.text_type(form.name.data), |
139 | | description=six.text_type(form.comment.data), |
140 | | upload_limit=upload_limit, max_file_size=max_file_size) |
| 137 | description=six.text_type(form.comment.data)) |
141 | 138 | |
142 | 139 | collection_id = form.category.data |
143 | 140 | if collection_id > 0: |
diff --git a/mediagoblin/submit/lib.py b/mediagoblin/submit/lib.py
index 2edea70..4979def 100644
a
|
b
|
class UserPastUploadLimit(UploadLimitError):
|
103 | 103 | def submit_media(mg_app, user, submitted_file, filename, |
104 | 104 | title=None, description=None, |
105 | 105 | license=None, metadata=None, tags_string=u"", |
106 | | upload_limit=None, max_file_size=None, |
107 | 106 | callback_url=None, urlgen=None,): |
108 | 107 | """ |
109 | 108 | Args: |
… |
… |
def submit_media(mg_app, user, submitted_file, filename,
|
119 | 118 | - license: license for this media entry |
120 | 119 | - tags_string: comma separated string of tags to be associated |
121 | 120 | with this entry |
122 | | - upload_limit: size in megabytes that's the per-user upload limit |
123 | | - max_file_size: maximum size each file can be that's uploaded |
124 | 121 | - callback_url: possible post-hook to call after submission |
125 | 122 | - urlgen: if provided, used to do the feed_url update and assign a public |
126 | 123 | ID used in the API (very important). |
127 | 124 | """ |
| 125 | upload_limit, max_file_size = get_upload_file_limits(user) |
128 | 126 | if upload_limit and user.uploaded >= upload_limit: |
129 | 127 | raise UserPastUploadLimit() |
130 | 128 | |
diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py
index eb11dfe..6bbe61d 100644
a
|
b
|
def submit_start(request):
|
77 | 77 | description=six.text_type(submit_form.description.data), |
78 | 78 | license=six.text_type(submit_form.license.data) or None, |
79 | 79 | tags_string=submit_form.tags.data, |
80 | | upload_limit=upload_limit, max_file_size=max_file_size, |
81 | 80 | urlgen=request.urlgen) |
82 | 81 | |
83 | 82 | if submit_form.collection and submit_form.collection.data: |