diff --git a/blogs_list/feeds.py b/blogs_list/feeds.py index 1e03e27e..42b13c14 100644 --- a/blogs_list/feeds.py +++ b/blogs_list/feeds.py @@ -61,10 +61,12 @@ def item_title(self, item): return item.title def item_description(self, item): - request = get_request() - c = ContentRenderer(request) - html = c.render_placeholder(item.content, RequestContext(request)) - return remove_control_characters(html) + if not item.lead_in: + request = get_request() + c = ContentRenderer(request) + html = c.render_placeholder(item.content, RequestContext(request)) + return remove_control_characters(html) + return item.lead_in def item_pubdate(self, item): return item.publishing_date diff --git a/gsoc/admin.py b/gsoc/admin.py index 41fc9f89..de1daabf 100644 --- a/gsoc/admin.py +++ b/gsoc/admin.py @@ -62,6 +62,7 @@ def return_func(self, request, obj=None, **kwargs): 'is_published', 'is_featured', 'featured_image', + 'lead_in', )}), # (_('Meta Options'), # {'classes': ('collapse',), @@ -201,16 +202,12 @@ def Article_get_queryset(self, request): return qs -def has_add_permission(self, request, obj=None): - return False - ArticleAdmin.save_model = Article_save_model ArticleAdmin.delete_model = Article_delete_model ArticleAdmin.get_queryset = Article_get_queryset -# ArticleAdmin.get_form = article_get_form() +ArticleAdmin.get_form = article_get_form() ArticleAdmin.add_view = Article_add_view ArticleAdmin.change_view = Article_change_view -ArticleAdmin.has_add_permission = has_add_permission admin.site.unregister(Article) admin.site.register(Article, ArticleAdmin) diff --git a/gsoc/cms_wizards.py b/gsoc/cms_wizards.py index 5d9427bd..3a08f2fd 100644 --- a/gsoc/cms_wizards.py +++ b/gsoc/cms_wizards.py @@ -5,6 +5,8 @@ from cms.api import add_plugin from cms.utils import permissions +from cms.wizards.forms import BaseFormMixin +from cms.wizards.wizard_pool import wizard_pool from djangocms_text_ckeditor.html import clean_html @@ -13,10 +15,12 @@ from aldryn_newsblog.cms_appconfig import NewsBlogConfig from aldryn_newsblog.cms_wizards import ( NewsBlogArticleWizard, - CreateNewsBlogArticleForm, - get_published_app_configs + get_published_app_configs, + newsblog_article_wizard ) +from parler.forms import TranslatableModelForm + def user_has_add_permission(self, user, **kwargs): """ @@ -41,51 +45,59 @@ def user_has_add_permission(self, user, **kwargs): NewsBlogArticleWizard.user_has_add_permission = user_has_add_permission -CreateNewsBlogArticleForm.Meta.fields = ['title'] - +class CreateNewsBlogArticleForm(BaseFormMixin, TranslatableModelForm): + """ + The ModelForm for the NewsBlog article wizard. Note that Article has a + number of translated fields that we need to access, so, we use + TranslatableModelForm + """ -def __init__(self, **kwargs): - super(CreateNewsBlogArticleForm, self).__init__(**kwargs) + class Meta: + model = Article + fields = ['title', 'lead_in', 'app_config'] + # The natural widget for app_config is meant for normal Admin views and + # contains JS to refresh the page on change. This is not wanted here. + widgets = {'app_config': forms.Select()} - # If there's only 1 (or zero) app_configs, don't bother show the - # app_config choice field, we'll choose the option for the user. - get_published_app_configs() + def __init__(self, **kwargs): + super(CreateNewsBlogArticleForm, self).__init__(**kwargs) - userprofiles = self.user.userprofile_set.all() + # If there's only 1 (or zero) app_configs, don't bother show the + # app_config choice field, we'll choose the option for the user. + get_published_app_configs() - if self.user.is_superuser: - userprofiles = UserProfile.objects.all() + userprofiles = self.user.userprofile_set.all() - app_config_choices = [] - for profile in userprofiles: - app_config_choices.append((profile.app_config.pk, profile.app_config.get_app_title())) + if self.user.is_superuser: + userprofiles = UserProfile.objects.all() - self.fields['app_config'] = forms.ChoiceField( - label=_('Section'), - required=True, - choices=app_config_choices - ) + app_config_choices = [] + for profile in userprofiles: + app_config_choices.append((profile.app_config.pk, profile.app_config.get_app_title())) + self.fields['app_config'] = forms.ChoiceField( + label=_('Section'), + required=True, + choices=app_config_choices + ) -def save(self, commit=True): - article = super(CreateNewsBlogArticleForm, self).save(commit=False) - article.owner = self.user - article.app_config = NewsBlogConfig.objects.filter(pk=self.cleaned_data['app_config']).first() - article.is_published = True - article.save() + def save(self, commit=True): + article = super(CreateNewsBlogArticleForm, self).save(commit=False) + article.owner = self.user + article.app_config = NewsBlogConfig.objects.\ + filter(pk=self.cleaned_data['app_config']).first() + article.is_published = True + article.save() + return article - # If 'content' field has value, create a TextPlugin with same and add it to the PlaceholderField - content = clean_html(self.cleaned_data.get('content', ''), False) - if content: - add_plugin( - placeholder=article.content, - plugin_type='TextPlugin', - language=self.language_code, - body=content, - ) - return article +wizard_pool.unregister(newsblog_article_wizard) +newsblog_article_wizard = NewsBlogArticleWizard( + title=_(u"New news/blog article"), + weight=200, + form=CreateNewsBlogArticleForm, + description=_(u"Create a new news/blog article.") +) -CreateNewsBlogArticleForm.__init__ = __init__ -CreateNewsBlogArticleForm.save = save +wizard_pool.register(newsblog_article_wizard) diff --git a/gsoc/static/css/article.css b/gsoc/static/css/article.css index acb41d8e..0a6af621 100644 --- a/gsoc/static/css/article.css +++ b/gsoc/static/css/article.css @@ -20,7 +20,6 @@ article > heading { .lead { font-family: 'Source Serif Pro', serif; text-align: justify; - font-style: italic; } .article-content { diff --git a/project.db b/project.db index 454c0f5f..70636cfa 100644 Binary files a/project.db and b/project.db differ