Added model for special galleries.
This commit is contained in:
@@ -8,13 +8,16 @@ import datetime
|
||||
|
||||
# Django imports.
|
||||
from django.http import HttpResponseNotFound
|
||||
from django.shortcuts import render
|
||||
from django.shortcuts import render, redirect
|
||||
from django.conf import settings
|
||||
from django.utils import timezone
|
||||
|
||||
# Third-party
|
||||
from PIL import Image
|
||||
|
||||
# Project imports.
|
||||
from .models import Image as Im
|
||||
|
||||
from .common import (
|
||||
normalize_sort,
|
||||
normalize_theme,
|
||||
@@ -34,6 +37,20 @@ def render_image(request, path_text, full_path):
|
||||
Renders the view corresponding to an image file.
|
||||
"""
|
||||
|
||||
try:
|
||||
img = Im.objects.get(path=full_path, user=request.user)
|
||||
|
||||
if request.method == 'POST':
|
||||
img.favorite = not img.favorite
|
||||
|
||||
except Im.DoesNotExist:
|
||||
img = Im(path=full_path, user=request.user)
|
||||
|
||||
finally:
|
||||
img.last_visited = timezone.now()
|
||||
img.visits = img.visits + 1
|
||||
img.save()
|
||||
|
||||
# Preserve query state (sort, search, theme) similar to gallery view
|
||||
search_text = request.GET.get("search", "").strip()
|
||||
sort_key = normalize_sort(request.GET.get("sort", "abc"))
|
||||
@@ -177,6 +194,9 @@ def render_image(request, path_text, full_path):
|
||||
"filesize": human_size(filesize),
|
||||
"created": fmt_ts(created_ts),
|
||||
"modified": fmt_ts(modified_ts),
|
||||
"visits": img.visits,
|
||||
"visited": fmt_ts(img.last_visited.timestamp()),
|
||||
"favorite": img.favorite
|
||||
},
|
||||
"breadcrumbs": breadcrumbs,
|
||||
"theme": theme,
|
||||
@@ -186,6 +206,7 @@ def render_image(request, path_text, full_path):
|
||||
"theme_toggle_url": gallery_url(
|
||||
Path(dir_path_text) if dir_path_text != "" else None, True, theme_query
|
||||
),
|
||||
"path": path_text,
|
||||
}
|
||||
|
||||
from .common import SORT_LABELS
|
||||
|
||||
Reference in New Issue
Block a user