Commit aaf7714a authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg

Show photo albums to members only and only the albums made during their membership

parent 4e83c64c
{% extends 'base.html' %} {% extends 'base.html' %}
{% load staticfiles i18n thumbnail shared_thumbnail %} {% load staticfiles i18n thumbnail shared_thumbnail %}
{% block title %}{{ album.title }} — {% trans "Photos" %} — {{ block.super }}{% endblock %}
{% block css_head %} {% block css_head %}
{{ block.super }} {{ block.super }}
<link href="{% static "photos/css/style.css" %}" rel="stylesheet" type="text/css"> <link href="{% static "photos/css/style.scss" %}" rel="stylesheet" type="text/scss">
{% endblock %} {% endblock %}
{% block body %} {% block body %}
...@@ -18,29 +20,29 @@ ...@@ -18,29 +20,29 @@
</p> </p>
{% endif %} {% endif %}
<div class="gallery"> <div class="gallery">
<ul class="gallery-photos row"> <ul class="gallery-photos row">
{% for photo in photos %} {% for photo in photos %}
<li class="post gallery-photo span3 has-overlay {% if forloop.counter0|divisibleby:4 %}first-child{% endif %}"> <li class="post gallery-photo span3 has-overlay {% if forloop.counter0|divisibleby:4 %}first-child{% endif %}">
<a data-fancybox-rotation="{{ photo.rotation }}" class="gallery-box" rel="gallery" <a data-fancybox-rotation="{{ photo.rotation }}" class="gallery-box" rel="gallery"
{% if album.shareable %}
data-download="{% url 'photos:shared-download' album.slug album.access_token photo %}" href="{% shared_thumbnail album.slug album.access_token photo '1024x768' fit=False %}"
{% else %}
data-download="{% url 'photos:download' photo %}" href="{% thumbnail photo.file '1024x768' fit=False %}"
{% endif %}>
<span class="post-inner">
<span class="inner-img">
{% if album.shareable %} {% if album.shareable %}
data-download="{% url 'photos:shared-download' album.slug album.access_token photo %}" href="{% shared_thumbnail album.slug album.access_token photo '1024x768' fit=False %}" <img class="rotate{{ photo.rotation }}" src="{% shared_thumbnail album.slug album.access_token photo '220x220' %}" alt="" />
{% else %} {% else %}
data-download="{% url 'photos:download' photo %}" href="{% thumbnail photo.file '1024x768' fit=False %}" <img class="rotate{{ photo.rotation }}" src="{% thumbnail photo.file '220x220' %}" alt="" />
{% endif %}> {% endif %}
<span class="post-inner"> </span>
<span class="inner-img"> <span class="post-overlay">
{% if album.shareable %} </span>
<img class="rotate{{ photo.rotation }}" src="{% shared_thumbnail album.slug album.access_token photo '220x220' %}" alt="" /> </span>
{% else %} </a>
<img class="rotate{{ photo.rotation }}" src="{% thumbnail photo.file '220x220' %}" alt="" /> </li>
{% endif %} {% endfor %}
</span> </ul>
<span class="post-overlay">
</span>
</span>
</a>
</li>
{% endfor %}
</ul>
</div> </div>
{% endblock %} {% endblock %}
\ No newline at end of file
{% extends 'base.html' %} {% extends 'base.html' %}
{% load i18n thumbnail staticfiles %} {% load i18n thumbnail staticfiles %}
{% block title %}{% trans "Photos" %} — {{ block.super }}{% endblock %}
{% block css_head %} {% block css_head %}
{{ block.super }} {{ block.super }}
<link href="{% static "photos/css/style.css" %}" rel="stylesheet" type="text/css"> <link href="{% static 'photos/css/style.scss' %}" rel="stylesheet" type="text/scss">
{% endblock %} {% endblock %}
{% block body %} {% block body %}
<h1>{% trans "Photos" %}</h1> <h1>{% trans "Photos" %}</h1>
<div class="gallery"> <div class="gallery">
<ul class="gallery-albums row"> <ul class="gallery-albums row">
{% for album in albums %} {% for album in albums %}
<li class="post gallery-album span3 has-overlay {% if forloop.counter0|divisibleby:4 %}first-child{% endif %}"> <li class="post gallery-album span3 has-overlay {% if forloop.counter0|divisibleby:4 %}first-child{% endif %}">
<a href="{% url 'photos:album' album.slug %}"> <a href="{% url 'photos:album' album.slug %}">
<span class="post-inner"> <span class="post-inner">
<span class="inner-img"> <span class="inner-img">
<img class="rotate{{ album.cover.rotation }}" src="{% thumbnail album.cover.file '220x220' %}" alt="" /> {% if album.cover is not None %}
</span> <img class="rotate{{ album.cover.rotation }}" src="{% thumbnail album.cover.file '220x220' %}" alt=""/>
<span class="post-overlay"> {% endif %}
<span class="post-overlay-meta"> </span>
<h2>{{ album.title }}</h2> <span class="post-overlay">
<p>{{ album.date|date:"d-m-Y" }}</p> <span class="post-overlay-meta">
</span> <h2>{{ album.title }}</h2>
</span> <p>{{ album.date|date:"d-m-Y" }}</p>
</span> </span>
</a> </span>
</li> </span>
{% endfor %} </a>
</ul> </li>
{% endfor %}
</ul>
</div> </div>
<div class='clearfix'></div>
<div class="pagination" style="float: none;text-align: center;"> <div class="clearfix"></div>
<span class="step-links">
{% if albums.has_previous %} <div class="pagination-wrapper row">
<a href="?page={{ albums.previous_page_number }}">&laquo;</a> <ul class="pagination">
{% else %} {% if albums.has_previous %}
<a style='visibility: hidden;'>&laquo;</a> <li>
{% endif %} <a class="page-prev" href="{% url 'photos:index' %}?page={{ albums.previous_page_number }}">Previous</a>
</li>
<span class="current"> {% endif %}
{{ albums.number }} / {{ albums.paginator.num_pages }}
</span> {% for page in page_range %}
{% if page == albums.number %}
{% if albums.has_next %} <li class="current">
<a href="?page={{ albums.next_page_number }}">&raquo;</a> <span class="page-number">
{% else %} {{ page }}
<a style='visibility: hidden;'>&raquo;</a> </span>
{% endif %} </li>
</span> {% else %}
<li>
<a href="{% url 'photos:index' %}?page={{ page }}" class="page-number button">{{ page }}</a>
</li>
{% endif %}
{% endfor %}
{% if albums.has_next %}
<li>
<a class="page-next" href="{% url 'photos:index' %}?page={{ albums.next_page_number }}">{% trans "Next" %}</a>
</li>
{% endif %}
</ul>
</div> </div>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -4,6 +4,7 @@ from django.conf import settings ...@@ -4,6 +4,7 @@ from django.conf import settings
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from django.http import Http404 from django.http import Http404
from django.db.models import Q
from django.shortcuts import get_object_or_404, render from django.shortcuts import get_object_or_404, render
from sendfile import sendfile from sendfile import sendfile
...@@ -17,10 +18,29 @@ COVER_FILENAME = 'cover.jpg' ...@@ -17,10 +18,29 @@ COVER_FILENAME = 'cover.jpg'
@login_required @login_required
def index(request): def index(request):
albums = Album.objects.filter(hidden=False).order_by('-date') if request.user.member is None:
raise Http404("Sorry, you're not a member")
albums_filter = Q()
# Check if the user currently has a membership
if request.user.member.current_membership is None:
# This is user is currently not a member
# so only show photos that were made during their membership
for membership in request.user.membership_set.all():
if membership.until is not None:
albums_filter |= (Q(date__gte=membership.since) & Q(
date__lte=membership.until))
else:
albums_filter |= (Q(date__gte=membership.since))
# Only show published albums
albums_filter = albums_filter & Q(hidden=False)
albums = Album.objects.filter(albums_filter).order_by('-date')
paginator = Paginator(albums, 12) paginator = Paginator(albums, 12)
page = request.GET.get('page') page = request.GET.get('page')
page = 1 if page is None or not page.isdigit() else int(page)
try: try:
albums = paginator.page(page) albums = paginator.page(page)
except PageNotAnInteger: except PageNotAnInteger:
...@@ -29,14 +49,44 @@ def index(request): ...@@ -29,14 +49,44 @@ def index(request):
except EmptyPage: except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results. # If page is out of range (e.g. 9999), deliver last page of results.
albums = paginator.page(paginator.num_pages) albums = paginator.page(paginator.num_pages)
return render(request, 'photos/index.html', {'albums': albums})
page_range = range(1, paginator.num_pages + 1)
if paginator.num_pages > 7:
if page > 3:
page_range_end = paginator.num_pages
if page + 3 <= paginator.num_pages:
page_range_end = page + 3
page_range = range(page - 2, page_range_end)
while page_range.stop - page_range.start < 5:
page_range = range(page_range.start - 1, page_range.stop)
else:
page_range = range(1, 6)
return render(request, 'photos/index.html', {'albums': albums,
'page_range': page_range})
@login_required @login_required
def album(request, slug): def album(request, slug):
album = get_object_or_404(Album, slug=slug) album = get_object_or_404(Album, slug=slug)
context = {'album': album, 'photos': album.photo_set.filter(hidden=False)} can_view = True
return render(request, 'photos/album.html', context)
# Check if the user currently has a membership
if request.user.member.current_membership is None:
# This user is currently not a member, so need to check if he/she
# can view this album by checking the membership
filter = Q(since__lte=album.date) & (Q(until__gte=album.date) |
Q(until=None))
can_view = request.user.membership_set.filter(filter).count() > 0
if request.user.member is not None and can_view:
context = {
'album': album,
'photos': album.photo_set.filter(hidden=False)
}
return render(request, 'photos/album.html', context)
raise Http404("Sorry, you're not allowed to view this album")
def _checked_shared_album(slug, token): def _checked_shared_album(slug, token):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment