-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,17 +29,14 @@ def __init__(self, attrs=None): | |
| self.directory = attrs.get('directory', '') | ||
| self.extensions = attrs.get('extensions', '') | ||
| self.format = attrs.get('format', '') | ||
| if attrs is not None: | ||
| self.attrs = attrs.copy() | ||
| else: | ||
| self.attrs = {} | ||
| self.attrs = attrs.copy() if attrs is not None else {} | ||
|
|
||
| def render(self, name, value, attrs=None): | ||
| if value is None: | ||
| value = "" | ||
| directory = self.directory | ||
| if self.directory: | ||
| if callable(self.directory): | ||
| if directory: | ||
| if callable(directory): | ||
|
Comment on lines
-41
to
+39
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| directory = self.directory() | ||
| directory = os.path.normpath(datetime.datetime.now().strftime(directory)) | ||
| fullpath = os.path.join(get_directory(), directory) | ||
|
|
@@ -77,7 +74,7 @@ def clean(self, value): | |
| if value == '': | ||
| return value | ||
| file_extension = os.path.splitext(value)[1].lower().split("?")[0] | ||
| if self.extensions and not file_extension in self.extensions: | ||
| if self.extensions and file_extension not in self.extensions: | ||
|
Comment on lines
-80
to
+77
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| raise forms.ValidationError(self.error_messages['extension'] % {'ext': file_extension, 'allowed': ", ".join(self.extensions)}) | ||
| return value | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,10 +73,7 @@ def url_join(*args): | |
| """ | ||
| URL join routine. | ||
| """ | ||
| if args[0].startswith("http://"): | ||
| url = "http://" | ||
| else: | ||
| url = "/" | ||
| url = "http://" if args[0].startswith("http://") else "/" | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| for arg in args: | ||
| arg = str(arg).replace("\\", "/") | ||
| arg_split = arg.split("/") | ||
|
|
@@ -211,11 +208,7 @@ def convert_filename(value): | |
| v = re.sub(r'[^\w\s-]', '', v).strip() | ||
| normalized.append(v) | ||
|
|
||
| if len(normalized) > 1: | ||
| value = '.'.join(normalized) | ||
| else: | ||
| value = normalized[0] | ||
|
|
||
| value = '.'.join(normalized) if len(normalized) > 1 else normalized[0] | ||
|
Comment on lines
-214
to
+211
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| if CONVERT_FILENAME: | ||
| value = value.replace(" ", "_").lower() | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,9 +17,6 @@ def pagination(context): | |
| if not paginator.num_pages or paginator.num_pages == 1: | ||
| page_range = [] | ||
| else: | ||
| ON_EACH_SIDE = 3 | ||
| ON_ENDS = 2 | ||
|
|
||
|
Comment on lines
-20
to
-22
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| # If there are 10 or fewer pages, display links to every page. | ||
| # Otherwise, do some fancy | ||
| if paginator.num_pages <= 10: | ||
|
|
@@ -29,12 +26,15 @@ def pagination(context): | |
| # links at either end of the list of pages, and there are always | ||
| # ON_EACH_SIDE links at either end of the "current page" link. | ||
| page_range = [] | ||
| ON_EACH_SIDE = 3 | ||
| ON_ENDS = 2 | ||
|
|
||
| if page_num > (ON_EACH_SIDE + ON_ENDS): | ||
| page_range.extend(list(range(0, ON_EACH_SIDE - 1))) | ||
| page_range.extend(list(range(ON_EACH_SIDE - 1))) | ||
| page_range.append(DOT) | ||
| page_range.extend(list(range(page_num - ON_EACH_SIDE, page_num + 1))) | ||
| else: | ||
| page_range.extend(list(range(0, page_num + 1))) | ||
| page_range.extend(list(range(page_num + 1))) | ||
| if page_num < (paginator.num_pages - ON_EACH_SIDE - ON_ENDS - 1): | ||
| page_range.extend(list(range(page_num + 1, page_num + ON_EACH_SIDE + 1))) | ||
| page_range.append(DOT) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -122,7 +122,7 @@ def render(self, context): | |
| format = '' | ||
| if filetype and format and filetype in SELECT_FORMATS[format]: | ||
| selectable = True | ||
| elif filetype and format and filetype not in SELECT_FORMATS[format]: | ||
| elif filetype and format: | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| selectable = False | ||
| else: | ||
| selectable = True | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,10 +103,7 @@ def browse(request): | |
|
|
||
| # INITIAL VARIABLES | ||
| results_var = {'results_total': 0, 'results_current': 0, 'delete_total': 0, 'images_total': 0, 'select_total': 0} | ||
| counter = {} | ||
| for k, v in EXTENSIONS.items(): | ||
| counter[k] = 0 | ||
|
|
||
| counter = {k: 0 for k, v in EXTENSIONS.items()} | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| dir_list, file_list = default_storage.listdir(abs_path) | ||
| files = [] | ||
| for file in dir_list + file_list: | ||
|
|
@@ -140,7 +137,7 @@ def browse(request): | |
| results_var['images_total'] += 1 | ||
| if fileobject.filetype != 'Folder': | ||
| results_var['delete_total'] += 1 | ||
| elif fileobject.filetype == 'Folder' and fileobject.is_empty: | ||
| elif fileobject.is_empty: | ||
| results_var['delete_total'] += 1 | ||
| if query.get('type') and query.get('type') in SELECT_FORMATS and fileobject.filetype in SELECT_FORMATS[query.get('type')]: | ||
| results_var['select_total'] += 1 | ||
|
|
@@ -296,9 +293,10 @@ def _check_file(request): | |
| fileArray = {} | ||
| if request.method == 'POST': | ||
| for k, v in list(request.POST.items()): | ||
| if k != "folder": | ||
| if default_storage.exists(os.path.join(get_directory(), folder, v)): | ||
| fileArray[k] = v | ||
| if k != "folder" and default_storage.exists( | ||
| os.path.join(get_directory(), folder, v) | ||
| ): | ||
| fileArray[k] = v | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return HttpResponse(dumps(fileArray)) | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
FileBrowseWidget.__init__refactored with the following changes:assign-if-exp)