Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
concrexit
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
70
Issues
70
List
Boards
Labels
Service Desk
Milestones
Merge Requests
10
Merge Requests
10
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
thalia
concrexit
Commits
aaf7714a
Commit
aaf7714a
authored
Nov 04, 2016
by
Sébastiaan Versteeg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Show photo albums to members only and only the albums made during their membership
parent
4e83c64c
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
136 additions
and
68 deletions
+136
-68
website/photos/static/photos/css/style.scss
website/photos/static/photos/css/style.scss
+0
-0
website/photos/templates/photos/album.html
website/photos/templates/photos/album.html
+26
-24
website/photos/templates/photos/index.html
website/photos/templates/photos/index.html
+56
-40
website/photos/views.py
website/photos/views.py
+54
-4
No files found.
website/photos/static/photos/css/style.css
→
website/photos/static/photos/css/style.
s
css
View file @
aaf7714a
File moved
website/photos/templates/photos/album.html
View file @
aaf7714a
{% 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/s
css"
>
{% endblock %}
{% endblock %}
{% block body %}
{% block body %}
...
...
website/photos/templates/photos/index.html
View file @
aaf7714a
{% 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/s
css"
>
{% endblock %}
{% endblock %}
{% block body %}
{% block body %}
...
@@ -16,7 +18,9 @@
...
@@ -16,7 +18,9 @@
<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 %}
<img
class=
"rotate{{ album.cover.rotation }}"
src=
"{% thumbnail album.cover.file '220x220' %}"
alt=
""
/>
{% endif %}
</span>
</span>
<span
class=
"post-overlay"
>
<span
class=
"post-overlay"
>
<span
class=
"post-overlay-meta"
>
<span
class=
"post-overlay-meta"
>
...
@@ -30,24 +34,36 @@
...
@@ -30,24 +34,36 @@
{% endfor %}
{% endfor %}
</ul>
</ul>
</div>
</div>
<div
class=
'clearfix'
></div>
<div
class=
"pagination"
style=
"float: none;text-align: center;"
>
<div
class=
"clearfix"
></div>
<span
class=
"step-links"
>
<div
class=
"pagination-wrapper row"
>
<ul
class=
"pagination"
>
{% if albums.has_previous %}
{% if albums.has_previous %}
<a
href=
"?page={{ albums.previous_page_number }}"
>
«
</a
>
<li
>
{% else %}
<a
class=
"page-prev"
href=
"{% url 'photos:index' %}?page={{ albums.previous_page_number }}"
>
Previous
</a>
<a
style=
'visibility: hidden;'
>
«
</a
>
</li
>
{% endif %}
{% endif %}
<span
class=
"current"
>
{% for page in page_range %}
{{ albums.number }} / {{ albums.paginator.num_pages }}
{% if page == albums.number %}
<li
class=
"current"
>
<span
class=
"page-number"
>
{{ page }}
</span>
</span>
</li>
{% else %}
<li>
<a
href=
"{% url 'photos:index' %}?page={{ page }}"
class=
"page-number button"
>
{{ page }}
</a>
</li>
{% endif %}
{% endfor %}
{% if albums.has_next %}
{% if albums.has_next %}
<a
href=
"?page={{ albums.next_page_number }}"
>
»
</a
>
<li
>
{% else %}
<a
class=
"page-next"
href=
"{% url 'photos:index' %}?page={{ albums.next_page_number }}"
>
{% trans "Next" %}
</a>
<a
style=
'visibility: hidden;'
>
»
</a
>
</li
>
{% endif %}
{% endif %}
</span
>
</ul
>
</div>
</div>
{% endblock %}
{% endblock %}
website/photos/views.py
View file @
aaf7714a
...
@@ -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
# 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
)
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
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment