Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Add publishing feature to ICEKit Events
Browse files Browse the repository at this point in the history
Add publishing features to events.

NOTE: This requires the latest upstream changes to django-icekit that
improve support for polymorphic models, particularly commit
a025303c4b84fd52f7c29b8fe50db0748c9e257b

- `AbstractEvent` is now a publishable model
- updated parent and child admins to show publishing features
- update test settings to apply publishing features
- update basic event views to work properly with publishing: show
  visible events only with support for ?edit verified draft links
- add publishing extra to django-icekit requirements.
  • Loading branch information
jmurty committed Aug 4, 2016
1 parent aecce03 commit 8179481
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 9 deletions.
21 changes: 17 additions & 4 deletions icekit_events/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
from polymorphic.admin import PolymorphicChildModelAdmin
from timezone import timezone

from icekit.publishing import admin as publishing_admin

from . import admin_forms, forms, models, plugins

logger = logging.getLogger(__name__)
Expand All @@ -49,7 +51,8 @@ class OccurrencesInline(admin.TabularInline):
readonly_fields = ('is_user_modified', 'is_cancelled',)


class EventChildAdmin(PolymorphicChildModelAdmin):
class EventChildAdmin(PolymorphicChildModelAdmin,
publishing_admin.PublishingAdmin):
"""
Abstract admin class for polymorphic child event models.
"""
Expand All @@ -71,17 +74,26 @@ class EventTypeFilter(ChildModelFilter):
child_model_plugin_class = plugins.EventChildModelPlugin


class EventAdmin(ChildModelPluginPolymorphicParentModelAdmin):
class EventAdmin(ChildModelPluginPolymorphicParentModelAdmin,
publishing_admin.PublishingAdmin):
base_model = models.Event
list_filter = (
EventTypeFilter, 'modified')
EventTypeFilter, 'modified',
publishing_admin.PublishingStatusFilter,
publishing_admin.PublishingPublishedFilter,
)
list_display = (
'__str__', 'get_type', 'modified')
'__str__', 'get_type', 'modified', 'publishing_column')
search_fields = ('title', )

child_model_plugin_class = plugins.EventChildModelPlugin
child_model_admin = EventChildAdmin

class Media:
css = {
'all': ('icekit_events/bower_components/font-awesome/css/font-awesome.css',),
}

def get_urls(self):
"""
Add a calendar URL.
Expand Down Expand Up @@ -116,6 +128,7 @@ def calendar(self, request):
datetime.datetime.strptime(request.GET['end'], '%Y-%m-%d'), tz)

all_occurrences = models.Occurrence.objects \
.filter(event__publishing_is_draft=True) \
.filter(
Q(is_all_day=False, start__gte=start) |
Q(is_all_day=True, start__gte=start.date())
Expand Down
36 changes: 36 additions & 0 deletions icekit_events/migrations/0017_auto_20160804_1342.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone


class Migration(migrations.Migration):

dependencies = [
('icekit_events', '0016_auto_20160803_1338'),
]

operations = [
migrations.AddField(
model_name='event',
name='publishing_is_draft',
field=models.BooleanField(default=True, db_index=True, editable=False),
),
migrations.AddField(
model_name='event',
name='publishing_linked',
field=models.OneToOneField(related_name='publishing_draft', null=True, on_delete=django.db.models.deletion.SET_NULL, editable=False, to='icekit_events.Event'),
),
migrations.AddField(
model_name='event',
name='publishing_modified_at',
field=models.DateTimeField(default=django.utils.timezone.now, editable=False),
),
migrations.AddField(
model_name='event',
name='publishing_published_at',
field=models.DateTimeField(null=True, editable=False),
),
]
19 changes: 18 additions & 1 deletion icekit_events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from polymorphic_tree.models import PolymorphicModel, PolymorphicTreeForeignKey
from timezone import timezone

from icekit.publishing.models import PublishingModel

from . import appsettings, validators, utils
from .utils import time as utils_time

Expand Down Expand Up @@ -152,7 +154,7 @@ def __str__(self):


@encoding.python_2_unicode_compatible
class AbstractEvent(PolymorphicModel, AbstractBaseModel):
class AbstractEvent(PolymorphicModel, AbstractBaseModel, PublishingModel):
"""
An abstract polymorphic event model, with the bare minimum fields.
Expand Down Expand Up @@ -349,6 +351,21 @@ def regenerate_occurrences(self, until=None):
# Generate occurrences for this event
self.extend_occurrences(until=until)

def clone_relations(self, dst_obj):
"""
Clone related `EventRepeatsGenerator` and `Occurrence` items on publish
"""
for generator in self.repeat_generators.all():
generator.pk = None
generator.event = dst_obj
generator.save()
# Clone only the user-modified Occurrences, all others will be
# auto-generated by the generators cloned above.
for occurrence in self.occurrences.filter(is_user_modified=True):
occurrence.pk = None
occurrence.event = dst_obj
occurrence.save()


class Event(AbstractEvent):
"""
Expand Down
3 changes: 2 additions & 1 deletion icekit_events/static/icekit_events/bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"fullcalendar": "~2.6.0",
"iframe-resizer": "~2.8.7",
"lodash": "~3.9.3",
"skveege-rrule": "~2.1.3"
"skveege-rrule": "~2.1.3",
"font-awesome": "~4.3.0"
}
}
7 changes: 7 additions & 0 deletions icekit_events/tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
'icekit',
'icekit_events',
'icekit_events.tests',

# Apps required for publishing features
'icekit.publishing',
'model_settings',
'polymorphic',
'compressor',
)

MIDDLEWARE_CLASSES = (
Expand All @@ -38,6 +44,7 @@
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner' # Default: django.test.runner.DiscoverRunner
TIME_ZONE = 'Australia/Sydney' # Default: America/Chicago
USE_TZ = True # Default: False
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

DDF_FILL_NULLABLE_FIELDS = False
FLUENT_PAGES_TEMPLATE_DIR = os.path.join(BASE_DIR, '..', 'templates')
8 changes: 6 additions & 2 deletions icekit_events/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Do not use generic class based views unless there is a really good reason to.
# Functional views are much easier to comprehend and maintain.
from django.core.exceptions import PermissionDenied
from django.http import Http404
from django.shortcuts import get_object_or_404
from django.template.response import TemplateResponse

Expand All @@ -26,7 +27,7 @@ def index(request, is_preview=False):
if is_preview and not permissions.allowed_to_preview(request.user):
raise PermissionDenied

events = models.Event.objects.all()
events = models.Event.objects.visible()
context = {
'is_preview': is_preview,
'events': events,
Expand All @@ -48,7 +49,10 @@ def detail(request, event_id, is_preview=False):
if is_preview and not permissions.allowed_to_preview(request.user):
raise PermissionDenied

event = get_object_or_404(models.Event, id=event_id)
event = get_object_or_404(models.Event, pk=event_id).get_visible()
if not event:
raise Http404

context = {
'is_preview': is_preview,
'event': event,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
'coverage',
'Django<1.9',
'django-dynamic-fixture',
'django-icekit',
'django-icekit[publishing]',
'django-model-utils<2.4', # See: https://github.com/jp74/django-model-publisher/pull/26
'django-nose',
'django-polymorphic<0.8', # ICEKit Events is not yet compatible with API changes in 0.8+
Expand Down

0 comments on commit 8179481

Please sign in to comment.