Statistics
| Branch: | Tag: | Revision:

root / cloudcms / content.py @ a13220f8

History | View | Annotate | Download (11.1 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

    
178

    
179
class IntroButton(models.Model):
180

    
181
    class Meta:
182
        abstract = True
183
        verbose_name = _('intro images')
184
        verbose_name_plural = _('intro images')
185

    
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")
194

    
195
    def render(self, **kwargs):
196
        return render_to_string(['content/intro_images.html'], {'content': self})
197

    
198

    
199

    
200
class TextileContent(models.Model):
201
    content = models.TextField()
202

    
203
    class Meta:
204
        abstract = True
205

    
206
    def render(self, **kwargs):
207
        return textile(self.content)
208
    
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)
214

    
215
    class Meta:
216
        abstract = True
217

    
218
    def render(self, **kwargs):
219
        return render_to_string(['content/intro_block.html'], {'content': self})
220

    
221

    
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)
227

    
228
    class Meta:
229
        abstract = True
230

    
231
    def render(self, **kwargs):
232
        return render_to_string(['content/block_with_color.html'], {'content': self})
233
    
234

    
235
class ClientDownload(models.Model):
236

    
237
    client = models.ForeignKey('cloudcms.Client')
238

    
239
    @property
240
    def media(self):
241
        return forms.Media(js=(
242
            settings.MEDIA_URL + 'cloudcms/' + 'js/' + 'client-downloads.js',))
243

    
244
    class Meta:
245
        abstract = True
246
        verbose_name = _('client download')
247
        verbose_name_plural = _('client downloads')
248

    
249
    def render(self, **kwrags):
250
        return render_to_string(['content/client_downloads.html'], {'content': self})
251

    
252

    
253
class StatsBlock(models.Model):
254
    
255
    @property
256
    def media(self):
257
        return forms.Media(js=(
258
            settings.MEDIA_URL + 'cloudcms/' + 'js/' + 'service-stats.js',))
259

    
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 - \
265
        DELETED VMs")
266
    running_networks = models.BooleanField(default=False, help_text = "ACTIVE \
267
        networks")
268
    spawned_networks = models.BooleanField(default=True,help_text= "All \
269
        Networks")
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)
279
    
280
    class Meta:
281
        abstract = True
282

    
283
    def render(self, **kwargs):
284
        return render_to_string(['content/stats_block.html'], {'content': self})
285

    
286
class IntroVideo(models.Model):
287

    
288
    @property
289
    def media(self):
290
        return forms.Media(js=(
291
            settings.MEDIA_URL + 'cloudcms/' + 'js/' + 'youtube.js',))
292

    
293
    image = MediaFileForeignKey(MediaFile, blank=True, null=True)
294
    youtube_id = models.CharField(max_length=255,blank=True, null=True)
295
    
296
    class Meta:
297
        abstract = True
298

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