from zope.interface import implementer
from Acquisition import aq_parent
from AccessControl import ClassSecurityInfo
from DateTime import DateTime
from Products.Archetypes import atapi
from Products.CMFCore.permissions import ModifyPortalContent
from Products.CMFDynamicViewFTI.browserdefault import BrowserDefaultMixin
from plone.app.event.base import DT
from plone.formwidget.datetime.at import DatetimeWidget
from bda.plone.shop.interfaces import IBuyable
from ..interfaces import ITicketOccurrence
from ..config import PROJECTNAME
from .. import _


schema = atapi.Schema((

    atapi.DateTimeField('startDate',
        required=True,
        searchable=False,
        accessor='start',
        write_permission=ModifyPortalContent,
        languageIndependent=True,
        widget=DatetimeWidget(
            label=_(u'label_start', default=u'Start'),
            description=_(u'help_start',
                          default=u"Date and Time"),
            ),
        ),

    atapi.DateTimeField('endDate',
        required=True,
        searchable=False,
        accessor='end',
        write_permission=ModifyPortalContent,
        languageIndependent=True,
        widget=DatetimeWidget(
            label=_(u'label_end', default=u'End'),
            description=_(u'help_end',
                          default=u"Date and Time"),
            ),
        ),
))


TicketOccurrence_schema = atapi.BaseSchema.copy() + schema.copy()


@implementer(ITicketOccurrence, IBuyable)
class TicketOccurrence(atapi.BaseContent, BrowserDefaultMixin):
    security = ClassSecurityInfo()
    portal_type = 'Ticket Occurrence'
    meta_type = 'TicketOccurrence'
    _at_rename_after_creation = True
    schema = TicketOccurrence_schema
    exclude_from_nav = True

    security.declareProtected('View', 'start')
    def start(self):
        return self.getStartDate()

    security.declareProtected('View', 'end')
    def end(self):
        return self.getEndDate()

atapi.registerType(TicketOccurrence, PROJECTNAME)

@@ -2,75 +2,95 @@
 rom 
-zope.interface import implementer%0Afrom Acquisition import aq_parent
+.. import _%0Afrom ..config import PROJECTNAME%0Afrom ..interfaces import ITicketOccurrence
 %0Afro
@@ -134,38 +134,8 @@
 nfo%0A
-from DateTime import DateTime%0A
 from
@@ -312,36 +312,80 @@
 rom 
+bda.
 plone.
-app
+shop.interfaces import IBuyable%0Afrom plone
 .event.
-base
+utils
  import 
 DT%0Af
@@ -384,10 +384,12 @@
 ort 
-DT
+pydt
 %0Afro
@@ -442,38 +442,28 @@
 Widget%0Afrom 
-bda.plone.sh
+z
 op
+e
 .interfaces 
@@ -456,33 +456,32 @@
 pe.interface
-s
  import 
 IBuyable%0Afro
@@ -472,109 +472,19 @@
 ort 
-IBuyable%0Afrom ..interfaces import ITicketOccurrence%0Afrom ..config import PROJECTNAME%0Afrom .. import _
+implementer
 %0A%0A%0As
@@ -1728,16 +1728,25 @@
 , 'start
+_date_iso
 ')%0A    d
@@ -1753,16 +1753,25 @@
 ef start
+_date_iso
 (self):%0A
@@ -1777,32 +1777,37 @@
 %0A        return 
+pydt(
 self.getStartDat
@@ -1809,16 +1809,49 @@
 rtDate()
+, exact=False).date().isoformat()
 %0A%0A    se
@@ -1886,16 +1886,25 @@
 w', 'end
+_date_iso
 ')%0A    d
@@ -1909,16 +1909,25 @@
  def end
+_date_iso
 (self):%0A
@@ -1941,16 +1941,21 @@
  return 
+pydt(
 self.get
@@ -1963,16 +1963,49 @@
 ndDate()
+, exact=False).date().isoformat()
 %0A%0Aatapi.

add end/start_date_iso to build annotation ids