Fix #30 -- Event microdata information (#546)

* Addition of all basics required for microdata

Microdata for event added to the head of the base event html template.

* Fixed flake8 errors & included settings checks

Fixed the flake8 too many blank line errors and changed the date and time section to refer to settings before including the time and/or the date_to.

* Typo in last commit

Fixed typo in last commit

* Fixed bracket mistake and flake8 error

Fixed tab between { and % in template tag. Removed extra lines. Removed unnecessary str() call.
Corrected binary & to [and] operator.

* Added testing for microdata

Testing added to the presale.test_event tests to cover the 4 branches and basic microdata functionality.
This commit is contained in:
Joepriesto
2017-07-16 16:42:46 +01:00
committed by Raphael Michel
parent 9582f8380f
commit 27b73227ed
3 changed files with 71 additions and 0 deletions

View File

@@ -365,6 +365,26 @@ class Event(EventMixin, LoggedModel):
providers[pp.identifier] = pp
return providers
@property
def event_microdata(self):
import json
eventdict = {"@context": "http://schema.org", "@type": "Event"}
eventdict["location"] = {"@type": "Place",
"address": str(self.location)}
if self.settings.show_times:
eventdict["startDate"] = self.date_from.isoformat()
if self.settings.show_date_to and self.date_to is not None:
eventdict["endDate"] = self.date_to.isoformat()
else:
eventdict["startDate"] = self.date_from.date().isoformat()
if self.settings.show_date_to and self.date_to is not None:
eventdict["endDate"] = self.date_to.date().isoformat()
eventdict["name"] = str(self.name)
return json.dumps(eventdict)
def get_invoice_renderers(self) -> dict:
"""
Returns a dictionary of initialized invoice renderers mapped by their identifiers.