Permalink
Browse files

Merge pull request #102 from evildmp/newsandevents

news and events minor formatting changes
  • Loading branch information...
2 parents 3c435a1 + dda597b commit 83de42812ea4b2b668f7717fab433cb0ffee4026 @evildmp committed May 30, 2013
Showing with 84 additions and 84 deletions.
  1. +29 −29 news_and_events/admin.py
  2. +55 −55 news_and_events/models.py
View
58 news_and_events/admin.py
@@ -20,7 +20,7 @@
class NewsAndEventsForm(GenericModelForm):
# a shared form for news and events
pass
-
+
from contacts_and_people.models import Entity
class NewsAndEventsAdmin(GenericModelAdmin):
@@ -34,12 +34,12 @@ class NewsAndEventsAdmin(GenericModelAdmin):
}
list_max_show_all = 1000
list_per_page = 1000
-
+
def _media(self):
return super(ModelAdminWithTabsAndCMSPlaceholder, self).media
media = property(_media)
-# this or something like it can be enabled when the
+# this or something like it can be enabled when the
# autocomplete-stop-sworking-after-adding-an-inlin
# bug has been addressed
# it will hugely speed up loading of news, events etc with lots of people in the m2m
@@ -51,22 +51,22 @@ def _media(self):
# def _media(self):
# return super(AutocompleteMixin, self).media
# media = property(_media)
-
+
class NewsArticleForm(NewsAndEventsForm):
class Meta(NewsAndEventsForm.Meta):
model = NewsArticle
-
+
def clean(self):
super(NewsArticleForm, self).clean()
-
+
# sticky_until value must be greater than (later) than date
date = datetime.date(self.cleaned_data['date'])
- self.cleaned_data['sticky_until'] = self.cleaned_data.get('sticky_until', date)
+ self.cleaned_data['sticky_until'] = self.cleaned_data.get('sticky_until', date)
# if importance = 0, it's not sticky
self.cleaned_data['sticky_until'] = self.cleaned_data['sticky_until'] or datetime.date(self.cleaned_data['date'])
if self.cleaned_data['importance'] == 0:
- self.cleaned_data['sticky_until'] = None
+ self.cleaned_data['sticky_until'] = None
elif self.cleaned_data['sticky_until'] < datetime.date(self.cleaned_data['date']):
self.cleaned_data['sticky_until'] = datetime.date(self.cleaned_data['date'])
return self.cleaned_data
@@ -79,9 +79,9 @@ class NewsArticleAdmin(NewsAndEventsAdmin):
read_only_fields = ('sticky_until')
filter_horizontal = (
'please_contact',
- 'publish_to',
+ 'publish_to',
)
- # inlines = [MembershipInline,]
+ # inlines = [MembershipInline,]
fieldset_stickiness = ('How this item should behave in lists', {'fields': ('sticky_until', 'is_sticky_everywhere',)})
tabs = (
('Basic', {'fieldsets': (fieldsets["basic"], fieldsets["host"], fieldsets["image"], fieldsets["publishing_control"],),}),
@@ -90,7 +90,7 @@ class NewsArticleAdmin(NewsAndEventsAdmin):
('Where to Publish', {'fieldsets': (fieldsets["where_to_publish"],)}),
('Related people', {'fieldsets': (fieldsets["people"],)}),
('Links', {'inlines': (ObjectLinkInline,),}),
- ('Advanced Options', {'fieldsets': (fieldsets["url"], fieldsets["slug"],)}),
+ ('Advanced Options', {'fieldsets': (fieldsets["url"], fieldsets["slug"],)}),
)
class EventForm(NewsAndEventsForm):
@@ -108,7 +108,7 @@ def clean(self):
print "checking parent field_content"
self.cleaned_data[field_name] = self.cleaned_data[field_name] or list(getattr(parent,field_name).all())
# other fields
- attribute_list = ['building', 'precise_location', 'hosted_by', 'access_note']
+ attribute_list = ['building', 'precise_location', 'hosted_by', 'access_note']
for field_name in attribute_list:
print "checking which attributes to inherit:", field_name
self.cleaned_data[field_name] = self.cleaned_data[field_name] or getattr(parent,field_name)
@@ -124,11 +124,11 @@ def clean(self):
# 2. go and do the checks in the parent class
super(EventForm, self).clean()
-
+
# 3. check dates
if self.cleaned_data["start_date"]:
if self.cleaned_data["series"]:
- raise forms.ValidationError("An event with a start date can't also be a series of events. Please correct this.")
+ raise forms.ValidationError("An event with a start date can't also be a series of events. Please correct this.")
elif self.cleaned_data["end_date"] == self.cleaned_data["start_date"]:
self.cleaned_data["single_day_event"] = True
elif not self.cleaned_data["end_date"]:
@@ -142,19 +142,19 @@ def clean(self):
self.cleaned_data["end_time"] = None
message = u"You didn't enter a start time, so I deleted the end time. I hope that's OK."
messages.add_message(self.request, messages.WARNING, message)
-
- if self.cleaned_data["single_day_event"]:
+
+ if self.cleaned_data["single_day_event"]:
self.cleaned_data["end_date"] = self.cleaned_data["start_date"]
if not self.cleaned_data["start_time"]:
message = u"You have a lovely smile."
messages.add_message(self.request, messages.INFO, message)
self.cleaned_data["end_time"] = None
elif self.cleaned_data["end_time"] and self.cleaned_data["end_time"] < self.cleaned_data["start_time"]:
raise forms.ValidationError('This event appears to end before it starts, which is very silly. Please correct the times.')
-
+
self.cleaned_data['jumps_queue_on'] = self.cleaned_data['jumps_queue_on'] or self.cleaned_data['start_date']
if self.cleaned_data['importance'] == 0:
- self.cleaned_data['jumps_queue_on'] = None
+ self.cleaned_data['jumps_queue_on'] = None
elif self.cleaned_data['jumps_queue_on'] > self.cleaned_data['start_date']:
self.cleaned_data['jumps_queue_on'] = self.cleaned_data['start_date']
@@ -165,7 +165,7 @@ def clean(self):
messages.add_message(self.request, messages.INFO, message)
self.cleaned_data['start_date'] = self.cleaned_data['end_date'] = self.cleaned_data['start_time'] = self.cleaned_data['end_time'] = None
self.cleaned_data['single_day_event'] = False
- self.cleaned_data['jumps_queue_on'] = None
+ self.cleaned_data['jumps_queue_on'] = None
self.cleaned_data['importance'] = 0
return self.cleaned_data
@@ -198,14 +198,14 @@ def queryset(self, request, queryset):
class EventAdmin(NewsAndEventsAdmin, TreeAdmin):
-
+
# some general settings
form = EventForm
filter_horizontal = (
'please_contact',
- 'publish_to',
+ 'publish_to',
'registration_enquiries',
- 'featuring',
+ 'featuring',
)
ordering = ['type',]
list_display = ('short_title', 'hosted_by', 'start_date')
@@ -230,15 +230,15 @@ class EventAdmin(NewsAndEventsAdmin, TreeAdmin):
('When displaying the children of this item in lists', {
'fields': ('show_titles', 'display_series_summary',),},),
)
- fieldset_registration = ('Registration enquiries', {'fields': ('registration_enquiries',)})
- fieldset_featuring = ('Featured people', {'fields': ('featuring',)})
+ fieldset_registration = ('Registration enquiries', {'fields': ('registration_enquiries',)})
+ fieldset_featuring = ('Featured people', {'fields': ('featuring',)})
fieldset_jumpiness = ('How this item should behave in lists', {'fields': ('jumps_queue_on', 'jumps_queue_everywhere')})
tabs = (
('Basic', {'fieldsets': (fieldsets["basic"], fieldset_type, fieldsets["host"], fieldsets["image"], fieldsets["publishing_control"],)}),
- ('Date & significance', {'fieldsets':
- (
- fieldset_when,
- fieldsets["importance"],
+ ('Date & significance', {'fieldsets':
+ (
+ fieldset_when,
+ fieldsets["importance"],
fieldset_jumpiness,)}
),
('Location', {'fieldsets': (fieldset_building, fieldsets["location"],)}),
@@ -247,7 +247,7 @@ class EventAdmin(NewsAndEventsAdmin, TreeAdmin):
('Where to Publish', {'fieldsets': (fieldsets["where_to_publish"],)}),
('People', {'fieldsets': (fieldset_featuring, fieldsets["people"], fieldset_registration)}),
('Links', {'inlines': (ObjectLinkInline,),}),
- ('Advanced Options', {'fieldsets': (fieldsets["url"], fieldsets["slug"],)}),
+ ('Advanced Options', {'fieldsets': (fieldsets["url"], fieldsets["slug"],)}),
)
View
110 news_and_events/models.py
@@ -26,9 +26,9 @@
class NewsAndEvents(ArkestraGenericModel, URLModelMixin):
- content = models.TextField(null=True, blank=True,
+ content = models.TextField(null=True, blank=True,
help_text="Not used or required for external items")
-
+
class Meta:
abstract = True
@@ -37,27 +37,27 @@ def save(self, *args, **kwargs):
def link_to_more(self):
if self.get_hosted_by:
- return self.get_hosted_by.get_related_info_page_url("news-and-events")
+ return self.get_hosted_by.get_related_info_page_url("news-and-events")
class NewsArticle(NewsAndEvents):
url_path = "news"
objects = ArkestraGenericModelManager()
-
+
date = models.DateTimeField(default=datetime.now,
help_text=u"Dateline for the item (the item will not be published until then" , )
display_indefinitely = models.BooleanField(
- help_text=u"Important news; it won't expire from news lists" , )
- external_news_source = models.ForeignKey('NewsSource', null=True, blank=True,
+ help_text=u"Important news; it won't expire from news lists" , )
+ external_news_source = models.ForeignKey('NewsSource', null=True, blank=True,
help_text=u"If this news item is from an external source")
- sticky_until = models.DateField(u"Featured until",
+ sticky_until = models.DateField(u"Featured until",
null=True, blank=True, default=pythondate.today,
help_text=u"Will remain a featured item until this date")
is_sticky_everywhere = models.BooleanField(u"Featured everywhere",
- default=False, help_text=u"Will be featured in other entities's news lists")
-
+ default=False, help_text=u"Will be featured in other entities's news lists")
+
class Meta:
ordering = ['-date']
-
+
@property
def has_expired(self):
# the item is too old to appear in current lists, and should only be listed in archives
@@ -72,7 +72,7 @@ def get_when(self):
Usually, this is an easily-readble rendering of the date (e.g. "April 2010") but it can also be "Top news", for items to be given special prominence.
"""
if getattr(self, "sticky", None):
- return "Top news"
+ return "Top news"
get_when = nice_date(self.date, ARKESTRA_DATE_FORMATS["date_groups"])
return get_when
@@ -86,8 +86,8 @@ class Event(NewsAndEvents, LocationModelMixin):
featuring = models.ManyToManyField(Person, related_name='%(class)s_featuring',
null=True, blank=True,
help_text="The speakers, lecturers, instructors or other people featured in this event")
- parent = models.ForeignKey('self',
- blank=True, null=True,
+ parent = models.ForeignKey('self',
+ blank=True, null=True,
on_delete=models.PROTECT,
related_name='children')
SERIES = (
@@ -108,52 +108,52 @@ class Event(NewsAndEvents, LocationModelMixin):
DISPLAY_SERIES_SUMMARY = (
(False, u"display children's summaries"),
(True, u"display the summary for the series"),
- )
+ )
display_series_summary = models.BooleanField(u"Summaries",
default=False,
choices=DISPLAY_SERIES_SUMMARY,
)
- child_list_heading = models.CharField(max_length=50, null=True, blank=True,
+ child_list_heading = models.CharField(max_length=50, null=True, blank=True,
help_text= u"e.g. Conference sessions; Lectures in this series")
start_date = models.DateField(null=True, blank=True,
- help_text=u"Not required for a series of events")
- start_time = models.TimeField(null=True, blank=True)
+ help_text=u"Not required for a series of events")
+ start_time = models.TimeField(null=True, blank=True)
end_date = models.DateField(null=True, blank=True)
end_time = models.TimeField(null=True, blank=True)
single_day_event = models.BooleanField(default=False)
- building = models.ForeignKey(Building,
+ building = models.ForeignKey(Building,
null=True, blank=True,
on_delete=models.SET_NULL)
jumps_queue_on = models.DateField(null=True, blank=True,
- help_text=u"Will become a featured item on this date")
+ help_text=u"Will become a featured item on this date")
jumps_queue_everywhere = models.BooleanField(default=False)
- registration_enquiries = models.ManyToManyField(Person,
- related_name = '%(class)s_registration',
+ registration_enquiries = models.ManyToManyField(Person,
+ related_name = '%(class)s_registration',
null = True, blank = True,
help_text=u"The people who responsible for registration, if different from those in <em>Please contact</em>"
- )
-
+ )
+
class Meta:
ordering = ['type', 'start_date', 'start_time']
-
+
@property
def informative_url(self):
- """
+ """
An event has an 'informative_url' if it itself is uninformative, but it is a child of a series
"""
- # print
+ # print
# print "========================================"
# print "checking", self
# print "is_uninformative", self.is_uninformative
# print "self.parent", self.parent
- #
+ #
if self.is_uninformative and self.parent and self.parent.series:
# print self, "parent!"
return self.parent.get_absolute_url()
else:
# print self, "self!"
return self.get_absolute_url()
-
+
@property
def show_parent_series(self):
"""
@@ -164,7 +164,7 @@ def show_parent_series(self):
@property
def is_uninformative(self):
- # print
+ # print
# print "============================"
# print self.body
# if self.body:
@@ -179,7 +179,7 @@ def is_uninformative(self):
else:
# print "informative"
return True
-
+
def save(self):
def slug_is_bad(self):
if self.slug in [slug.values()[0] for slug in Event.objects.exclude(id=self.id).values("slug")]:
@@ -206,28 +206,28 @@ def slug_is_bad(self):
self.slug=self.slug + "-x"
# print "adding suffix:", "-x"
super(Event, self).save()
-
+
def get_children_forthcoming(self):
if self.series:
return self.children.filter(Q(start_date__gte = datetime.now()) | Q(end_date__gte = datetime.now()) | Q(series = True)).order_by('start_date')
else:
return self.children.all()
-
+
def get_children_previous(self):
if self.series:
return self.children.filter(Q(start_date__lt = datetime.now()) | Q(end_date__lt = datetime.now()) | Q(series = True)).order_by('-start_date')
-
+
def get_featuring(self, featuring = None):
featuring = set(self.featuring.all()) or set()
if not self.series:
for child_event in self.children.all():
featuring.update(child_event.get_featuring(featuring))
return featuring
-
+
@property
def date(self):
return self.start_date
-
+
def get_date_if_needed_and_time_heading(self):
date_time_heading = []
if not self.series:
@@ -236,17 +236,17 @@ def get_date_if_needed_and_time_heading(self):
if self.get_times():
date_time_heading.append("time")
return date_time_heading
-
+
def get_date_if_needed_and_time(self):
date_and_time = []
date = self.get_dates()
time = self.get_times()
if self.parent.single_day_event and not time:
date_and_time.append(date)
if time:
- date_and_time.append(time)
+ date_and_time.append(time)
return date_and_time
-
+
def get_dates(self):
if not self.series:
start_date = self.start_date
@@ -258,7 +258,7 @@ def get_dates(self):
if start_date.year == end_date.year: # start and end in the same year, so:
start_date_format = ARKESTRA_DATE_FORMATS["not_this_month"] # start format example: "3rd May"
if start_date.month == end_date.month: # start and end in the same month, so:
- start_date_format = ARKESTRA_DATE_FORMATS["this_month"] # start format example: "21st"
+ start_date_format = ARKESTRA_DATE_FORMATS["this_month"] # start format example: "21st"
if end_date.year == now.year: # they're both this year, so:
end_date_format = ARKESTRA_DATE_FORMATS["not_this_month"] # end format example: "23rd May"
if self.single_day_event:
@@ -268,7 +268,7 @@ def get_dates(self):
return dates
else:
return "Series"
-
+
def get_times(self):
start_time = self.start_time
if self.single_day_event and start_time:
@@ -278,7 +278,7 @@ def get_times(self):
else:
times = time(start_time)
return times
-
+
def get_image(self):
return self.image or (self.parent.get_image() if self.parent else None)
@@ -305,8 +305,8 @@ def check_date(self): # we need somehow to send a message to the user about this
if need_to_save:
self.single_day_event = False
self.save()
- return
-
+ return
+
def apply_parent_attributes(self): # is this required?
print "we're in event.apply_parent_attributes - the question is why"
if self.parent:
@@ -319,14 +319,14 @@ def calculated_summary(self):
if self.parent and self.parent.display_series_summary:
return self.parent.summary
else:
- return self.summary
+ return self.summary
- @property
+ @property
def get_when(self):
if self.start_date:
if getattr(self, "sticky", None):
return "Top events"
-
+
#return self.start_date
#now = datetime.now()
date_format = "F Y" # Aikido Cardiff version
@@ -342,31 +342,31 @@ def get_when(self):
#return when_heading
elif self.series:
return "Regular events"
-
-
+
+
def get_admin_title(self):
return self.title + " (" + self.get_dates() + ")"
class EventType(models.Model):
event_type = models.CharField(max_length=50)
-
+
class Meta:
ordering = ['event_type']
-
+
def __unicode__(self):
return self.event_type
class NewsSource(models.Model):
external_news_source = models.CharField(max_length=50)
-
+
def __unicode__(self):
return self.external_news_source
def receiver_function(sender, **kwargs):
- event = kwargs['instance']
+ event = kwargs['instance']
event.get_root().check_date()
post_save.connect(receiver_function, sender = Event)
@@ -382,13 +382,13 @@ class NewsAndEventsPlugin(CMSPlugin, ArkestraGenericPluginOptions):
show_previous_events = models.BooleanField()
news_heading_text = models.CharField(max_length=25, default=_(u"News"))
events_heading_text = models.CharField(max_length=25, default=_(u"Events"))
-
+
try:
mptt.register(Event)
except mptt.AlreadyRegistered:
- pass
+ pass
-'''
+'''
entity: ('name',)
building: ('name', 'number', 'street', 'postcode', 'site__site_name',)
website: ('title_set__title',)

0 comments on commit 83de428

Please sign in to comment.