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
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
c2796785
Commit
c2796785
authored
Oct 04, 2017
by
fred
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add possibility to search on nonstop zone
parent
8a5f167b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
15 deletions
+27
-15
nonstop/forms.py
nonstop/forms.py
+8
-0
nonstop/templates/nonstop/search.html
nonstop/templates/nonstop/search.html
+4
-12
nonstop/views.py
nonstop/views.py
+15
-3
No files found.
nonstop/forms.py
View file @
c2796785
from
django
import
forms
from
django.utils.translation
import
ugettext_lazy
as
_
from
.models
import
Track
...
...
@@ -19,3 +20,10 @@ class TrackMetaForm(forms.ModelForm):
class
Meta
:
model
=
Track
fields
=
[
'language'
,
'instru'
,
'sabam'
,
'cfwb'
,
'nonstop_zones'
]
class
TrackSearchForm
(
forms
.
Form
):
q
=
forms
.
CharField
(
label
=
_
(
'Text'
))
zone
=
forms
.
ChoiceField
(
label
=
_
(
'Nonstop Zone'
),
choices
=
get_optional_nonstop_zones
)
order_by
=
forms
.
ChoiceField
(
label
=
_
(
'Order'
),
choices
=
[(
'alpha'
,
_
(
'Alphabetically'
))])
nonstop/templates/nonstop/search.html
View file @
c2796785
...
...
@@ -6,26 +6,18 @@
{% endblock %}
{% block content %}
<form><input
name=
"q"
type=
"search"
><button>
{% trans "Search" %}
</button></form>
<form
id=
"track-search"
>
{{ form.as_p }}
<button>
{% trans "Search" %}
</button>
</form>
<hr>
{% if artists.exists %}
<h3>
{% trans "Artists" %}
</h3>
<ul>
{% for artist in artists %}
<li><a
href=
"{% url 'artist-view' pk=artist.id %}"
>
{{artist.name}}
</a></li>
{% endfor %}
</ul>
{% endif %}
{% if tracks.exists %}
<h3>
{% trans "Tracks" %}
</h3>
<ul>
{% for track in tracks %}
<li><a
href=
"{% url 'track-view' pk=track.id %}"
>
{{track.title}}
</a>
— {{track.artist.name}}
</li>
{% endfor %}
</ul>
{% endif %}
{% endblock %}
nonstop/views.py
View file @
c2796785
...
...
@@ -10,6 +10,7 @@ import mutagen
from
django.core.files.storage
import
default_storage
from
django.core.urlresolvers
import
reverse
from
django.contrib
import
messages
from
django.db.models
import
Q
from
django.http
import
HttpResponse
,
HttpResponseRedirect
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.views.generic.base
import
RedirectView
,
TemplateView
...
...
@@ -18,7 +19,7 @@ from django.views.generic.detail import DetailView
from
django.views.generic.edit
import
FormView
from
django.views.generic.list
import
ListView
from
.forms
import
UploadTracksForm
,
TrackMetaForm
from
.forms
import
UploadTracksForm
,
TrackMetaForm
,
TrackSearchForm
from
.models
import
SomaLogLine
,
Track
,
Artist
,
NonstopFile
from
emissions.models
import
Nonstop
...
...
@@ -245,8 +246,19 @@ class SearchView(TemplateView):
def
get_context_data
(
self
,
**
kwargs
):
ctx
=
super
(
SearchView
,
self
).
get_context_data
(
**
kwargs
)
ctx
[
'form'
]
=
TrackSearchForm
()
queryset
=
Track
.
objects
.
all
()
q
=
self
.
request
.
GET
.
get
(
'q'
)
if
q
:
ctx
[
'artists'
]
=
Artist
.
objects
.
filter
(
name__icontains
=
q
.
lower
())
ctx
[
'tracks'
]
=
Track
.
objects
.
filter
(
title__icontains
=
q
.
lower
()).
order_by
(
'title'
).
select_related
()
queryset
=
queryset
.
filter
(
Q
(
title__icontains
=
q
.
lower
())
|
Q
(
artist__name__icontains
=
q
.
lower
()))
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
()
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