2014-01-08 07:25:18 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2015-09-13 00:46:05 +02:00
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
|
|
|
|
2014-01-08 07:25:18 +01:00
|
|
|
from django import forms
|
|
|
|
from django.conf import settings
|
2015-09-20 01:11:14 +02:00
|
|
|
from parler.forms import TranslatableModelForm
|
2015-06-28 18:34:33 +02:00
|
|
|
from taggit_autosuggest.widgets import TagAutoSuggest
|
2014-11-30 12:55:15 +01:00
|
|
|
|
2015-10-01 23:16:10 +02:00
|
|
|
from .models import BlogCategory, BlogConfig, Post
|
2015-09-20 01:11:14 +02:00
|
|
|
|
2014-01-08 07:25:18 +01:00
|
|
|
|
|
|
|
class LatestEntriesForm(forms.ModelForm):
|
2015-06-28 18:34:33 +02:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(LatestEntriesForm, self).__init__(*args, **kwargs)
|
|
|
|
self.fields['tags'].widget = TagAutoSuggest('taggit.Tag')
|
2014-01-08 07:25:18 +01:00
|
|
|
|
|
|
|
class Media:
|
|
|
|
css = {
|
2014-01-10 06:37:55 +01:00
|
|
|
'all': ('%sdjangocms_blog/css/%s' % (settings.STATIC_URL,
|
2014-09-05 08:28:10 +02:00
|
|
|
'djangocms_blog_admin.css'),)
|
2014-06-11 21:25:10 +02:00
|
|
|
}
|
2015-09-20 01:11:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
class PostAdminForm(TranslatableModelForm):
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Post
|
|
|
|
fields = '__all__'
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(PostAdminForm, self).__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
qs = BlogCategory.objects
|
|
|
|
|
|
|
|
if getattr(self.instance, 'app_config_id', None):
|
|
|
|
qs = qs.namespace(self.instance.app_config.namespace)
|
|
|
|
elif 'initial' in kwargs and 'app_config' in kwargs['initial']:
|
2015-10-01 23:16:10 +02:00
|
|
|
config = BlogConfig.objects.get(pk=kwargs['initial']['app_config'])
|
|
|
|
qs = qs.namespace(config.namespace)
|
2015-09-20 01:11:14 +02:00
|
|
|
|
|
|
|
if 'categories' in self.fields:
|
|
|
|
self.fields['categories'].queryset = qs
|
|
|
|
|
|
|
|
if 'app_config' in self.fields:
|
|
|
|
# Don't allow app_configs to be added here. The correct way to add an
|
|
|
|
# apphook-config is to create an apphook on a cms Page.
|
|
|
|
self.fields['app_config'].widget.can_add_related = False
|