# Path: aircox/models/page.py
# class Category(models.Model):
#     title = models.CharField(_('title'), max_length=64)
#     slug = models.SlugField(_('slug'), max_length=64, db_index=True)
# 
#     class Meta:
#         verbose_name = _('Category')
#         verbose_name_plural = _('Categories')
# 
#     def __str__(self):
#         return self.title
# 
# class Page(BasePage):
#     """ Base Page model used for articles and other dated content. """
#     category = models.ForeignKey(
#         Category, models.SET_NULL,
#         verbose_name=_('category'), blank=True, null=True, db_index=True
#     )
#     pub_date = models.DateTimeField(blank=True, null=True)
#     featured = models.BooleanField(
#         _('featured'), default=False,
#     )
#     allow_comments = models.BooleanField(
#         _('allow comments'), default=True,
#     )
# 
#     class Meta:
#         verbose_name = _('Publication')
#         verbose_name_plural = _('Publications')
# 
#     def save(self, *args, **kwargs):
#         if self.is_published and self.pub_date is None:
#             self.pub_date = tz.now()
#         elif not self.is_published:
#             self.pub_date = None
# 
#         if self.parent and not self.category:
#             self.category = self.parent.category
#         super().save(*args, **kwargs)
# 
# class StaticPage(BasePage):
#     """ Static page that eventually can be attached to a specific view. """
#     detail_url_name = 'static-page-detail'
# 
#     ATTACH_TO_HOME = 0x00
#     ATTACH_TO_DIFFUSIONS = 0x01
#     ATTACH_TO_LOGS = 0x02
#     ATTACH_TO_PROGRAMS = 0x03
#     ATTACH_TO_EPISODES = 0x04
#     ATTACH_TO_ARTICLES = 0x05
# 
#     ATTACH_TO_CHOICES = (
#         (ATTACH_TO_HOME, _('Home page')),
#         (ATTACH_TO_DIFFUSIONS, _('Diffusions page')),
#         (ATTACH_TO_LOGS, _('Logs page')),
#         (ATTACH_TO_PROGRAMS, _('Programs list')),
#         (ATTACH_TO_EPISODES, _('Episodes list')),
#         (ATTACH_TO_ARTICLES, _('Articles list')),
#     )
#     VIEWS = {
#         ATTACH_TO_HOME: 'home',
#         ATTACH_TO_DIFFUSIONS: 'diffusion-list',
#         ATTACH_TO_LOGS: 'log-list',
#         ATTACH_TO_PROGRAMS: 'program-list',
#         ATTACH_TO_EPISODES: 'episode-list',
#         ATTACH_TO_ARTICLES: 'article-list',
#     }
# 
#     attach_to = models.SmallIntegerField(
#         _('attach to'), choices=ATTACH_TO_CHOICES, blank=True, null=True,
#         help_text=_('display this page content to related element'),
#     )
# 
#     def get_absolute_url(self):
#         if self.attach_to:
#             return reverse(self.VIEWS[self.attach_to])
#         return super().get_absolute_url()
# 
# class Comment(models.Model):
#     page = models.ForeignKey(
#         Page, models.CASCADE, verbose_name=_('related page'),
#         db_index=True,
#         # TODO: allow_comment filter
#     )
#     nickname = models.CharField(_('nickname'), max_length=32)
#     email = models.EmailField(_('email'), max_length=32)
#     date = models.DateTimeField(auto_now_add=True)
#     content = models.TextField(_('content'), max_length=1024)
# 
#     class Meta:
#         verbose_name = _('Comment')
#         verbose_name_plural = _('Comments')
# 
# class NavItem(models.Model):
#     """ Navigation menu items """
#     station = models.ForeignKey(
#         Station, models.CASCADE, verbose_name=_('station'))
#     menu = models.SlugField(_('menu'), max_length=24)
#     order = models.PositiveSmallIntegerField(_('order'))
#     text = models.CharField(_('title'), max_length=64)
#     url = models.CharField(_('url'), max_length=256, blank=True, null=True)
#     page = models.ForeignKey(StaticPage, models.CASCADE, db_index=True,
#                              verbose_name=_('page'), blank=True, null=True)
#     class Meta:
#         verbose_name = _('Menu item')
#         verbose_name_plural = _('Menu items')
#         ordering = ('order', 'pk')
# 
#     def get_url(self):
#         return self.url if self.url else \
#             self.page.get_absolute_url() if self.page else None
# 
#     def render(self, request, css_class='', active_class=''):
#         url = self.get_url()
#         if active_class and request.path.startswith(url):
#             css_class += ' ' + active_class
# 
#         if not url:
#             return self.text
#         elif not css_class:
#             return format_html('<a href="{}">{}</a>', url, self.text)
#         else:
#             return format_html('<a href="{}" class="{}">{}</a>', url,
#                                css_class, self.text)


