Revision 5cc874ca cloudcms/content.py
b/cloudcms/content.py | ||
---|---|---|
39 | 39 |
from django.utils.translation import ugettext_lazy as _ |
40 | 40 |
from django.template.loader import render_to_string |
41 | 41 |
from django.utils import simplejson |
42 |
from django.utils.html import mark_safe |
|
42 | 43 |
|
43 | 44 |
from feincms.admin.editor import ItemEditorForm |
44 | 45 |
from feincms.module.page.models import Page |
... | ... | |
47 | 48 |
from feincms.module.medialibrary.fields import MediaFileForeignKey |
48 | 49 |
|
49 | 50 |
|
50 |
DEFAULT_JQ_TWITTER_URL = settings.MEDIA_URL + 'cloudcms/' + 'js/' + 'twitter/' + \ |
|
51 |
'jquery.twitter.js' |
|
52 |
DEFAULT_LINKIFY_URL = settings.MEDIA_URL + 'cloudcms/' + 'js/' + 'twitter/' + \ |
|
53 |
'ba-linkify.js' |
|
54 |
DEFAULT_JQ_TIMEAGO_URL = settings.MEDIA_URL + 'cloudcms/' + 'js/' + 'twitter/' + \ |
|
55 |
'jquery.timeago.js' |
|
56 |
JQUERY_TWITTER_URL = getattr(settings, "JQUERY_TWITTER_URL", |
|
57 |
DEFAULT_JQ_TWITTER_URL) |
|
58 |
LINKIFY_JS_URL = getattr(settings, "LINKIFY_JS_URL", |
|
59 |
DEFAULT_LINKIFY_URL) |
|
60 |
JQUERY_TIMEAGO_URL = getattr(settings, "JQUERY_TIMEAGO_URL", |
|
61 |
DEFAULT_JQ_TIMEAGO_URL) |
|
51 |
TWITTER_LOAD_CODE = getattr(settings, 'CLOUDCMS_TWITTER_LOAD_CODE', |
|
52 |
"""!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");""") |
|
62 | 53 |
|
63 | 54 |
class VideoSection(models.Model): |
64 | 55 |
section_title = models.CharField(max_length=200, blank=True) |
... | ... | |
82 | 73 |
return render_to_string(['content/videosection.html'], {'content': self}) |
83 | 74 |
|
84 | 75 |
|
76 |
TWITTER_HELP_DESC = mark_safe(""" |
|
77 |
See <a |
|
78 |
href="https://dev.twitter.com/docs/embedded-timelines">embedded timelines |
|
79 |
documentation</a> |
|
80 |
""") |
|
81 |
|
|
85 | 82 |
class TwitterFeed(models.Model): |
86 | 83 |
title = models.CharField(max_length=200, blank=True) |
87 |
account = models.CharField(max_length=200, blank=True) |
|
88 |
nots = models.CharField(max_length=200, help_text="Ugly words", blank=True) |
|
89 |
query = models.CharField(max_length=200, blank=True, |
|
90 |
help_text="Filter query") |
|
91 |
tag = models.CharField(max_length=200, blank=True, help_text="Hashtag") |
|
92 |
limit = models.PositiveIntegerField(default=10) |
|
93 |
replies = models.BooleanField(default=True) |
|
94 |
retweets = models.BooleanField(default=True) |
|
95 |
avatar = models.BooleanField(default=False) |
|
96 |
extra_params = models.TextField(blank=True, |
|
97 |
help_text="Json object to append to " |
|
98 |
"JQuery-twitter-plugin settings. Change " |
|
99 |
"this only if you know what you are doing.") |
|
84 |
widget_id = models.CharField(max_length=200, blank=True, |
|
85 |
help_text= mark_safe(_(""" |
|
86 |
Widget id from |
|
87 |
<a href=https://twitter.com/settings/widgets>Twitter widgets</a> |
|
88 |
"""))) |
|
89 |
|
|
90 |
limit = models.PositiveIntegerField(default=10, |
|
91 |
help_text="Number of tweets to be displayed") |
|
92 |
theme = models.CharField(max_length=200, blank=True, default="light", |
|
93 |
help_text=TWITTER_HELP_DESC) |
|
94 |
link_color = models.CharField(max_length=200, blank=True, default="#F89A1C", |
|
95 |
help_text=TWITTER_HELP_DESC) |
|
96 |
chrome = models.CharField(max_length=200, blank=True, default="noscrollbar nofooter noheader noborders", |
|
97 |
help_text=TWITTER_HELP_DESC) |
|
98 |
screen_name = models.CharField(max_length=200, blank=True, |
|
99 |
help_text=TWITTER_HELP_DESC) |
|
100 |
custom_timeline_id = models.CharField(max_length=200, blank=True, |
|
101 |
help_text=TWITTER_HELP_DESC) |
|
102 |
favorites_screen_name = models.CharField(max_length=200, blank=True, |
|
103 |
help_text=TWITTER_HELP_DESC) |
|
104 |
list_owner_screen_name = models.CharField(max_length=200, blank=True, |
|
105 |
help_text=TWITTER_HELP_DESC) |
|
106 |
list_slug = models.CharField(max_length=200, blank=True, |
|
107 |
help_text=TWITTER_HELP_DESC) |
|
108 |
aria_politeness = models.CharField(max_length=200, blank=True, |
|
109 |
help_text=TWITTER_HELP_DESC) |
|
110 |
border_color = models.CharField(max_length=200, blank=True, |
|
111 |
help_text=TWITTER_HELP_DESC) |
|
112 |
height = models.CharField(max_length=200, blank=True, |
|
113 |
help_text=TWITTER_HELP_DESC) |
|
114 |
extra_attributes = models.TextField(blank=True, |
|
115 |
help_text="Extra code to be applied within the html element") |
|
116 |
|
|
117 |
code = models.TextField(blank=True, |
|
118 |
help_text="Twitter loading code. " |
|
119 |
"Leave empty for default javascript code to be used.") |
|
100 | 120 |
|
101 | 121 |
class Meta: |
102 | 122 |
abstract = True |
103 | 123 |
verbose_name = _('twitter feed') |
104 | 124 |
verbose_name_plural = _('twitter feeds') |
105 | 125 |
|
106 |
@property |
|
107 |
def media(self): |
|
108 |
return forms.Media(js=( |
|
109 |
LINKIFY_JS_URL, JQUERY_TWITTER_URL, JQUERY_TIMEAGO_URL |
|
110 |
)) |
|
111 |
|
|
112 |
def js_conf(self): |
|
113 |
conf = {} |
|
114 |
if self.account: |
|
115 |
conf['from'] = self.account |
|
116 |
|
|
117 |
for f in ['nots', 'query', 'tag', 'limit', 'replies', 'retweets', 'avatar']: |
|
118 |
if type(getattr(self, f)) == bool: |
|
119 |
conf[f] = getattr(self, f) |
|
120 |
|
|
121 |
if getattr(self, f): |
|
122 |
conf[f] = getattr(self, f) |
|
123 |
|
|
124 |
xtraconf = {} |
|
125 |
try: |
|
126 |
xtraconf = simplejson.loads(self.extra_params) |
|
127 |
except: |
|
128 |
pass |
|
129 |
|
|
130 |
conf.update(xtraconf) |
|
131 |
return simplejson.dumps(conf) |
|
132 |
|
|
133 |
|
|
134 | 126 |
def render(self, **kwargs): |
135 |
return render_to_string(['content/twitter_feed.html'], {'content': self}) |
|
127 |
return render_to_string(['content/twitter_feed.html'], { |
|
128 |
'content': self, |
|
129 |
'load_code': self.code if self.code else "<script>%s</script>" % (TWITTER_LOAD_CODE) |
|
130 |
}) |
|
136 | 131 |
|
137 | 132 |
|
138 | 133 |
class AboutBlock(models.Model): |
... | ... | |
205 | 200 |
|
206 | 201 |
def render(self, **kwargs): |
207 | 202 |
return textile(self.content) |
208 |
|
|
203 |
|
|
209 | 204 |
class IntroBlock(models.Model): |
210 | 205 |
title = models.CharField(_('title'), max_length=200, blank=False) |
211 | 206 |
content = models.TextField() |
... | ... | |
230 | 225 |
|
231 | 226 |
def render(self, **kwargs): |
232 | 227 |
return render_to_string(['content/block_with_color.html'], {'content': self}) |
233 |
|
|
228 |
|
|
234 | 229 |
|
235 | 230 |
class ClientDownload(models.Model): |
236 | 231 |
|
... | ... | |
251 | 246 |
|
252 | 247 |
|
253 | 248 |
class StatsBlock(models.Model): |
254 |
|
|
249 |
|
|
255 | 250 |
@property |
256 | 251 |
def media(self): |
257 | 252 |
return forms.Media(js=( |
258 | 253 |
settings.MEDIA_URL + 'cloudcms/' + 'js/' + 'service-stats.js',)) |
259 | 254 |
|
260 |
title = models.CharField(_('title'), max_length=200, blank=True)
|
|
255 |
title = models.CharField(_('title'), max_length=200, blank=True) |
|
261 | 256 |
color = models.CharField(max_length=200, blank=True, null=True) |
262 | 257 |
running_vms = models.BooleanField(default=False, help_text = "ACTIVE VMs") |
263 | 258 |
spawned_vms = models.BooleanField(default=True, help_text= "All VMs") |
... | ... | |
276 | 271 |
title_spawned_networks = models.CharField(max_length=255,blank=True, null=True) |
277 | 272 |
title_active_networks = models.CharField(max_length=255,blank=True, null=True) |
278 | 273 |
compute_url = models.CharField(max_length=255,blank=True, null=True) |
279 |
|
|
274 |
|
|
280 | 275 |
class Meta: |
281 | 276 |
abstract = True |
282 | 277 |
|
... | ... | |
292 | 287 |
|
293 | 288 |
image = MediaFileForeignKey(MediaFile, blank=True, null=True) |
294 | 289 |
youtube_id = models.CharField(max_length=255,blank=True, null=True) |
295 |
|
|
290 |
|
|
296 | 291 |
class Meta: |
297 | 292 |
abstract = True |
298 | 293 |
|
299 | 294 |
def render(self, **kwargs): |
300 |
return render_to_string(['content/intro_video.html'], {'content': self}) |
|
295 |
return render_to_string(['content/intro_video.html'], {'content': self}) |
Also available in: Unified diff