Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making Entry Model swappable using django-swappable-models. #507

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ zinnia = beautifulsoup4
mots-vides
pyparsing
regex
swapper
markups = docutils
markdown
textile
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
license=zinnia.__license__,
include_package_data=True,
zip_safe=False,
install_requires=['beautifulsoup4>=4.3.2',
install_requires=['swapper>=1.0.0',
'beautifulsoup4>=4.3.2',
'django-contrib-comments>=1.7.2',
'django-mptt>=0.8.6',
'django-tagging>=0.4.5',
Expand Down
1 change: 1 addition & 0 deletions versions.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ sh = 1.12.9
snowballstemmer = 1.2.1
sphinx = 1.5.3
sphinx-rtd-theme = 0.1.9
swapper = 1.0.0
textile = 2.3.3
zc.recipe.egg = 2.0.3
8 changes: 4 additions & 4 deletions zinnia/admin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""Admin of Zinnia"""
from django.contrib import admin

import swapper

from zinnia.admin.category import CategoryAdmin
from zinnia.admin.entry import EntryAdmin
from zinnia.models.category import Category
from zinnia.models.entry import Entry
from zinnia.settings import ENTRY_BASE_MODEL


if ENTRY_BASE_MODEL == 'zinnia.models_bases.entry.AbstractEntry':
admin.site.register(Entry, EntryAdmin)
Entry = swapper.load_model("zinnia", "Entry")

admin.site.register(Entry, EntryAdmin)
admin.site.register(Category, CategoryAdmin)
5 changes: 5 additions & 0 deletions zinnia/admin/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from mptt.forms import TreeNodeChoiceField

import swapper

from zinnia.admin.fields import MPTTModelMultipleChoiceField
from zinnia.admin.widgets import MPTTFilteredSelectMultiple
from zinnia.admin.widgets import MiniTextarea
Expand Down Expand Up @@ -60,6 +62,9 @@ class EntryAdminForm(forms.ModelForm):

def __init__(self, *args, **kwargs):
super(EntryAdminForm, self).__init__(*args, **kwargs)

Entry = swapper.load_model("zinnia", "Entry") # noqa: N806

self.fields['categories'].widget = RelatedFieldWidgetWrapper(
self.fields['categories'].widget,
Entry.categories.field.remote_field,
Expand Down
5 changes: 3 additions & 2 deletions zinnia/admin/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
from django.utils.html import format_html
from django.utils.safestring import mark_safe

from tagging.models import Tag
import swapper

from zinnia.models import Entry
from tagging.models import Tag


class MPTTFilteredSelectMultiple(widgets.FilteredSelectMultiple):
Expand Down Expand Up @@ -82,6 +82,7 @@ def get_tags(self):
"""
Returns the list of tags to auto-complete.
"""
Entry = swapper.load_model("zinnia", "Entry") # noqa: N806
return [tag.name for tag in
Tag.objects.usage_for_model(Entry)]

Expand Down
4 changes: 3 additions & 1 deletion zinnia/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ class ZinniaConfig(AppConfig):
def ready(self):
from django_comments.moderation import moderator

import swapper

from zinnia.signals import connect_entry_signals
from zinnia.signals import connect_discussion_signals
from zinnia.moderator import EntryCommentModerator

entry_klass = self.get_model('Entry')
entry_klass = swapper.load_model('zinnia', 'Entry')
# Register the comment moderator on Entry
moderator.register(entry_klass, EntryCommentModerator)
# Connect the signals
Expand Down
4 changes: 3 additions & 1 deletion zinnia/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
from django.utils.formats import date_format
from django.utils.formats import get_format

from zinnia.models.entry import Entry
import swapper

Entry = swapper.load_model("zinnia", "Entry")

AMERICAN_TO_EUROPEAN_WEEK_DAYS = [6, 0, 1, 2, 3, 4, 5]

Expand Down
4 changes: 3 additions & 1 deletion zinnia/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@

import regex as re

from zinnia.models.entry import Entry
import swapper

from zinnia.settings import COMPARISON_FIELDS
from zinnia.settings import STOP_WORDS


Entry = swapper.load_model("zinnia", "Entry")
PUNCTUATION = re.compile(r'\p{P}+')


Expand Down
6 changes: 5 additions & 1 deletion zinnia/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@

import django_comments as comments

import swapper

from tagging.models import Tag
from tagging.models import TaggedItem

from zinnia.models.author import Author
from zinnia.models.entry import Entry
from zinnia.settings import COPYRIGHT
from zinnia.settings import FEEDS_FORMAT
from zinnia.settings import FEEDS_MAX_ITEMS
Expand All @@ -35,6 +36,9 @@
from zinnia.views.categories import get_category_or_404


Entry = swapper.load_model("zinnia", "Entry")


class ZinniaFeed(Feed):
"""
Base Feed class for the Zinnia application,
Expand Down
6 changes: 5 additions & 1 deletion zinnia/management/commands/count_discussions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
from django.core.management.base import BaseCommand
from django.utils.encoding import smart_str

from zinnia.models.entry import Entry
import swapper

from zinnia.signals import disconnect_entry_signals


Entry = swapper.load_model("zinnia", "Entry")


class Command(BaseCommand):
"""
Command for re-counting the discussions on entries
Expand Down
5 changes: 4 additions & 1 deletion zinnia/management/commands/spam_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

import django_comments as comments

from zinnia.models.entry import Entry
import swapper


Entry = swapper.load_model("zinnia", "Entry")


class Command(BaseCommand):
Expand Down
4 changes: 3 additions & 1 deletion zinnia/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ def tags_published():
Return the published tags.
"""
from tagging.models import Tag
from zinnia.models.entry import Entry
import swapper
Entry = swapper.load_model("zinnia", "Entry") # noqa: N806

tags_entry_published = Tag.objects.usage_for_queryset(
Entry.published.all())
# Need to do that until the issue #44 of django-tagging is fixed
Expand Down
122 changes: 0 additions & 122 deletions zinnia/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import django.utils.timezone
from django.conf import settings
from django.db import migrations
from django.db import models

import mptt.fields

import tagging.fields

import zinnia.models_bases.entry
import zinnia.settings


class Migration(migrations.Migration):

Expand Down Expand Up @@ -53,108 +47,6 @@ class Migration(migrations.Migration):
},
bases=(models.Model,),
),
migrations.CreateModel(
name='Entry',
fields=[
('id', models.AutoField(
verbose_name='ID', serialize=False,
auto_created=True, primary_key=True)),
('title', models.CharField(
max_length=255, verbose_name='title')),
('slug', models.SlugField(
help_text="Used to build the entry's URL.", max_length=255,
verbose_name='slug', unique_for_date='creation_date')),
('status', models.IntegerField(
default=0, db_index=True, verbose_name='status',
choices=[(0, 'draft'), (1, 'hidden'), (2, 'published')])),
('start_publication', models.DateTimeField(
help_text='Start date of publication.', null=True,
verbose_name='start publication',
db_index=True, blank=True)),
('end_publication', models.DateTimeField(
help_text='End date of publication.', null=True,
verbose_name='end publication',
db_index=True, blank=True)),
('creation_date', models.DateTimeField(
default=django.utils.timezone.now,
help_text="Used to build the entry's URL.",
verbose_name='creation date', db_index=True)),
('last_update', models.DateTimeField(
default=django.utils.timezone.now,
verbose_name='last update')),
('content', models.TextField(
verbose_name='content', blank=True)),
('comment_enabled', models.BooleanField(
default=True, help_text='Allows comments if checked.',
verbose_name='comments enabled')),
('pingback_enabled', models.BooleanField(
default=True, help_text='Allows pingbacks if checked.',
verbose_name='pingbacks enabled')),
('trackback_enabled', models.BooleanField(
default=True, help_text='Allows trackbacks if checked.',
verbose_name='trackbacks enabled')),
('comment_count', models.IntegerField(
default=0, verbose_name='comment count')),
('pingback_count', models.IntegerField(
default=0, verbose_name='pingback count')),
('trackback_count', models.IntegerField(
default=0, verbose_name='trackback count')),
('excerpt', models.TextField(
help_text='Used for SEO purposes.',
verbose_name='excerpt', blank=True)),
('image', models.ImageField(
help_text='Used for illustration.',
upload_to=zinnia.models_bases.entry.image_upload_to_dispatcher, # noqa
verbose_name='image', blank=True)),
('featured', models.BooleanField(
default=False, verbose_name='featured')),
('tags', tagging.fields.TagField(
max_length=255, verbose_name='tags', blank=True)),
('login_required', models.BooleanField(
default=False, verbose_name='login required',
help_text='Only authenticated users can view the entry.')),
('password', models.CharField(
help_text='Protects the entry with a password.',
max_length=50, verbose_name='password', blank=True)),
('content_template', models.CharField(
default='zinnia/_entry_detail.html',
help_text="Template used to display the entry's content.",
max_length=250, verbose_name='content template',
choices=[
('zinnia/_entry_detail.html', 'Default template')] + \
zinnia.settings.ENTRY_CONTENT_TEMPLATES)),
('detail_template', models.CharField(
default='entry_detail.html',
help_text="Template used to display the entry's detail page.", # noqa
max_length=250, verbose_name='detail template',
choices=[
('entry_detail.html', 'Default template')] + \
zinnia.settings.ENTRY_DETAIL_TEMPLATES)),
('categories', models.ManyToManyField(
related_name='entries',
verbose_name='categories', to='zinnia.Category',
blank=True)),
('related', models.ManyToManyField(
related_name='related_rel_+',
verbose_name='related entries', to='zinnia.Entry',
blank=True)),
('sites', models.ManyToManyField(
help_text='Sites where the entry will be published.',
related_name='entries', verbose_name='sites',
to='sites.Site')),
],
options={
'get_latest_by': 'creation_date',
'ordering': ['-creation_date'],
'abstract': False,
'verbose_name_plural': 'entries',
'verbose_name': 'entry',
'permissions': (('can_view_all', 'Can view all entries'),
('can_change_status', 'Can change status'),
('can_change_author', 'Can change author(s)')),
},
bases=(models.Model,),
),
migrations.CreateModel(
name='Author',
fields=[
Expand All @@ -164,18 +56,4 @@ class Migration(migrations.Migration):
},
bases=(settings.AUTH_USER_MODEL.lower(), models.Model),
),
migrations.AddField(
model_name='entry',
name='authors',
field=models.ManyToManyField(
related_name='entries', verbose_name='authors',
to='zinnia.Author', blank=True),
preserve_default=True,
),
migrations.AlterIndexTogether(
name='entry',
index_together=set([('status', 'creation_date',
'start_publication', 'end_publication'),
('slug', 'creation_date')]),
),
]
Loading