Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
radiopanik
panikdb
Commits
6287dfa4
Commit
6287dfa4
authored
May 25, 2015
by
fred
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add support for Topik objects
parent
e97101bb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
1 deletion
+67
-1
panikdb/customtags/templatetags/panikdbtags.py
panikdb/customtags/templatetags/panikdbtags.py
+26
-0
panikdb/templates/combo/manager_base.html
panikdb/templates/combo/manager_base.html
+10
-1
panikdb/urls.py
panikdb/urls.py
+6
-0
panikdb/views.py
panikdb/views.py
+25
-0
No files found.
panikdb/customtags/templatetags/panikdbtags.py
View file @
6287dfa4
...
...
@@ -3,6 +3,7 @@ from django.conf import settings
from
django.core.urlresolvers
import
reverse
from
emissions.models
import
Emission
,
Episode
,
NewsItem
,
SoundFile
,
Focus
from
panikombo.models
import
Topik
from
combo.data.models
import
Page
register
=
Library
()
...
...
@@ -54,6 +55,8 @@ def has_focus(object):
object_type
=
'episode'
elif
isinstance
(
object
,
SoundFile
):
object_type
=
'soundfile'
elif
isinstance
(
object
,
Page
):
object_type
=
'page'
else
:
return
False
try
:
...
...
@@ -73,6 +76,8 @@ def unset_focus_url(object):
object_type
=
'episode'
elif
isinstance
(
object
,
SoundFile
):
object_type
=
'soundfile'
elif
isinstance
(
object
,
Page
):
object_type
=
'page'
return
reverse
(
'focus-unset'
,
kwargs
=
{
'object_type'
:
object_type
,
'object_id'
:
object
.
id
})
...
...
@@ -88,6 +93,8 @@ def set_focus_url(object):
object_type
=
'episode'
elif
isinstance
(
object
,
SoundFile
):
object_type
=
'soundfile'
elif
isinstance
(
object
,
Page
):
object_type
=
'page'
return
reverse
(
'focus-set'
,
kwargs
=
{
'object_type'
:
object_type
,
'object_id'
:
object
.
id
})
...
...
@@ -102,6 +109,12 @@ def can_focus(object):
return
True
elif
isinstance
(
object
,
SoundFile
):
return
bool
(
object
.
format
)
elif
isinstance
(
object
,
Page
):
try
:
topik
=
Topik
.
objects
.
get
(
page
=
object
)
except
Topik
.
DoesNotExist
:
return
False
return
bool
(
topik
.
image
)
return
False
...
...
@@ -110,3 +123,16 @@ def as_duration(value):
if
not
value
:
return
'-'
return
'%s:%02d'
%
(
value
/
60
,
value
%
60
)
@
register
.
filter
def
is_page
(
obj
):
return
isinstance
(
obj
,
Page
)
@
register
.
filter
def
has_topik
(
obj
):
return
Topik
.
objects
.
filter
(
page
=
obj
).
count
()
==
1
@
register
.
filter
def
topik_id
(
obj
):
return
Topik
.
objects
.
get
(
page
=
obj
).
id
panikdb/templates/combo/manager_base.html
View file @
6287dfa4
{% extends "base.html" %}
{% load static %}
{% load static
panikdbtags
%}
{% block extrascripts %}
<script
src=
"{% static "
ckeditor
/
ckeditor
/
ckeditor.js
"
%}"
></script>
...
...
@@ -11,6 +11,15 @@
{% block more-user-links %}
<a
href=
"{% url 'combo-manager-homepage' %}"
>
Pages
</a>
{% if object|is_page %}
{% if object|has_topik %}
{% with object|topik_id as topik_id %}
<a
rel=
"popup"
href=
"{% url 'edit-topik' pk=topik_id %}"
>
Options de Topik
</a>
{% endwith %}
{% else %}
<a
href=
"{% url 'make-topik' page_pk=object.id %}"
>
Transformer en Topik
</a>
{% endif %}
{% endif %}
{% endblock %}
{% block bodyattr %}class="combo"{% endblock %}
panikdb/urls.py
View file @
6287dfa4
...
...
@@ -55,10 +55,16 @@ urlpatterns = patterns('',
url
(
r
'^focus/unset/(?P<object_type>[\w,-]+)/(?P<object_id>\d+)$'
,
'panikdb.views.focus_unset'
,
name
=
'focus-unset'
),
url
(
r
'^cms/pages/(?P<page_pk>\w+)/make-topik$'
,
'panikdb.views.make_topik'
,
name
=
'make-topik'
),
url
(
r
'^cms/pages/topik/(?P<pk>\w+)/edit-topik$'
,
'panikombo.views.topik_edit'
,
name
=
'edit-topik'
),
url
(
r
'^accounts/logout/'
,
'django.contrib.auth.views.logout_then_login'
,
name
=
'logout'
),
url
(
r
'^accounts/'
,
include
(
'registration.backends.default.urls'
)),
url
(
r
'^combok/soundfiles/'
,
'panikombo.views.soundfiles'
),
url
(
r
'^combok/episodes/'
,
'panikombo.views.episodes'
),
url
(
r
'^admin/'
,
include
(
admin
.
site
.
urls
)),
)
...
...
panikdb/views.py
View file @
6287dfa4
...
...
@@ -7,9 +7,12 @@ from django.template import loader, Context
from
django.views.generic.base
import
TemplateView
,
RedirectView
from
django.views.generic.list
import
ListView
from
django.contrib
import
messages
from
django.shortcuts
import
redirect
from
emissions.models
import
*
from
emissions.utils
import
period_program
from
panikombo.models
import
Topik
from
combo.data.models
import
Page
import
emissions.views
import
newsletter.views
...
...
@@ -147,6 +150,16 @@ class FocusSetView(RedirectView):
'slug'
:
soundfile
.
episode
.
slug
,
'emission_slug'
:
soundfile
.
episode
.
emission
.
slug
,
})
if
object_type
==
'page'
:
page
=
Page
.
objects
.
get
(
id
=
object_id
)
try
:
f
=
Focus
.
objects
.
get
(
page
=
page
)
except
Focus
.
DoesNotExist
:
f
=
Focus
()
f
.
current
=
True
f
.
page
=
page
f
.
save
()
return
reverse
(
'combo-manager-page-view'
,
kwargs
=
{
'pk'
:
object_id
})
focus_set
=
FocusSetView
.
as_view
()
...
...
@@ -186,5 +199,17 @@ class FocusUnsetView(RedirectView):
'slug'
:
soundfile
.
episode
.
slug
,
'emission_slug'
:
soundfile
.
episode
.
emission
.
slug
,
})
if
object_type
==
'page'
:
focus
=
Focus
.
objects
.
get
(
page
=
object_id
)
focus
.
current
=
False
focus
.
save
()
return
reverse
(
'combo-manager-page-view'
,
kwargs
=
{
'pk'
:
object_id
})
focus_unset
=
FocusUnsetView
.
as_view
()
def
make_topik
(
request
,
page_pk
):
if
Topik
.
objects
.
filter
(
page__id
=
page_pk
).
count
():
raise
Exception
(
'page already associated to topik'
)
topik
=
Topik
(
page_id
=
page_pk
)
topik
.
save
()
return
redirect
(
'combo-manager-page-view'
,
pk
=
page_pk
)
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