2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2026-03-31 17:26:03 +01:00

[svn] Updates to allow subcave tree with nice admin.

This commit is contained in:
substantialnoninfringinguser
2009-05-21 19:47:19 +01:00
parent 99949d466a
commit 54a62999c0
46 changed files with 1931 additions and 33 deletions

View File

View File

View File

@@ -0,0 +1,20 @@
from django.db import models
from django.template.loader import render_to_string
from django.utils.translation import ugettext_lazy as _
class FileContent(models.Model):
title = models.CharField(max_length=200)
file = models.FileField(_('file'), upload_to='filecontent')
class Meta:
abstract = True
verbose_name = _('file')
verbose_name_plural = _('files')
def render(self, **kwargs):
return render_to_string([
'content/file/%s.html' % self.region.key,
'content/file/default.html',
], {'content': self})

View File

View File

@@ -0,0 +1,32 @@
from django.db import models
from django.template.loader import render_to_string
from django.utils.translation import ugettext_lazy as _
class ImageContent(models.Model):
"""
Create an ImageContent like this:
Cls.create_content_type(ImageContent, POSITION_CHOICES=(
('left', 'Left'),
('right', Right'),
))
"""
image = models.ImageField(_('image'), upload_to='imagecontent')
class Meta:
abstract = True
verbose_name = _('image')
verbose_name_plural = _('images')
def render(self, **kwargs):
return render_to_string([
'content/image/%s.html' % self.position,
'content/image/default.html',
], {'content': self})
@classmethod
def handle_kwargs(cls, POSITION_CHOICES=()):
models.CharField(_('position'), max_length=10, choices=POSITION_CHOICES
).contribute_to_class(cls, 'position')

View File

View File

@@ -0,0 +1,16 @@
from django.db import models
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
class RichTextContent(models.Model):
text = models.TextField(_('text'), blank=True)
class Meta:
abstract = True
verbose_name = _('rich text')
verbose_name_plural = _('rich texts')
def render(self, **kwargs):
return mark_safe(self.text)

View File

View File

@@ -0,0 +1,39 @@
from datetime import datetime
from django.db import models
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
from django.template.loader import render_to_string
import feedparser
class RSSContent(models.Model):
title = models.CharField(help_text=_('The rss field is updated several times a day. A change in the title will only be visible on the home page after the next feed update.'), max_length=50)
link = models.URLField(_('link'))
rendered_content = models.TextField(_('Pre-rendered content'), blank=True, editable=False)
last_updated = models.DateTimeField(_('Last updated'), blank=True, null=True)
max_items = models.IntegerField(_('Max. items'), default=5)
class Meta:
abstract = True
verbose_name = _('RSS feed')
verbose_name_plural = _('RSS feeds')
def render(self, **kwargs):
return mark_safe(self.rendered_content)
def cache_content(self):
print u"Getting RSS feed at %s" % (self.link,)
feed = feedparser.parse(self.link)
print u"Pre-rendering content"
self.rendered_content = render_to_string('content/rss/content.html', {
'feed_title': self.title,
'feed_link': feed['feed']['link'],
'entries': feed['entries'][:self.max_items],
})
self.last_updated = datetime.now()
self.save()

View File

View File

@@ -0,0 +1,26 @@
from django.db import models
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
import re
class VideoContent(models.Model):
video = models.URLField(_('video link'),help_text=_('This should be a link to a youtube video, i.e.: http://www.youtube.com/watch?v=zmj1rpzDRZ0'))
class Meta:
abstract = True
verbose_name = _('video')
verbose_name_plural = _('videos')
def render(self, **kwargs):
vid = re.search('(?<==)\w+',self.video)
ret = """
<div class="videocontent">
<object width="400" height="330">
<param name="movie" value="http://www.youtube.com/v/%s&hl=de&fs=1"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src="http://www.youtube.com/v/%s&hl=de&fs=1&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="400" height="330"></embed>
</object>
</div>
""" % (vid.group(0), vid.group(0))
return ret