1 # Copyright 2012 GRNET S.A. All rights reserved.
3 # Redistribution and use in source and binary forms, with or
4 # without modification, are permitted provided that the following
7 # 1. Redistributions of source code must retain the above
8 # copyright notice, this list of conditions and the following
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.
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.
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.
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
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
50 DEFAULT_JQ_TWITTER_URL = settings.MEDIA_URL + 'cloudcms/' + 'js/' + 'twitter/' + \
52 DEFAULT_LINKIFY_URL = settings.MEDIA_URL + 'cloudcms/' + 'js/' + 'twitter/' + \
54 DEFAULT_JQ_TIMEAGO_URL = settings.MEDIA_URL + 'cloudcms/' + 'js/' + 'twitter/' + \
56 JQUERY_TWITTER_URL = getattr(settings, "JQUERY_TWITTER_URL",
57 DEFAULT_JQ_TWITTER_URL)
58 LINKIFY_JS_URL = getattr(settings, "LINKIFY_JS_URL",
60 JQUERY_TIMEAGO_URL = getattr(settings, "JQUERY_TIMEAGO_URL",
61 DEFAULT_JQ_TIMEAGO_URL)
64 class VideoSection(models.Model):
65 section_title = models.CharField(max_length=200, blank=True)
66 video_title = models.CharField(max_length=200, blank=True)
67 video_link = models.CharField(max_length=200, blank=True)
68 video_width = models.PositiveIntegerField(default=700)
69 video_height = models.PositiveIntegerField(default=550)
70 image = MediaFileForeignKey(MediaFile, blank=True, null=True,
71 related_name="as_image_for_video_section")
72 image_hover = MediaFileForeignKey(MediaFile, blank=True, null=True,
73 related_name="as_hover_for_video_section")
74 alt_text = models.TextField(null=True, blank=True)
75 extra_url_params = models.CharField(max_length=200, blank=True)
79 verbose_name = _('video section')
80 verbose_name_plural = _('video sections')
82 def render(self, **kwargs):
83 return render_to_string(['content/videosection.html'], {'content': self})
86 class TwitterFeed(models.Model):
87 title = models.CharField(max_length=200, blank=True)
88 account = models.CharField(max_length=200, blank=True)
89 nots = models.CharField(max_length=200, help_text="Ugly words", blank=True)
90 query = models.CharField(max_length=200, blank=True,
91 help_text="Filter query")
92 tag = models.CharField(max_length=200, blank=True, help_text="Hashtag")
93 limit = models.PositiveIntegerField(default=10)
94 replies = models.BooleanField(default=True)
95 retweets = models.BooleanField(default=True)
96 avatar = models.BooleanField(default=False)
97 extra_params = models.TextField(blank=True,
98 help_text="Json object to append to "
99 "JQuery-twitter-plugin settings. Change "
100 "this only if you know what you are doing.")
104 verbose_name = _('twitter feed')
105 verbose_name_plural = _('twitter feeds')
109 return forms.Media(js=(
110 LINKIFY_JS_URL, JQUERY_TWITTER_URL, JQUERY_TIMEAGO_URL
116 conf['from'] = self.account
118 for f in ['nots', 'query', 'tag', 'limit', 'replies', 'retweets', 'avatar']:
119 if type(getattr(self, f)) == bool:
120 conf[f] = getattr(self, f)
123 conf[f] = getattr(self, f)
127 xtraconf = simplejson.loads(self.extra_params)
131 conf.update(xtraconf)
132 return simplejson.dumps(conf)
135 def render(self, **kwargs):
136 return render_to_string(['content/twitter_feed.html'], {'content': self})
139 class AboutBlock(models.Model):
141 title = models.CharField(max_length=200, blank=False)
142 content = models.TextField(blank=False)
143 image = MediaFileForeignKey(MediaFile, blank=True, null=True)
144 image_position = models.CharField(max_length=200,
145 choices=(('top', 'Top'), ('left', 'Left'), ('right', 'Right')))
146 color = models.CharField(max_length=200, blank=False)
147 offset_left = models.IntegerField(null=True, blank=True)
148 offset_top = models.IntegerField(null=True, blank=True)
152 verbose_name = _('about page block')
153 verbose_name_plural = _('about page blocks')
155 def render(self, **kwargs):
156 return render_to_string(['content/about_block.html'], {'content': self})
159 class LoginForm(models.Model):
164 title = models.CharField(_('title'), max_length=200, blank=False)
165 action_url = models.CharField(_('im url'), max_length=100, blank=False)
166 display_forgot_password = models.BooleanField(default=False, null=False)
167 next_url = models.CharField(max_length=255, null=True, blank=True)
171 verbose_name = _('login form')
172 verbose_name_plural = _('login forms')
174 def render(self, **kwargs):
175 return render_to_string(['content/login_form.html'], {'content': self})