root / cloudcms / content.py @ f334ea63
History | View | Annotate | Download (6.8 kB)
1 |
# Copyright 2012 GRNET S.A. All rights reserved.
|
---|---|
2 |
#
|
3 |
# Redistribution and use in source and binary forms, with or
|
4 |
# without modification, are permitted provided that the following
|
5 |
# conditions are met:
|
6 |
#
|
7 |
# 1. Redistributions of source code must retain the above
|
8 |
# copyright notice, this list of conditions and the following
|
9 |
# disclaimer.
|
10 |
#
|
11 |
# 2. Redistributions in binary form must reproduce the above
|
12 |
# copyright notice, this list of conditions and the following
|
13 |
# disclaimer in the documentation and/or other materials
|
14 |
# provided with the distribution.
|
15 |
#
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 |
# POSSIBILITY OF SUCH DAMAGE.
|
28 |
#
|
29 |
# The views and conclusions contained in the software and
|
30 |
# documentation are those of the authors and should not be
|
31 |
# interpreted as representing official policies, either expressed
|
32 |
# or implied, of GRNET S.A.
|
33 |
|
34 |
|
35 |
from django.contrib.markup.templatetags.markup import textile |
36 |
from django.db import models |
37 |
from django import forms |
38 |
from django.conf import settings |
39 |
from django.utils.translation import ugettext_lazy as _ |
40 |
from django.template.loader import render_to_string |
41 |
from django.utils import simplejson |
42 |
|
43 |
from feincms.admin.editor import ItemEditorForm |
44 |
from feincms.module.page.models import Page |
45 |
from feincms.module.medialibrary.models import MediaFile |
46 |
from feincms.content.medialibrary.models import MediaFileWidget |
47 |
from feincms.module.medialibrary.fields import MediaFileForeignKey |
48 |
|
49 |
|
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) |
62 |
|
63 |
class VideoSection(models.Model): |
64 |
section_title = models.CharField(max_length=200, blank=True) |
65 |
video_title = models.CharField(max_length=200, blank=True) |
66 |
video_link = models.CharField(max_length=200, blank=True) |
67 |
video_width = models.PositiveIntegerField(default=700)
|
68 |
video_height = models.PositiveIntegerField(default=550)
|
69 |
image = MediaFileForeignKey(MediaFile, blank=True, null=True, |
70 |
related_name="as_image_for_video_section")
|
71 |
image_hover = MediaFileForeignKey(MediaFile, blank=True, null=True, |
72 |
related_name="as_hover_for_video_section")
|
73 |
alt_text = models.TextField(null=True, blank=True) |
74 |
extra_url_params = models.CharField(max_length=200, blank=True) |
75 |
|
76 |
class Meta: |
77 |
abstract = True
|
78 |
verbose_name = _('video section')
|
79 |
verbose_name_plural = _('video sections')
|
80 |
|
81 |
def render(self, **kwargs): |
82 |
return render_to_string(['content/videosection.html'], {'content': self}) |
83 |
|
84 |
|
85 |
class TwitterFeed(models.Model): |
86 |
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.")
|
100 |
|
101 |
class Meta: |
102 |
abstract = True
|
103 |
verbose_name = _('twitter feed')
|
104 |
verbose_name_plural = _('twitter feeds')
|
105 |
|
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 |
def render(self, **kwargs): |
135 |
return render_to_string(['content/twitter_feed.html'], {'content': self}) |
136 |
|
137 |
|
138 |
class AboutBlock(models.Model): |
139 |
|
140 |
title = models.CharField(max_length=200, blank=False) |
141 |
content = models.TextField(blank=False)
|
142 |
image = MediaFileForeignKey(MediaFile, blank=True, null=True) |
143 |
image_position = models.CharField(max_length=200,
|
144 |
choices=(('top', 'Top'), ('left', 'Left'), ('right', 'Right'))) |
145 |
color = models.CharField(max_length=200, blank=False) |
146 |
offset_left = models.IntegerField(null=True, blank=True) |
147 |
offset_top = models.IntegerField(null=True, blank=True) |
148 |
|
149 |
class Meta: |
150 |
abstract = True
|
151 |
verbose_name = _('about page block')
|
152 |
verbose_name_plural = _('about page blocks')
|
153 |
|
154 |
def render(self, **kwargs): |
155 |
return render_to_string(['content/about_block.html'], {'content': self}) |
156 |
|
157 |
|
158 |
class LoginForm(models.Model): |
159 |
"""
|
160 |
Login form
|
161 |
"""
|
162 |
|
163 |
title = models.CharField(_('title'), max_length=200, blank=False) |
164 |
action_url = models.CharField(_('im url'), max_length=100, blank=False) |
165 |
display_forgot_password = models.BooleanField(default=False, null=False) |
166 |
next_url = models.CharField(max_length=255, null=True, blank=True) |
167 |
bottom_content = models.TextField(blank=True)
|
168 |
logged_in_content = models.TextField(blank=True)
|
169 |
|
170 |
class Meta: |
171 |
abstract = True
|
172 |
verbose_name = _('login form')
|
173 |
verbose_name_plural = _('login forms')
|
174 |
|
175 |
def render(self, **kwargs): |
176 |
return render_to_string(['content/login_form.html'], {'content': self}) |
177 |
|