Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
django-panik-nonstop
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
radiopanik
django-panik-nonstop
Commits
4126205e
Commit
4126205e
authored
Oct 05, 2017
by
fred
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
complete search page with filters, pagination, etc.
parent
3a4a451e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
93 additions
and
12 deletions
+93
-12
nonstop/forms.py
nonstop/forms.py
+10
-3
nonstop/templates/nonstop/search.html
nonstop/templates/nonstop/search.html
+57
-4
nonstop/views.py
nonstop/views.py
+26
-5
No files found.
nonstop/forms.py
View file @
4126205e
...
...
@@ -10,6 +10,9 @@ def get_nonstop_zones():
def
get_optional_nonstop_zones
():
return
[(
''
,
''
)]
+
get_nonstop_zones
()
def
get_search_nonstop_zones
():
return
[(
''
,
'All'
),
(
''
,
'--------------'
)]
+
get_nonstop_zones
()
+
[(
''
,
'--------------'
),
(
'none'
,
'None'
)]
class
UploadTracksForm
(
forms
.
Form
):
tracks
=
forms
.
FileField
(
widget
=
forms
.
ClearableFileInput
(
attrs
=
{
'multiple'
:
True
,
'accept'
:
'audio/*'
}))
...
...
@@ -23,10 +26,14 @@ class TrackMetaForm(forms.ModelForm):
class
TrackSearchForm
(
forms
.
Form
):
q
=
forms
.
CharField
(
label
=
_
(
'Text'
))
zone
=
forms
.
ChoiceField
(
label
=
_
(
'Nonstop Zone'
),
choices
=
get_optional_nonstop_zones
)
q
=
forms
.
CharField
(
label
=
_
(
'Text'
),
required
=
False
)
zone
=
forms
.
ChoiceField
(
label
=
_
(
'Nonstop Zone'
),
choices
=
get_search_nonstop_zones
,
required
=
False
)
order_by
=
forms
.
ChoiceField
(
label
=
_
(
'Order'
),
choices
=
[(
'alpha'
,
_
(
'Alphabetically'
))])
required
=
False
,
choices
=
[(
'title'
,
_
(
'Alphabetically'
)),
(
'-added_to_nonstop_timestamp'
,
_
(
'Newest first'
)),
(
'added_to_nonstop_timestamp'
,
_
(
'Oldest first'
))])
class
CleanupForm
(
forms
.
Form
):
...
...
nonstop/templates/nonstop/search.html
View file @
4126205e
...
...
@@ -12,12 +12,65 @@
</form>
<hr>
{% if tracks
.exists
%}
<
ul
>
{% if tracks %}
<
table
>
{% for track in tracks %}
<li><a
href=
"{% url 'track-view' pk=track.id %}"
>
{{track.title}}
</a>
— {{track.artist.name}}
</li>
<tr><td
class=
"track"
><a
href=
"{% url 'track-view' pk=track.id %}"
>
{{track.title}}
</a></td>
<td
class=
"artist"
>
{{track.artist.name}}
</td>
<td
class=
"zone"
>
{% for zone in track.nonstop_zones.all %}{{ zone.title }}{% if not forloop.last %}, {% endif %}{% endfor %}
</td>
<td
class=
"since"
>
{% if track.added_to_nonstop_timestamp %}(since {{track.added_to_nonstop_timestamp|date:"SHORT_DATE_FORMAT" }}{% endif %}
</td>
</tr>
{% endfor %}
</ul>
</table>
<div
class=
"pagination"
>
<span
class=
"step-links"
>
{% if tracks.has_previous %}
<a
href=
"?{{ qs }}&page={{ tracks.previous_page_number }}"
>
←
</a>
{% endif %}
<span
class=
"current"
>
{{ tracks.number }} / {{ tracks.paginator.num_pages }}
</span>
{% if tracks.has_next %}
<a
href=
"?{{ qs }}&page={{ tracks.next_page_number }}"
>
→
</a>
{% endif %}
</span>
</div>
{% endif %}
<style>
table
{
max-width
:
100%
;
min-width
:
50em
;
}
td
{
padding
:
0.4ex
1ex
;
}
td
.track
{
min-width
:
30em
;
}
td
.artist
{
min-width
:
20em
;
}
td
.zone
{
min-width
:
10em
;
}
td
.since
{
min-width
:
10em
;
}
tr
:nth-child
(
even
)
{
background
:
#f2f2f2
;
}
.step-links
a
{
padding
:
1ex
;
}
div
.pagination
{
margin-top
:
1em
;
}
</style>
{% endblock %}
nonstop/views.py
View file @
4126205e
...
...
@@ -8,6 +8,7 @@ import tempfile
import
mutagen
from
django.core.files.storage
import
default_storage
from
django.core.paginator
import
Paginator
,
EmptyPage
,
PageNotAnInteger
from
django.core.urlresolvers
import
reverse
from
django.contrib
import
messages
from
django.db.models
import
Q
...
...
@@ -246,7 +247,7 @@ class SearchView(TemplateView):
def
get_context_data
(
self
,
**
kwargs
):
ctx
=
super
(
SearchView
,
self
).
get_context_data
(
**
kwargs
)
ctx
[
'form'
]
=
TrackSearchForm
()
ctx
[
'form'
]
=
TrackSearchForm
(
self
.
request
.
GET
)
queryset
=
Track
.
objects
.
all
()
q
=
self
.
request
.
GET
.
get
(
'q'
)
...
...
@@ -256,10 +257,30 @@ class SearchView(TemplateView):
zone
=
self
.
request
.
GET
.
get
(
'zone'
)
if
zone
:
from
emissions.models
import
Nonstop
queryset
=
queryset
.
filter
(
nonstop_zones
=
zone
)
if
q
or
zone
:
ctx
[
'tracks'
]
=
queryset
.
order_by
(
'title'
).
select_related
()
if
zone
==
'none'
:
queryset
=
queryset
.
filter
(
nonstop_zones
=
None
)
else
:
queryset
=
queryset
.
filter
(
nonstop_zones
=
zone
)
qs
=
self
.
request
.
GET
.
copy
()
qs
.
pop
(
'page'
,
None
)
ctx
[
'qs'
]
=
qs
.
urlencode
()
order
=
self
.
request
.
GET
.
get
(
'order_by'
)
or
'title'
if
order
:
if
'added_to_nonstop_timestamp'
in
order
:
queryset
=
queryset
.
filter
(
added_to_nonstop_timestamp__isnull
=
False
)
queryset
=
queryset
.
order_by
(
order
)
tracks
=
Paginator
(
queryset
.
select_related
(),
20
)
page
=
self
.
request
.
GET
.
get
(
'page'
)
try
:
ctx
[
'tracks'
]
=
tracks
.
page
(
page
)
except
PageNotAnInteger
:
ctx
[
'tracks'
]
=
tracks
.
page
(
1
)
except
EmptyPage
:
ctx
[
'tracks'
]
=
tracks
.
page
(
tracks
.
num_pages
)
return
ctx
...
...
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