Statistics
| Branch: | Tag: | Revision:

root / cloudcms / content.py @ 5cc874ca

History | View | Annotate | Download (11.7 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
from django.utils.html import mark_safe
43

    
44
from feincms.admin.editor import ItemEditorForm
45
from feincms.module.page.models import Page
46
from feincms.module.medialibrary.models import MediaFile
47
from feincms.content.medialibrary.models import MediaFileWidget
48
from feincms.module.medialibrary.fields import MediaFileForeignKey
49

    
50

    
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");""")
53

    
54
class VideoSection(models.Model):
55
    section_title = models.CharField(max_length=200, blank=True)
56
    video_title = models.CharField(max_length=200, blank=True)
57
    video_link = models.CharField(max_length=200, blank=True)
58
    video_width = models.PositiveIntegerField(default=700)
59
    video_height = models.PositiveIntegerField(default=550)
60
    image = MediaFileForeignKey(MediaFile, blank=True, null=True,
61
    related_name="as_image_for_video_section")
62
    image_hover = MediaFileForeignKey(MediaFile, blank=True, null=True,
63
            related_name="as_hover_for_video_section")
64
    alt_text = models.TextField(null=True, blank=True)
65
    extra_url_params = models.CharField(max_length=200, blank=True)
66

    
67
    class Meta:
68
        abstract = True
69
        verbose_name = _('video section')
70
        verbose_name_plural = _('video sections')
71

    
72
    def render(self, **kwargs):
73
        return render_to_string(['content/videosection.html'], {'content': self})
74

    
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

    
82
class TwitterFeed(models.Model):
83
    title = models.CharField(max_length=200, blank=True)
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.")
120

    
121
    class Meta:
122
        abstract = True
123
        verbose_name = _('twitter feed')
124
        verbose_name_plural = _('twitter feeds')
125

    
126
    def render(self, **kwargs):
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
        })
131

    
132

    
133
class AboutBlock(models.Model):
134

    
135
    title = models.CharField(max_length=200, blank=False)
136
    content = models.TextField(blank=False)
137
    image = MediaFileForeignKey(MediaFile, blank=True, null=True)
138
    image_position = models.CharField(max_length=200,
139
            choices=(('top', 'Top'), ('left', 'Left'), ('right', 'Right')))
140
    color = models.CharField(max_length=200, blank=False)
141
    offset_left = models.IntegerField(null=True, blank=True)
142
    offset_top = models.IntegerField(null=True, blank=True)
143

    
144
    class Meta:
145
        abstract = True
146
        verbose_name = _('about page block')
147
        verbose_name_plural = _('about page blocks')
148

    
149
    def render(self, **kwargs):
150
        return render_to_string(['content/about_block.html'], {'content': self})
151

    
152

    
153
class LoginForm(models.Model):
154
    """
155
    Login form
156
    """
157

    
158
    title = models.CharField(_('title'), max_length=200, blank=False)
159
    action_url = models.CharField(_('im url'), max_length=100, blank=False)
160
    display_forgot_password = models.BooleanField(default=False, null=False)
161
    next_url = models.CharField(max_length=255, null=True, blank=True)
162
    bottom_content = models.TextField(blank=True)
163
    logged_in_content = models.TextField(blank=True)
164

    
165
    class Meta:
166
        abstract = True
167
        verbose_name = _('login form')
168
        verbose_name_plural = _('login forms')
169

    
170
    def render(self, **kwargs):
171
        return render_to_string(['content/login_form.html'], {'content': self})
172

    
173

    
174
class IntroButton(models.Model):
175

    
176
    class Meta:
177
        abstract = True
178
        verbose_name = _('intro images')
179
        verbose_name_plural = _('intro images')
180

    
181
    image_1 = MediaFileForeignKey(MediaFile, blank=True, null=True,
182
            related_name="as_image1")
183
    image_2 = MediaFileForeignKey(MediaFile, blank=True, null=True,
184
            related_name="as_image2")
185
    image_3 = MediaFileForeignKey(MediaFile, blank=True, null=True,
186
            related_name="as_image3")
187
    link = models.CharField(max_length=255, blank=False, default="/welcome")
188
    link_title = models.CharField(max_length=255, blank=False, default="~okeanos")
