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)
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)
78 verbose_name = _('video section')
79 verbose_name_plural = _('video sections')
81 def render(self, **kwargs):
82 return render_to_string(['content/videosection.html'], {'content': self})
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.")
103 verbose_name = _('twitter feed')
104 verbose_name_plural = _('twitter feeds')
108 return forms.Media(js=(
109 LINKIFY_JS_URL, JQUERY_TWITTER_URL, JQUERY_TIMEAGO_URL
115 conf['from'] = self.account
117 for f in ['nots', 'query', 'tag', 'limit', 'replies', 'retweets', 'avatar']:
118 if type(getattr(self, f)) == bool:
119 conf[f] = getattr(self, f)
122 conf[f] = getattr(self, f)
126 xtraconf = simplejson.loads(self.extra_params)
130 conf.update(xtraconf)
131 return simplejson.dumps(conf)
134 def render(self, **kwargs):
135 return render_to_string(['content/twitter_feed.html'], {'content': self})
138 class AboutBlock(models.Model):
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)
151 verbose_name = _('about page block')
152 verbose_name_plural = _('about page blocks')
154 def render(self, **kwargs):
155 return render_to_string(['content/about_block.html'], {'content': self})
158 class LoginForm(models.Model):
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)
172 verbose_name = _('login form')
173 verbose_name_plural = _('login forms')
175 def render(self, **kwargs):
176 return render_to_string(['content/login_form.html'], {'content': self})
179 class IntroButton(models.Model):
183 verbose_name = _('intro images')
184 verbose_name_plural = _('intro images')
186 image_1 = MediaFileForeignKey(MediaFile, blank=True, null=True,
187 related_name="as_image1")
188 image_2 = MediaFileForeignKey(MediaFile, blank=True, null=True,
189 related_name="as_image2")
190 image_3 = MediaFileForeignKey(MediaFile, blank=True, null=True,
191 related_name="as_image3")
192 link = models.CharField(max_length=255, blank=False, default="/welcome")
193 link_title = models.CharField(max_length=255, blank=False, default="~okeanos")
195 def render(self, **kwargs):
196 return render_to_string(['content/intro_images.html'], {'content': self})
200 class TextileContent(models.Model):
201 content = models.TextField()
206 def render(self, **kwargs):
207 return textile(self.content)
209 class IntroBlock(models.Model):
210 title = models.CharField(_('title'), max_length=200, blank=False)
211 content = models.TextField()
212 class_name = models.CharField(_('class_name'), max_length=200, blank=True, null=True)
213 image = MediaFileForeignKey(MediaFile, blank=True, null=True)
218 def render(self, **kwargs):
219 return render_to_string(['content/intro_block.html'], {'content': self})
222 class BlockColor(models.Model):
223 title = models.CharField(_('title'), max_length=200, blank=False)
224 content = models.TextField()
225 color = models.CharField(max_length=200, blank=True, null=True)
226 image = MediaFileForeignKey(MediaFile, blank=True, null=True)
231 def render(self, **kwargs):
232 return render_to_string(['content/block_with_color.html'], {'content': self})
235 class ClientDownload(models.Model):
237 client = models.ForeignKey('cloudcms.Client')
241 return forms.Media(js=(
242 settings.MEDIA_URL + 'cloudcms/' + 'js/' + 'client-downloads.js',))
246 verbose_name = _('client download')
247 verbose_name_plural = _('client downloads')
249 def render(self, **kwrags):
250 return render_to_string(['content/client_downloads.html'], {'content': self})
253 class StatsBlock(models.Model):
257 return forms.Media(js=(
258 settings.MEDIA_URL + 'cloudcms/' + 'js/' + 'service-stats.js',))
260 title = models.CharField(_('title'), max_length=200, blank=True)
261 color = models.CharField(max_length=200, blank=True, null=True)
262 running_vms = models.BooleanField(default=False, help_text = "ACTIVE VMs")
263 spawned_vms = models.BooleanField(default=True, help_text= "All VMs")
264 active_vms = models.BooleanField(default=True, help_text ="All VMs - \
266 running_networks = models.BooleanField(default=False, help_text = "ACTIVE \
268 spawned_networks = models.BooleanField(default=True,help_text= "All \
270 active_networks = models.BooleanField(default=False, help_text ="All \
271 Networks - DELETED Networks")
272 title_running_vms = models.CharField(max_length=255,blank=True, null=True)
273 title_spawned_vms = models.CharField(max_length=255,blank=True, null=True)
274 title_active_vms = models.CharField(max_length=255,blank=True, null=True)
275 title_running_networks = models.CharField(max_length=255,blank=True, null=True)
276 title_spawned_networks = models.CharField(max_length=255,blank=True, null=True)
277 title_active_networks = models.CharField(max_length=255,blank=True, null=True)
278 compute_url = models.CharField(max_length=255,blank=True, null=True)
283 def render(self, **kwargs):
284 return render_to_string(['content/stats_block.html'], {'content': self})
286 class IntroVideo(models.Model):
290 return forms.Media(js=(
291 settings.MEDIA_URL + 'cloudcms/' + 'js/' + 'youtube.js',))
293 image = MediaFileForeignKey(MediaFile, blank=True, null=True)
294 youtube_id = models.CharField(max_length=255,blank=True, null=True)
299 def render(self, **kwargs):
300 return render_to_string(['content/intro_video.html'], {'content': self})