Skip to content

Commit 8204705

Browse files
added view section
1 parent 332abd1 commit 8204705

File tree

14 files changed

+85
-70
lines changed

14 files changed

+85
-70
lines changed
1.72 KB
Binary file not shown.
19 Bytes
Binary file not shown.
-1.1 KB
Binary file not shown.
15 Bytes
Binary file not shown.
9 Bytes
Binary file not shown.

gallery/loadFiles.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# -*- coding: utf-8 -*-
2+
import os
3+
import urllib.parse
4+
5+
class LoadFiles:
6+
7+
PATH = "c:/Users/George/venv/myProjects/gallery-pic"
8+
9+
def __init__(self, path_to_scan = None):
10+
self.path_to_scan = path_to_scan if path_to_scan else self.PATH
11+
12+
def scanDirFunc(self):
13+
files = os.listdir(self.path_to_scan)
14+
return files
15+
16+
def getFirstFile(self, files, first_file = True):
17+
files_content = []
18+
for file in files:
19+
if(os.path.isdir(self.path_to_scan + '/' + file) == False):
20+
continue
21+
files_in_dir = os.listdir(self.path_to_scan + '/' + file)
22+
if(first_file == True):
23+
files_in_dir = files_in_dir[0]
24+
files_content.append({
25+
'dir_name': file,
26+
'dir_name_encoded': LoadFiles.encodeUrl(file),
27+
'files_in_dir': LoadFiles.encodeUrl(file+'/'+files_in_dir)
28+
})
29+
return files_content
30+
31+
def getPhotosFiles(self, dir_name):
32+
files_content = []
33+
dir_name = LoadFiles.decodeUrl(dir_name)
34+
self.path_to_scan = self.path_to_scan + '/' + dir_name
35+
for file in self.scanDirFunc():
36+
file_path = self.path_to_scan + '/' + file
37+
if(os.path.isdir(file_path) == True):
38+
continue
39+
files_content.append(file_path)
40+
return files_content
41+
42+
@staticmethod
43+
def encodeUrl(str_var):
44+
return urllib.parse.quote(str_var)
45+
46+
@staticmethod
47+
def decodeUrl(str_var):
48+
return urllib.parse.unquote(str_var)
49+
50+

gallery/pagination.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class Pagination:
22

3-
MAX_ON_PAGE = 500
3+
MAX_ON_PAGE = 50
44

55
def __init__(self, last_page = None):
66
self.__last_page = self.lastPageSetter(last_page, self.MAX_ON_PAGE)
@@ -15,28 +15,20 @@ def lastPage(self):
1515
def next(self):
1616
return self.__next
1717

18-
# @next.setter
19-
def nextSetter(self, value, max_pages):
20-
return value + max_pages
21-
2218
@property
2319
def prev(self):
2420
return self.__prev
2521

2622
# @prev.setter
2723
def lastPageSetter(self, value, max_pages):
28-
return int(value if value != None else max_pages)
24+
value = int(value) if value else max_pages
25+
return value if value > 0 else max_pages
2926

27+
# @next.setter
28+
def nextSetter(self, value, max_pages):
29+
return value + max_pages
30+
3031
# @prev.setter
3132
def prevSetter(self, value, max_pages):
3233
prev_var = (value if value else 0) - max_pages
33-
return 0 if prev_var < 0 else prev_var
34-
35-
# def setMaxPagination(max, search):
36-
# return search ? max : ( >= max ? max : $this->getLastPage());
37-
38-
39-
# function setMinPagination($search) : int {
40-
# return $search ? 0 : $this->getPrev();
41-
# }
42-
34+
return 0 if prev_var < 0 else prev_var

gallery/scan_dir_class.py

Lines changed: 0 additions & 36 deletions
This file was deleted.

gallery/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
urlpatterns = [
66
path('', views.index, name='index_main'),
77
url(r'^(?P<last_item>\d+)$', views.index, name='index_main'),
8-
path('view', views.view, name='view_main'),
8+
path('view/<folder_name>', views.view, name='view_main'),
99
]

gallery/views.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
from django.shortcuts import render
2-
from gallery.scan_dir_class import ScanDir
2+
from gallery.loadFiles import LoadFiles
33
from gallery.pagination import Pagination
44
import random
55

6-
76
def index(request, last_item = None):
87
r = Pagination(last_item)
9-
s = ScanDir()
10-
files = s.scanDirFunc()
11-
files = s.scanDirFunc()[r.prev:r.next]
12-
return render(request, 'index.html', {
13-
'var_test': 's',
14-
'files': files,
8+
s = LoadFiles()
9+
files = s.scanDirFunc()[r.prev:r.lastPage]
10+
return render(request, 'index.html', {
1511
'complete_list': s.getFirstFile(files),
1612
'next': r.next,
17-
'prev': r.prev,
13+
'prev': r.prev
1814
})
1915

20-
def view(request):
21-
return render(request, 'view.html', {'var_test': 's2'})
16+
def view(request, folder_name):
17+
return render(request, 'view.html', {
18+
'files': LoadFiles().getPhotosFiles(folder_name)
19+
})
2220

0 commit comments

Comments
 (0)