Skip to content

Commit

Permalink
Merge pull request #38 from mcilya/next
Browse files Browse the repository at this point in the history
Move away from using list indexes in templates
  • Loading branch information
ada-af committed Oct 30, 2020
2 parents 5a6e7d8 + 08e3646 commit df28d7b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
2 changes: 2 additions & 0 deletions DBooru_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def search():
try:
results, total = db.search(db_search_list['search'],
db_search_list['remove'], page=page-1)
results = [DBImage(x) for x in results]
except (IndexError, KeyError):
pass
return render_template('results.html', search=query, page=page,
Expand All @@ -83,6 +84,7 @@ def search():
def image(img_id):
prefix, img_id = img_id.split("_")
image = db.search_by_id(img_id, prefix=prefix)
image = DBImage(image)
query = request.args.get('q')
if query is None:
query = ""
Expand Down
6 changes: 5 additions & 1 deletion dermod/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ class DBImage:
def __init__(self, data=None):
if isinstance(data, list) or isinstance(data, tuple):
self.no_p_fname = data[0]
self.tags = set(data[1].split(',,'))
self.tags = list(sorted(set([x for x in data[1].split(',,') if x != '' and x != ' '])))
self.width = data[2]
self.height = data[3]
self.ratio = data[4]
self.link = data[5]
self.prefix = data[6]
self.id = data[7]
self.fformat = self.no_p_fname.split('.')[-1]
self.fname = self.prefix + self.no_p_fname
else:
self.no_p_fname
self.tags
Expand All @@ -78,6 +80,8 @@ def __init__(self, data=None):
self.link
self.prefix
self.id
self.fformat = self.no_p_fname.split('.')[-1]
self.fname = self.prefix + self.no_p_fname

def __repr__(self):
return f"<Image {self.prefix}{self.id}>"
25 changes: 13 additions & 12 deletions templates/image.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,35 @@
</div>
<div>
<div class=" text-center">
{% if image[0].endswith('.webm') %}
{% if image.no_p_fname.endswith('.webm') %}
<video class="img img-fluid" preload="auto" autoplay controls muted loop>
<source src="/raw/{{ image[-2] + image[0] }}" />
<source src="/raw/{{ image.fname }}" />
</video>
{% else %}
<img src="/raw/{{ image[-2] + image[0] }}" class="ft" id="image" onclick="sw()" />
<img src="/raw/{{ image.fname }}" class="ft" id="image" onclick="sw()" />
{% endif %}<br />
</div>
<div class="text-center">
<div class="btn-group">
<button class="btn btn-primary" onclick="dl('{{ image[-2] + image[0] }}')">
<button class="btn btn-primary" onclick="dl('{{ image.fname }}')">
Download
</button>
<a class="btn btn-primary" data-clipboard-text="{{ image[-3] }}" id="clip">
<a class="btn btn-primary" data-clipboard-text="{{ image.link }}" id="clip">
Copy CDN link
</a>
<button type="button" class="btn btn-primary dropdown-toggle"
aria-haspopup="true" aria-expanded="false" data-toggle="dropdown">
<span class="sr-only">Toggle Dropdown</span>
</button>
<div class="dropdown-menu" id='dropdown'>
<a class="dropdown-item" id="open" onclick="view('{{ image[-2]}}{{image[0] }}')">
<a class="dropdown-item" id="open" onclick="view('{{ image.fname }}')">
View
</a>
<a class="dropdown-item" onclick="dcdn('{{ image[-3] }}')">
<a class="dropdown-item" onclick="dcdn('{{ image.link }}')">
View on CDN
</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" onclick="reloadimg('{{image[-2]}}{{image[-1]}}')">
<a class="dropdown-item" onclick="reloadimg('{{ image.prefix }}{{ image.id }}')">
Redownload Image
</a>
<a class="dropdown-item" data-toggle="modal" data-target="#deletemodal">
Expand All @@ -74,9 +74,10 @@
</div>
<div>
<h3>
Tags: {% for i in image[1].split(',,')[1:-2] %}
<a href="/search?q={{ i }}&page=1">{{ i }}</a>, {% endfor %} <a
href="/search?q={{ image[1].split(',,')[-2] }}&page=1">{{ image[1].split(',,')[-2] }}</a>
Tags: {% for i in image.tags[:-2] %}
<a href="/search?q={{ i }}&page=1">{{ i }}</a>,
{% endfor %}
<a href="/search?q={{ image.tags[-1] }}&page=1">{{ image.tags[-1] }}</a>
</h3>
</div>
</div>
Expand All @@ -96,7 +97,7 @@ <h5 class="modal-title" id="deletemodallabel">Image removal</h5>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Go back</button>
<button type="button" class="btn btn-danger" onclick="removeimg('{{image[-2]}}{{image[-1]}}')">Yes, remove it</button>
<button type="button" class="btn btn-danger" onclick="removeimg('{{image.prefix}}{{image.id}}')">Yes, remove it</button>
</div>
</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions templates/results.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@
<div class="row">
<div class="col-lg-12">
{% for i in results %}
{% if i[0].endswith('.webm') %}
{% if i.no_p_fname.endswith('.webm') %}
<div class="cont">
<div class='g-item'>
<video class="img-fluid g-item" preload='auto' muted onclick="sclick('{{i[-2]+str(i[-1])}}')">
<source src="/raw/{{i[-2]+i[0]}}" />
<video class="img-fluid g-item" preload='auto' muted onclick="sclick('{{i.prefix}}{{i.id}}')">
<source src="/raw/{{i.fname}}" />
</video></div>
</div>
{% else %}
<div class="cont">
<div class='g-item'><img src="/thumbnail/{{i[-2]+i[0]}}" onclick="sclick('{{i[-2]+str(i[-1])}}')"
<div class='g-item'><img src="/thumbnail/{{i.fname}}" onclick="sclick('{{i.prefix}}{{i.id}}')"
class="img-fluid g-item"></abbr></div>
</div>
{% endif %}
Expand Down

0 comments on commit df28d7b

Please sign in to comment.