This repository was archived by the owner on Nov 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 178
Expand file tree
/
Copy pathcms_plugins.py
More file actions
67 lines (57 loc) · 1.8 KB
/
cms_plugins.py
File metadata and controls
67 lines (57 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.templatetags.static import static
from django.utils.translation import ugettext as _
from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
from .forms import FilerLinkForm
from .models import FilerLinkPlugin as FilerLinkPluginModel
class FilerLinkPlugin(CMSPluginBase):
form = FilerLinkForm
model = FilerLinkPluginModel
module = _('Filer')
name = _("Link")
raw_id_fields = ('page_link', )
render_template = "cmsplugin_filer_link/link.html"
text_enabled = True
fieldsets = (
(None, {
'fields': [
'name',
'url',
'page_link',
'mailto',
'file',
'link_style',
'new_window',
]
}),
(_('Advanced'), {
'classes': ['collapse', ],
'fields': [
'link_attributes',
]
})
)
def render(self, context, instance, placeholder):
context = super(FilerLinkPlugin, self).render(context, instance, placeholder)
if instance.file:
link = instance.file.url
elif instance.mailto:
link = "mailto:%s" % _(instance.mailto)
elif instance.url:
link = _(instance.url)
elif instance.page_link:
link = instance.page_link.get_absolute_url()
else:
link = ""
context.update({
'link': link,
'style': instance.link_style,
'name': instance.name,
'new_window': instance.new_window,
})
return context
def icon_src(self, instance):
return static("cms/img/icons/plugins/link.png")
plugin_pool.register_plugin(FilerLinkPlugin)