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:
		@ -14,7 +14,7 @@ class TrackInline(SortableTabularInline):
 | 
			
		||||
    sortable = 'position'
 | 
			
		||||
    extra = 10
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
admin.site.register(models.Article, cms.PostAdmin)
 | 
			
		||||
admin.site.register(models.Program, cms.RelatedPostAdmin)
 | 
			
		||||
admin.site.register(models.Diffusion, cms.RelatedPostAdmin)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
                    )
 | 
			
		||||
                )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -9,6 +9,28 @@ import aircox.cms.sections as sections
 | 
			
		||||
import aircox.website.models as models
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Player(sections.Section):
 | 
			
		||||
    """
 | 
			
		||||
    Display a player that is cool.
 | 
			
		||||
    """
 | 
			
		||||
    template_name = 'aircox/website/player.html'
 | 
			
		||||
    live_streams = []
 | 
			
		||||
    """
 | 
			
		||||
    A ListItem objects that display a list of available streams.
 | 
			
		||||
    """
 | 
			
		||||
    #default_sounds
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    def get_context_data(self, *args, **kwargs):
 | 
			
		||||
        context = super().get_context_data(*args, **kwargs)
 | 
			
		||||
 | 
			
		||||
        context.update({
 | 
			
		||||
            'live_streams': self.live_streams
 | 
			
		||||
        })
 | 
			
		||||
        return context
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Diffusions(sections.List):
 | 
			
		||||
    """
 | 
			
		||||
    Section that print diffusions. When rendering, if there is no post yet
 | 
			
		||||
@ -19,14 +41,19 @@ class Diffusions(sections.List):
 | 
			
		||||
 | 
			
		||||
    def __init__(self, *args, **kwargs):
 | 
			
		||||
        super().__init__(*args, **kwargs)
 | 
			
		||||
        self.__dict__.update(kwargs)
 | 
			
		||||
 | 
			
		||||
    def get_diffs(self, **filter_args):
 | 
			
		||||
        qs = programs.Diffusion.objects.filter(
 | 
			
		||||
            type = programs.Diffusion.Type.normal
 | 
			
		||||
        )
 | 
			
		||||
        if self.object:
 | 
			
		||||
            qs = qs.filter(program = self.object.related)
 | 
			
		||||
            object = self.object.related
 | 
			
		||||
            if type(object) == programs.Program:
 | 
			
		||||
                qs = qs.filter(program = object)
 | 
			
		||||
            elif type(object) == programs.Diffusion:
 | 
			
		||||
                if object.initial:
 | 
			
		||||
                    object = object.initial
 | 
			
		||||
                qs = qs.filter(initial = object) | qs.filter(pk = object.pk)
 | 
			
		||||
        if filter_args:
 | 
			
		||||
            qs = qs.filter(**filter_args).order_by('start')
 | 
			
		||||
 | 
			
		||||
@ -72,6 +99,9 @@ class Diffusions(sections.List):
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def url(self):
 | 
			
		||||
        if not self.need_url():
 | 
			
		||||
            return
 | 
			
		||||
 | 
			
		||||
        if self.object:
 | 
			
		||||
            return models.Diffusion.route_url(routes.ThreadRoute,
 | 
			
		||||
                pk = self.object.id,
 | 
			
		||||
@ -114,6 +144,10 @@ class Playlist(sections.List):
 | 
			
		||||
                    for track in tracks ]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Sounds(sections.List):
 | 
			
		||||
    pass
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Schedule(Diffusions):
 | 
			
		||||
    """
 | 
			
		||||
    Render a list of diffusions in the form of a schedule
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user