189

    
190
    def render(self, **kwargs):
191
        return render_to_string(['content/intro_images.html'], {'content': self})
192

    
193

    
194

    
195
class TextileContent(models.Model):
196
    content = models.TextField()
197

    
198
    class Meta:
199
        abstract = True
200

    
201
    def render(self, **kwargs):
202
        return textile(self.content)
203

    
204
class IntroBlock(models.Model):
205
    title = models.CharField(_('title'), max_length=200, blank=False)
206
    content = models.TextField()
207
    class_name = models.CharField(_('class_name'), max_length=200, blank=True, null=True)
208
    image = MediaFileForeignKey(MediaFile, blank=True, null=True)
209

    
210
    class Meta:
211
        abstract = True
212

    
213
    def render(self, **kwargs):
214
        return render_to_string(['content/intro_block.html'], {'content': self})
215

    
216

    
217
class BlockColor(models.Model):
218
    title = models.CharField(_('title'), max_length=200, blank=False)
219
    content = models.TextField()
220
    color = models.CharField(max_length=200, blank=True, null=True)
221
    image = MediaFileForeignKey(MediaFile, blank=True, null=True)
222

    
223
    class Meta:
224
        abstract = True
225

    
226
    def render(self, **kwargs):
227
        return render_to_string(['content/block_with_color.html'], {'content': self})
228

    
229

    
230
class ClientDownload(models.Model):
231

    
232
    client = models.ForeignKey('cloudcms.Client')
233

    
234
    @property
235
    def media(self):
236
        return forms.Media(js=(
237
            settings.MEDIA_URL + 'cloudcms/' + 'js/' + 'client-downloads.js',))
238

    
239
    class Meta:
240
        abstract = True
241
        verbose_name = _('client download')
242
        verbose_name_plural = _('client downloads')
243

    
244
    def render(self, **kwrags):
245
        return render_to_string(['content/client_downloads.html'], {'content': self})
246

    
247

    
248
class StatsBlock(models.Model):
249

    
250
    @property
251
    def media(self):
252
        return forms.Media(js=(
253
            settings.MEDIA_URL + 'cloudcms/' + 'js/' + 'service-stats.js',))
254

    
255
    title = models.CharField(_('title'), max_length=200, blank=True)
256
    color = models.CharField(max_length=200, blank=True, null=True)
257
    running_vms = models.BooleanField(default=False, help_text = "ACTIVE VMs")
258
    spawned_vms = models.BooleanField(default=True, help_text= "All VMs")
259
    active_vms = models.BooleanField(default=True, help_text ="All VMs - \
260
        DELETED VMs")
261
    running_networks = models.BooleanField(default=False, help_text = "ACTIVE \
262
        networks")
263
    spawned_networks = models.BooleanField(default=True,help_text= "All \
264
        Networks")
265
    active_networks = models.BooleanField(default=False, help_text ="All \
266
        Networks - DELETED Networks")
267
    title_running_vms = models.CharField(max_length=255,blank=True, null=True)
268
    title_spawned_vms = models.CharField(max_length=255,blank=True, null=True)
269
    title_active_vms = models.CharField(max_length=255,blank=True, null=True)
270
    title_running_networks = models.CharField(max_length=255,blank=True, null=True)
271
    title_spawned_networks = models.CharField(max_length=255,blank=True, null=True)
272
    title_active_networks = models.CharField(max_length=255,blank=True, null=True)
273
    compute_url = models.CharField(max_length=255,blank=True, null=True)
274

    
275
    class Meta:
276
        abstract = True
277

    
278
    def render(self, **kwargs):
279
        return render_to_string(['content/stats_block.html'], {'content': self})
280

    
281
class IntroVideo(models.Model):
282

    
283
    @property
284
    def media(self):
285
        return forms.Media(js=(
286
            settings.MEDIA_URL + 'cloudcms/' + 'js/' + 'youtube.js',))
287

    
288
    image = MediaFileForeignKey(MediaFile, blank=True, null=True)
289
    youtube_id = models.CharField(max_length=255,blank=True, null=True)
290

    
291
    class Meta:
292
        abstract = True
293

    
294
    def render(self, **kwargs):
295
        return render_to_string(['content/intro_video.html'], {'content': self})