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

Commit

Permalink
Merge branch 'feature/media-category-api' of github.com:ic-labs/djang…
Browse files Browse the repository at this point in the history
…o-icekit into feature/media-category-api
  • Loading branch information
markfinger committed Jun 13, 2017
2 parents fc8ede3 + 67a4e43 commit 0077972
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 41 deletions.
8 changes: 4 additions & 4 deletions icekit/api/management/commands/dump_collection_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def handle(self, *args, **options):
a['accession_number'] = artwork.accession_number
a['medium_display'] = artwork.medium_display
a['medium_medium'] = artwork.medium_medium
a['date_display'] = artwork.date_display
a['creation_date_display'] = artwork.creation_date_display
a['object_type'] = artwork.type
a['origin_country'] = artwork.origin_country
a['dimensions_display'] = artwork.dimensions_display
Expand All @@ -61,7 +61,7 @@ def handle(self, *args, **options):
# primary_artists_list = list()
# for work in artist.public_artworks:
# work_accession_numbers.append(work.accession_number)

# works = ",".join(work_accession_numbers)
# a['artwork_accession_numbers'] = works
# artist_csv.append(a)
Expand All @@ -70,7 +70,7 @@ def handle(self, *args, **options):
# for artist in artwork.primary_artists:
# primary_artist = artist.name_display
# primary_artists.append(primary_artist)

# primary_artists = ",".join(primary_artists)
# a['primary_artists'] = primary_artists

Expand Down Expand Up @@ -106,7 +106,7 @@ def handle(self, *args, **options):
work_accession_numbers = list()
for work in artist.public_artworks:
work_accession_numbers.append(work.accession_number)

works = ",".join(work_accession_numbers)
a['artwork_accession_numbers'] = works
artist_csv.append(a)
Expand Down
5 changes: 4 additions & 1 deletion icekit/plugins/links/content_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ class ArticleLinkPlugin(LinkPlugin):
class AuthorLinkPlugin(LinkPlugin):
model = models.AuthorLink
fieldsets = deepcopy(LinkPlugin.fieldsets)
fieldsets[1][1]['fields'] += ("exclude_from_contributions", )
fieldsets[1][1]['fields'] += (
"exclude_from_contributions",
"exclude_from_authorship",
)

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('ik_links', '0006_authorlink_exclude_from_contributions'),
]

operations = [
migrations.AddField(
model_name='authorlink',
name='exclude_from_authorship',
field=models.BooleanField(default=False, help_text=b'Exclude this author from the list of authors on the page.'),
),
]
2 changes: 2 additions & 0 deletions icekit/plugins/links/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class AuthorLink(AbstractLinkItem):

exclude_from_contributions = models.BooleanField(help_text="Exclude this content "
"from the author's contributions.", default=False)
exclude_from_authorship = models.BooleanField(help_text="Exclude this author "
"from the list of authors on the page.", default=False)

class Meta:
verbose_name = "Author link"
Expand Down
11 changes: 2 additions & 9 deletions icekit/templates/icekit/partials/preview_link.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,11 @@
{% if request.IS_DRAFT or request.user.is_staff %}
<div class="preview-ribbon" {{ attrs }}>
{% if request.user.is_staff %}
<a
class="preview-ribbon__link"
{% if obj.is_draft %}
href="{{ obj|admin_url }}"
{% else %}
href="{{ obj.get_draft|admin_url }}"
{% endif %}
>
<a class="preview-ribbon__link" href="{{ obj.get_draft|admin_url }}">
{% endif %}
<div class="preview-ribbon__content">
{% if obj.is_draft and not obj.has_been_published %}
<span class="preview-ribbon__text">Preview</span>
<i class="fa fa-low-vision preview-ribbon__icon"></i><i class="fa fa-pencil preview-ribbon__icon"></i>
{% else %}
<i class="fa fa-pencil preview-ribbon__icon"></i>
{% endif %}
Expand Down
10 changes: 6 additions & 4 deletions icekit/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
from fluent_pages.models import PageLayout
from fluent_pages.pagetypes.fluentpage.models import FluentPage
from forms_builder.forms.models import Form

from icekit.admin_tools.forms import PasswordResetForm
from icekit.mixins import LayoutFieldMixin
from icekit.page_types.layout_page.models import LayoutPage
from icekit.plugins import descriptors
Expand All @@ -39,7 +41,7 @@
from icekit.utils import fluent_contents, implementation
from icekit.admin_tools import mixins

from icekit import admin_forms, models, validators
from icekit import models, validators
from icekit.tests import models as test_models

# Conditional imports
Expand Down Expand Up @@ -78,14 +80,14 @@ def setUp(self):

def test_password_reset_form(self):
self.assertEqual(
six.next(admin_forms.PasswordResetForm().get_users(self.user_1.email)),
six.next(PasswordResetForm().get_users(self.user_1.email)),
self.user_1
)
with self.assertRaises(StopIteration):
six.next(admin_forms.PasswordResetForm().get_users(self.user_2.email))
six.next(PasswordResetForm().get_users(self.user_2.email))

