root / cloudcms / content.py @ c1468bcc
History | View | Annotate | Download (5.2 kB)
1 |
from django.contrib.markup.templatetags.markup import textile |
---|---|
2 |
from django.db import models |
3 |
from django import forms |
4 |
from django.conf import settings |
5 |
from django.utils.translation import ugettext_lazy as _ |
6 |
from django.template.loader import render_to_string |
7 |
from django.utils import simplejson |
8 |
|
9 |
from feincms.admin.editor import ItemEditorForm |
10 |
from feincms.module.page.models import Page |
11 |
from feincms.module.medialibrary.models import MediaFile |
12 |
from feincms.content.medialibrary.models import MediaFileWidget |
13 |
from feincms.module.medialibrary.fields import MediaFileForeignKey |
14 |
|
15 |
|
16 |
DEFAULT_JQ_TWITTER_URL = settings.MEDIA_URL + 'cloudcms/' + 'js/' + 'twitter/' + \ |
17 |
'jquery.twitter.js'
|
18 |
DEFAULT_LINKIFY_URL = settings.MEDIA_URL + 'cloudcms/' + 'js/' + 'twitter/' + \ |
19 |
'ba-linkify.js'
|
20 |
DEFAULT_JQ_TIMEAGO_URL = settings.MEDIA_URL + 'cloudcms/' + 'js/' + 'twitter/' + \ |
21 |
'jquery.timeago.js'
|
22 |
JQUERY_TWITTER_URL = getattr(settings, "JQUERY_TWITTER_URL", |
23 |
DEFAULT_JQ_TWITTER_URL) |
24 |
LINKIFY_JS_URL = getattr(settings, "LINKIFY_JS_URL", |
25 |
DEFAULT_LINKIFY_URL) |
26 |
JQUERY_TIMEAGO_URL = getattr(settings, "JQUERY_TIMEAGO_URL", |
27 |
DEFAULT_JQ_TIMEAGO_URL) |
28 |
|
29 |
|
30 |
class VideoSection(models.Model): |
31 |
section_title = models.CharField(max_length=200, blank=True) |
32 |
video_title = models.CharField(max_length=200, blank=True) |
33 |
video_link = models.CharField(max_length=200, blank=True) |
34 |
video_width = models.PositiveIntegerField(default=700)
|
35 |
video_height = models.PositiveIntegerField(default=550)
|
36 |
image = MediaFileForeignKey(MediaFile, blank=True, null=True, |
37 |
related_name="as_image_for_video_section")
|
38 |
image_hover = MediaFileForeignKey(MediaFile, blank=True, null=True, |
39 |
related_name="as_hover_for_video_section")
|
40 |
alt_text = models.TextField(null=True, blank=True) |
41 |
extra_url_params = models.CharField(max_length=200, blank=True) |
42 |
|
43 |
class Meta: |
44 |
abstract = True
|
45 |
verbose_name = _('video section')
|
46 |
verbose_name_plural = _('video sections')
|
47 |
|
48 |
def render(self, **kwargs): |
49 |
return render_to_string(['content/videosection.html'], {'content': self}) |
50 |
|
51 |
|
52 |
class TwitterFeed(models.Model): |
53 |
title = models.CharField(max_length=200, blank=True) |
54 |
account = models.CharField(max_length=200, blank=True) |
55 |
nots = models.CharField(max_length=200, help_text="Ugly words", blank=True) |
56 |
query = models.CharField(max_length=200, blank=True, |
57 |
help_text="Filter query")
|
58 |
tag = models.CharField(max_length=200, blank=True, help_text="Hashtag") |
59 |
limit = models.PositiveIntegerField(default=10)
|
60 |
replies = models.BooleanField(default=True)
|
61 |
retweets = models.BooleanField(default=True)
|
62 |
avatar = models.BooleanField(default=False)
|
63 |
extra_params = models.TextField(blank=True,
|
64 |
help_text="Json object to append to "
|
65 |
"JQuery-twitter-plugin settings. Change "
|
66 |
"this only if you know what you are doing.")
|
67 |
|
68 |
class Meta: |
69 |
abstract = True
|
70 |
verbose_name = _('twitter feed')
|
71 |
verbose_name_plural = _('twitter feeds')
|
72 |
|
73 |
@property
|
74 |
def media(self): |
75 |
return forms.Media(js=(
|
76 |
LINKIFY_JS_URL, JQUERY_TWITTER_URL, JQUERY_TIMEAGO_URL |
77 |
)) |
78 |
|
79 |
def js_conf(self): |
80 |
conf = {} |
81 |
if self.account: |
82 |
conf['from'] = self.account |
83 |
|
84 |
for f in ['nots', 'query', 'tag', 'limit', 'replies', 'retweets', 'avatar']: |
85 |
if type(getattr(self, f)) == bool: |
86 |
conf[f] = getattr(self, f) |
87 |
|
88 |
if getattr(self, f): |
89 |
conf[f] = getattr(self, f) |
90 |
|
91 |
xtraconf = {} |
92 |
try:
|
93 |
xtraconf = simplejson.loads(self.extra_params)
|
94 |
except:
|
95 |
pass
|
96 |
|
97 |
conf.update(xtraconf) |
98 |
return simplejson.dumps(conf)
|
99 |
|
100 |
|
101 |
def render(self, **kwargs): |
102 |
return render_to_string(['content/twitter_feed.html'], {'content': self}) |
103 |
|
104 |
|
105 |
class AboutBlock(models.Model): |
106 |
|
107 |
title = models.CharField(max_length=200, blank=False) |
108 |
content = models.TextField(blank=False)
|
109 |
image = MediaFileForeignKey(MediaFile, blank=True, null=True) |
110 |
image_position = models.CharField(max_length=200,
|
111 |
choices=(('top', 'Top'), ('left', 'Left'), ('right', 'Right'))) |
112 |
color = models.CharField(max_length=200, blank=False) |
113 |
offset_left = models.IntegerField(null=True, blank=True) |
114 |
offset_top = models.IntegerField(null=True, blank=True) |
115 |
|
116 |
class Meta: |
117 |
abstract = True
|
118 |
verbose_name = _('about page block')
|
119 |
verbose_name_plural = _('about page blocks')
|
120 |
|
121 |
def render(self, **kwargs): |
122 |
return render_to_string(['content/about_block.html'], {'content': self}) |
123 |
|
124 |
|
125 |
class LoginForm(models.Model): |
126 |
"""
|
127 |
Login form
|
128 |
"""
|
129 |
|
130 |
title = models.CharField(_('title'), max_length=200, blank=False) |
131 |
action_url = models.CharField(_('im url'), max_length=100, blank=False) |
132 |
display_forgot_password = models.BooleanField(default=False, null=False) |
133 |
next_url = models.CharField(max_length=255, null=True, blank=True) |
134 |
|
135 |
class Meta: |
136 |
abstract = True
|
137 |
verbose_name = _('login form')
|
138 |
verbose_name_plural = _('login forms')
|
139 |
|
140 |
def render(self, **kwargs): |
141 |
return render_to_string(['content/login_form.html'], {'content': self}) |
142 |
|