import threading

from cms.models import CMSPlugin
from django.db import models
from django.utils.translation import ugettext_lazy as _
from inline_ordering.models import Orderable
from filer.fields.image import FilerImageField

import utils

localdata = threading.local()
localdata.TEMPLATE_CHOICES = utils.autodiscover_templates()
TEMPLATE_CHOICES = localdata.TEMPLATE_CHOICES


class GalleryPlugin(CMSPlugin):

    def copy_relations(self, oldinstance):
        for img in oldinstance.image_set.all():
            new_img = Image()
            new_img.gallery=self
            new_img.src = img.src
            new_img.title = img.title
            new_img.alt = img.alt
            new_img.save()

    template = models.CharField(max_length=255,
                                choices=TEMPLATE_CHOICES,
                                default=TEMPLATE_CHOICES[0][0],
                                editable=len(TEMPLATE_CHOICES) > 1)
示例#2
0
from datetime import date
import os
import threading

from cms.models import CMSPlugin
from cms.utils import get_cms_setting
from django.db import models
from django.utils.translation import ugettext_lazy as _
from inline_ordering.models import Orderable
from django.utils.deconstruct import deconstructible
from django.db import connection

import utils

localdata = threading.local()
localdata.TEMPLATE_CHOICES = utils.autodiscover_templates()
TEMPLATE_CHOICES = localdata.TEMPLATE_CHOICES


@deconstructible
class UploadPath(object):
    def __init__(self, sub_path):
        self.path = sub_path

    def __call__(self, instance, filename):
        if connection.schema_name:
            return "gallery/%s/%s/%s" % (instance.title,
                                         connection.schema_name, filename)
        else:
            return "gallery/%s/%s" % (instance.title, filename)
import threading
from django.db import models
from cms.models.pluginmodel import CMSPlugin
import utils

localdata = threading.local()
localdata.TEMPLATE_CHOICES = utils.autodiscover_templates('cmsplugin_syntax_highlight')
TEMPLATE_CHOICES = localdata.TEMPLATE_CHOICES

class SyntaxHighlighter(CMSPlugin):
    template = models.CharField(max_length=255,
                                choices=TEMPLATE_CHOICES)
    content = models.TextField()

    def __str__(self):
        return "highlighter_" + str(self.id)

    def __unicode__(self):
        return "highlighter_" + str(self.id)