This repository has been archived by the owner on Sep 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #573 from CSCfi/stable
Merge stable to master: v1.7.0
- Loading branch information
Showing
18 changed files
with
911 additions
and
267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 2.2.10 on 2020-03-30 08:01 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('metax_api', '0017_catalogrecord_rems_identifier'), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name='catalogrecord', | ||
old_name='_access_granter', | ||
new_name='access_granter', | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from rest_framework.pagination import LimitOffsetPagination | ||
|
||
|
||
class DirectoryPagination(LimitOffsetPagination): | ||
|
||
page_size = 10 | ||
page_size_query_param = 'page_size' | ||
|
||
def paginate_queryset(self, queryset, request, view=None): | ||
self.count = self.get_count(queryset) | ||
self.limit = self.get_limit(request) | ||
if self.limit is None: | ||
return None | ||
|
||
self.offset = self.get_offset(request) | ||
self.request = request | ||
if self.count > self.limit and self.template is not None: | ||
self.display_page_controls = True | ||
|
||
if self.count == 0 or self.offset > self.count: | ||
return [] | ||
|
||
# serves filters directories_only and files_only which returnes dictionaries | ||
if len(queryset) == 1: | ||
key = list(queryset.keys())[0] | ||
return dict({key: queryset[key][self.offset:self.offset + self.limit]}) | ||
|
||
dirs = [] | ||
files = [] | ||
dir_len = len(queryset['directories']) | ||
|
||
# if no directories left to show | ||
if self.offset >= dir_len: | ||
offset = self.offset - dir_len | ||
files = queryset['files'][offset:offset + self.limit] | ||
|
||
# if directories are not enough for one page limit | ||
elif (self.offset + self.limit) >= dir_len: | ||
dirs = queryset['directories'][self.offset:] | ||
files_to_show = self.limit - (dir_len - self.offset) | ||
if files_to_show > 0: | ||
files = queryset['files'][0:files_to_show] | ||
|
||
# if enough directories for page limit | ||
else: | ||
dirs = queryset['directories'][self.offset:self.offset + self.limit] | ||
|
||
return dict({'directories': dirs, 'files': files}) | ||
|
||
def get_count(self, queryset): | ||
""" | ||
Determine a count of directory dictionary. | ||
""" | ||
count = 0 | ||
for q, v in queryset.items(): | ||
if q in ['directories', 'files']: | ||
count = count + len(v) | ||
return count |
Oops, something went wrong.