Skip to content
This repository was archived by the owner on Aug 26, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions blogs_list/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions gsoc/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def return_func(self, request, obj=None, **kwargs):
'is_published',
'is_featured',
'featured_image',
'lead_in',
)}),
# (_('Meta Options'),
# {'classes': ('collapse',),
Expand Down Expand Up @@ -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)
Expand Down
88 changes: 50 additions & 38 deletions gsoc/cms_wizards.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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):
"""
Expand All @@ -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)
1 change: 0 additions & 1 deletion gsoc/static/css/article.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ article > heading {
.lead {
font-family: 'Source Serif Pro', serif;
text-align: justify;
font-style: italic;
}

.article-content {
Expand Down
Binary file modified project.db
Binary file not shown.