from copy import deepcopy
from django.contrib import admin
from django.http import QueryDict
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
from adminsortable2.admin import SortableInlineAdminMixin
from ..models import Category, Comment, NavItem, Page, StaticPage





__all__ = ['CategoryAdmin', 'PageAdmin', 'NavItemInline']


@admin.register(Category)
class CategoryAdmin(admin.ModelAdmin):
    list_display = ['pk', 'title', 'slug']
    list_editable = ['title', 'slug']
    search_fields = ['title']
    fields = ['title', 'slug']
    prepopulated_fields = {"slug": ("title",)}


class BasePageAdmin(admin.ModelAdmin):
    list_display = ('cover_thumb', 'title', 'status', 'parent')
    list_display_links = ('cover_thumb', 'title')
    list_editable = ('status',)
    list_filter = ('status',)
    prepopulated_fields = {"slug": ("title",)}

    # prepopulate fields using changelist's filters
    prepopulated_filters = ('parent',)

    search_fields = ('title',)


# Path: aircox/models/page.py
# class Category(models.Model):
#     title = models.CharField(_('title'), max_length=64)
#     slug = models.SlugField(_('slug'), max_length=64, db_index=True)
# 
#     class Meta:
#         verbose_name = _('Category')
#         verbose_name_plural = _('Categories')
# 
#     def __str__(self):
#         return self.title
# 
# class Page(BasePage):
#     """ Base Page model used for articles and other dated content. """
#     category = models.ForeignKey(
#         Category, models.SET_NULL,
#         verbose_name=_('category'), blank=True, null=True, db_index=True
#     )
#     pub_date = models.DateTimeField(blank=True, null=True)
#     featured = models.BooleanField(
#         _('featured'), default=False,
#     )
#     allow_comments = models.BooleanField(
#         _('allow comments'), default=True,
#     )
# 
#     class Meta:
#         verbose_name = _('Publication')
#         verbose_name_plural = _('Publications')
# 
#     def save(self, *args, **kwargs):
#         if self.is_published and self.pub_date is None:
#             self.pub_date = tz.now()
#         elif not self.is_published:
#             self.pub_date = None
# 
#         if self.parent and not self.category:
#             self.category = self.parent.category
#         super().save(*args, **kwargs)
# 
# class StaticPage(BasePage):
#     """ Static page that eventually can be attached to a specific view. """
#     detail_url_name = 'static-page-detail'
# 
#     ATTACH_TO_HOME = 0x00
#     ATTACH_TO_DIFFUSIONS = 0x01
#     ATTACH_TO_LOGS = 0x02
#     ATTACH_TO_PROGRAMS = 0x03
#     ATTACH_TO_EPISODES = 0x04
#     ATTACH_TO_ARTICLES = 0x05
# 
#     ATTACH_TO_CHOICES = (
#         (ATTACH_TO_HOME, _('Home page')),
#         (ATTACH_TO_DIFFUSIONS, _('Diffusions page')),
#         (ATTACH_TO_LOGS, _('Logs page')),
#         (ATTACH_TO_PROGRAMS, _('Programs list')),
#         (ATTACH_TO_EPISODES, _('Episodes list')),
#         (ATTACH_TO_ARTICLES, _('Articles list')),
#     )
#     VIEWS = {
#         ATTACH_TO_HOME: 'home',
#         ATTACH_TO_DIFFUSIONS: 'diffusion-list',
#         ATTACH_TO_LOGS: 'log-list',
#         ATTACH_TO_PROGRAMS: 'program-list',
#         ATTACH_TO_EPISODES: 'episode-list',
#         ATTACH_TO_ARTICLES: 'article-list',
#     }
# 
#     attach_to = models.SmallIntegerField(
#         _('attach to'), choices=ATTACH_TO_CHOICES, blank=True, null=True,
#         help_text=_('display this page content to related element'),
#     )
# 
#     def get_absolute_url(self):
#         if self.attach_to:
#             return reverse(self.VIEWS[self.attach_to])
#         return super().get_absolute_url()
# 
# class Comment(models.Model):
#     page = models.ForeignKey(
#         Page, models.CASCADE, verbose_name=_('related page'),
#         db_index=True,
#         # TODO: allow_comment filter
#     )
#     nickname = models.CharField(_('nickname'), max_length=32)
#     email = models.EmailField(_('email'), max_length=32)
#     date = models.DateTimeField(auto_now_add=True)
#     content = models.TextField(_('content'), max_length=1024)
# 
#     class Meta:
#         verbose_name = _('Comment')
#         verbose_name_plural = _('Comments')
# 
# class NavItem(models.Model):
#     """ Navigation menu items """
#     station = models.ForeignKey(
#         Station, models.CASCADE, verbose_name=_('station'))
#     menu = models.SlugField(_('menu'), max_length=24)
#     order = models.PositiveSmallIntegerField(_('order'))
#     text = models.CharField(_('title'), max_length=64)
#     url = models.CharField(_('url'), max_length=256, blank=True, null=True)
#     page = models.ForeignKey(StaticPage, models.CASCADE, db_index=True,
#                              verbose_name=_('page'), blank=True, null=True)
#     class Meta:
#         verbose_name = _('Menu item')
#         verbose_name_plural = _('Menu items')
#         ordering = ('order', 'pk')
# 
#     def get_url(self):
#         return self.url if self.url else \
#             self.page.get_absolute_url() if self.page else None
# 
#     def render(self, request, css_class='', active_class=''):
#         url = self.get_url()
#         if active_class and request.path.startswith(url):
#             css_class += ' ' + active_class
# 
#         if not url:
#             return self.text
#         elif not css_class:
#             return format_html('<a href="{}">{}</a>', url, self.text)
#         else:
#             return format_html('<a href="{}" class="{}">{}</a>', url,
#                                css_class, self.text)


# Path: aircox/admin/page.py
from copy import deepcopy
from django.contrib import admin
from django.http import QueryDict
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
from adminsortable2.admin import SortableInlineAdminMixin
from ..models import Category, Comment, NavItem, Page, StaticPage






__all__ = ['CategoryAdmin', 'PageAdmin', 'NavItemInline']


@admin.register(Category)
class CategoryAdmin(admin.ModelAdmin):
    list_display = ['pk', 'title', 'slug']
    list_editable = ['title', 'slug']
    search_fields = ['title']
    fields = ['title', 'slug']
    prepopulated_fields = {"slug": ("title",)}


class BasePageAdmin(admin.ModelAdmin):
    list_display = ('cover_thumb', 'title', 'status', 'parent')
    list_display_links = ('cover_thumb', 'title')
    list_editable = ('status',)
    list_filter = ('status',)
    prepopulated_fields = {"slug": ("title",)}

    # prepopulate fields using changelist's filters
    prepopulated_filters = ('parent',)

    search_fields = ('title',)


    fieldsets = [