forked from rc/aircox
		
	remove Station model (to much trouble for few advantages); start new player; rename Post.detail_url to Post.url, same for ListItem; move Article into website app; add website.Sound post; work on lists;...
This commit is contained in:
		@ -1,11 +1,38 @@
 | 
			
		||||
import os
 | 
			
		||||
import logging
 | 
			
		||||
 | 
			
		||||
logger = logging.getLogger('aircox')
 | 
			
		||||
 | 
			
		||||
from django.db import models
 | 
			
		||||
from django.utils.translation import ugettext as _, ugettext_lazy
 | 
			
		||||
 | 
			
		||||
from aircox.cms.models import RelatedPost, Article
 | 
			
		||||
from aircox.cms.models import Post, RelatedPost
 | 
			
		||||
import aircox.programs.models as programs
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Article (Post):
 | 
			
		||||
    """
 | 
			
		||||
    Represent an article or a static page on the website.
 | 
			
		||||
    """
 | 
			
		||||
    static_page = models.BooleanField(
 | 
			
		||||
        _('static page'),
 | 
			
		||||
        default = False,
 | 
			
		||||
    )
 | 
			
		||||
    focus = models.BooleanField(
 | 
			
		||||
        _('article is focus'),
 | 
			
		||||
        default = False,
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    class Meta:
 | 
			
		||||
        verbose_name = _('Article')
 | 
			
		||||
        verbose_name_plural = _('Articles')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Program (RelatedPost):
 | 
			
		||||
    url = models.URLField(_('website'), blank=True, null=True)
 | 
			
		||||
    website = models.URLField(
 | 
			
		||||
        _('website'),
 | 
			
		||||
        blank=True, null=True
 | 
			
		||||
    )
 | 
			
		||||
    # rss = models.URLField()
 | 
			
		||||
    email = models.EmailField(
 | 
			
		||||
        _('email'), blank=True, null=True,
 | 
			
		||||
@ -20,6 +47,7 @@ class Program (RelatedPost):
 | 
			
		||||
        rel_to_post = True
 | 
			
		||||
        auto_create = True
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Diffusion (RelatedPost):
 | 
			
		||||
    class Relation:
 | 
			
		||||
        model = programs.Diffusion
 | 
			
		||||
@ -59,3 +87,52 @@ class Diffusion (RelatedPost):
 | 
			
		||||
        return _('rerun of %(day)s') % {
 | 
			
		||||
            'day': self.related.initial.start.strftime('%A %d/%m')
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Sound (RelatedPost):
 | 
			
		||||
    """
 | 
			
		||||
    Publication concerning sound. In order to manage access of sound
 | 
			
		||||
    files in the filesystem, we use permissions -- it is up to the
 | 
			
		||||
    user to work select the correct groups and permissions.
 | 
			
		||||
    """
 | 
			
		||||
    embed = models.TextField(
 | 
			
		||||
        _('embedding code'),
 | 
			
		||||
        blank=True, null=True,
 | 
			
		||||
        help_text = _('HTML code used to embed a sound from an external '
 | 
			
		||||
                      'plateform'),
 | 
			
		||||
    )
 | 
			
		||||
    """
 | 
			
		||||
    Embedding code if the file has been published on an external
 | 
			
		||||
    plateform.
 | 
			
		||||
    """
 | 
			
		||||
 | 
			
		||||
    auto_chmod = True
 | 
			
		||||
    """
 | 
			
		||||
    change file permission depending on the "published" attribute.
 | 
			
		||||
    """
 | 
			
		||||
    chmod_flags = (750, 700)
 | 
			
		||||
    """
 | 
			
		||||
    chmod bit flags, for (not_published, published)
 | 
			
		||||
    """
 | 
			
		||||
    class Relation:
 | 
			
		||||
        model = programs.Sound
 | 
			
		||||
        bindings = {
 | 
			
		||||
            'date': 'mtime',
 | 
			
		||||
        }
 | 
			
		||||
        rel_to_post = True
 | 
			
		||||
 | 
			
		||||
    def save(self, *args, **kwargs):
 | 
			
		||||
        super().save(*args, **kwargs)
 | 
			
		||||
        if self.auto_chmod and not self.related.removed and \
 | 
			
		||||
                os.path.exists(self.related.path):
 | 
			
		||||
            try:
 | 
			
		||||
                os.chmod(self.related.path,
 | 
			
		||||
                         self.chmod_flags[self.published])
 | 
			
		||||
            except PermissionError as err:
 | 
			
		||||
                logger.error(
 | 
			
		||||
                    'cannot set permission {} to file {}: {}'.format(
 | 
			
		||||
                        self.chmod_flags[self.published],
 | 
			
		||||
                        self.related.path, err
 | 
			
		||||
                    )
 | 
			
		||||
                )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user