with self.assertRaises(StopIteration):
six.next(admin_forms.PasswordResetForm().get_users(self.user_3.email))
six.next(PasswordResetForm().get_users(self.user_3.email))

def test_twitter_embed_admin_form(self):
twitter_url = 'https://twitter.com/Interior/status/463440424141459456'
Expand Down
29 changes: 23 additions & 6 deletions icekit_events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,26 +418,37 @@ def visible_part_of(self):
return self.part_of.get_visible()
return None

@cached_property
def own_occurrences(self):
"""
The value is returned as a list, to emphasise its cached/resolved nature.
Manipulating a queryset would lose the benefit of caching.
:return: A list of occurrences directly attached to the event. Used to
fall back to `part_of` occurrences.
"""
return list(self.occurrences.all())

@cached_property
def occurrence_list(self):
"""
:return: A list of my occurrences, or those of my visible_part_of event
"""
o = list(self.occurrences.all())
o = self.own_occurrences
if o:
return o
if self.visible_part_of:
return self.visible_part_of.occurrence_list
return o # empty
return []

@cached_property
def upcoming_occurrence_list(self):
o = list(self.occurrences.upcoming())
if o:
return o
if self.own_occurrences:
return list(self.occurrences.upcoming())

if self.visible_part_of:
return self.visible_part_of.upcoming_occurrence_list
return o # empty
return []

def invalidate_caches(self):
"""
Expand All @@ -454,6 +465,11 @@ def invalidate_caches(self):
except AttributeError:
pass

try:
del self.own_occurrences
except AttributeError:
pass

try:
del self.upcoming_occurrence_list
except AttributeError:
Expand Down Expand Up @@ -549,6 +565,7 @@ def has_finished(self):
There are occurrences, and
There are no upcoming occurrences
"""

return self.occurrence_list and not self.upcoming_occurrence_list


Expand Down
15 changes: 4 additions & 11 deletions icekit_events/templatetags/events_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ def dates_range(event, format=""):
default ''
from_text - text to prepend if the event never ends (the 'last' date is
None)
ended_text - text to append if the event has ended
:return: text describing the date range for the event. If human dates are
given, use that, otherwise, use the first and last occurrences for an event.
Expand All @@ -116,7 +115,6 @@ def dates_range(event, format=""):
separator = "&nbsp;&ndash; "
no_dates_text = ''
from_text = "from "
ended_text = " (ended)"
arg_list = [arg.strip() for arg in format.split('|')]
if arg_list:
date_format = arg_list[0]
Expand All @@ -128,13 +126,8 @@ def dates_range(event, format=""):
except IndexError:
pass

if event.has_finished():
f = ended_text
else:
f = ""

if event.human_dates:
return event.human_dates.strip() + f
return event.human_dates.strip()

# Get the dates from the occurrence
first, last = event.get_occurrences_range()
Expand All @@ -155,16 +148,16 @@ def dates_range(event, format=""):
first_date_format = _format_with_same_year_and_month(date_format)
if start.day == end.day:
# the two dates are equal, just return one date.
return mark_safe(datefilter(start, date_format) + f)
return mark_safe(datefilter(start, date_format))

return mark_safe('%s%s%s' % (
datefilter(start, first_date_format),
separator,
datefilter(end, date_format)
) + f)
))

elif start and not end:
return '%s%s' % (from_text, datefilter(start, date_format)) + f
return '%s%s' % (from_text, datefilter(start, date_format))
elif not (start or end):
return no_dates_text
else:
Expand Down
24 changes: 24 additions & 0 deletions icekit_press_releases/migrations/0010_add_brief.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('icekit_press_releases', '0009_auto_20170519_1308'),
]

operations = [
migrations.AddField(
model_name='pressrelease',
name='admin_notes',
field=models.TextField(blank=True, help_text=b"Administrator's notes about this content"),
),
migrations.AddField(
model_name='pressrelease',
name='brief',
field=models.TextField(blank=True, help_text=b'A document brief describing the purpose of this content'),
),
]
9 changes: 3 additions & 6 deletions icekit_press_releases/models.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import os
from django.core.urlresolvers import NoReverseMatch
from fluent_contents.models import ContentItem
from fluent_pages.urlresolvers import app_reverse, PageTypeNotMounted
from icekit.publishing.models import PublishingModel

from icekit.models import ICEkitContentsMixin
from timezone import timezone
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _

from icekit.content_collections.abstract_models import AbstractCollectedContent, \
TitleSlugMixin, AbstractListingPage
Expand Down Expand Up @@ -36,7 +33,7 @@ class Meta:

python_2_unicode_compatible
class PressRelease(
PublishingModel,
ICEkitContentsMixin,
AbstractCollectedContent,
TitleSlugMixin,
FluentFieldsMixin
Expand Down

0 comments on commit 0077972

Please sign in to comment.