Skip to content

Commit 905040b

Browse files
build basic gallery engine
1 parent 38f2874 commit 905040b

File tree

8 files changed

+61
-2
lines changed

8 files changed

+61
-2
lines changed

1.jpg

203 KB
Loading
790 Bytes
Binary file not shown.
251 Bytes
Binary file not shown.

gallery/scan_dir_class.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import os
2+
3+
class ScanDir:
4+
5+
PATH = "c:/Users/George/venv/myProjects/gallery-pic";
6+
7+
def scan_dir(self):
8+
files = os.listdir(self.PATH)
9+
10+
# for f in files:
11+
# print(f)
12+
files = files[:20]
13+
return files;
14+
15+
def getFirstFile(self, file):
16+
if(os.path.isdir(self.PATH + '/' + file)):
17+
return self.PATH + '/' + file + '/' + os.listdir(self.PATH + '/' + file)[0]
18+
else:
19+
return None

gallery/views.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
from django.shortcuts import render
2+
from gallery.scan_dir_class import ScanDir
23
import random
34

45

56
def index(request):
6-
return render(request, 'index.html', {'var_test': 's'})
7+
files_content = []
8+
files = ScanDir().scan_dir()
9+
for file in files:
10+
first_file = ScanDir().getFirstFile(file)
11+
if (first_file):
12+
files_content.append({
13+
'dir': file,
14+
'first_file': first_file
15+
})
16+
return render(request, 'index.html', {'var_test': 's', 'files': ScanDir().scan_dir(), 'complete_list': files_content})
717

818
def view(request):
919
return render(request, 'view.html', {'var_test': 's2'})
44 Bytes
Binary file not shown.

python_gallery_manager/settings.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,10 @@
119119
# https://docs.djangoproject.com/en/3.0/howto/static-files/
120120

121121
STATIC_URL = '/static/'
122+
123+
# Additional locations of static files
124+
STATICFILES_DIRS = (
125+
# location of your application, should not be public web accessible
126+
# os.path.join(BASE_DIR, 'mainApp/static'),
127+
os.path.join(BASE_DIR, 'static'),
128+
)

templates/index.html

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,24 @@
1-
Test {{ var_test }}
1+
2+
{% load static %}
3+
4+
Test {{ var_test }}
5+
6+
7+
{{ files|length }}
8+
<img src="{% static '1.jpg' %}">
9+
{% comment %}
10+
11+
{% for file in files %}
12+
<BR>
13+
{{ file }}
14+
{% endfor %}
15+
16+
17+
18+
{% endcomment %}
19+
20+
{% for file in complete_list %}
21+
<BR>
22+
{{ file.dir }}
23+
<img src="{{ file.first_file }}" />"
24+
{% endfor %}

0 commit comments

Comments
 (0)