Esempio n. 1
0
    def __call__(self):
        context = self.context

        eventPhysicalPath = '/'.join(context.getPhysicalPath())
        wft = getToolByName(context, 'portal_workflow')
        state = wft.getInfoFor(context, 'review_state')
        member = context.portal_membership.getAuthenticatedMember()
        editable = bool(member.has_permission('Modify portal content', context))
        allday = (context.end() - context.start()) > 1.0

        adapted = interfaces.ISFBaseEventFields(context, None)
        if adapted:
            allday = adapted.allDay

        copycut = ''
        if self.copyDict and eventPhysicalPath == self.copyDict['url']:
            copycut = self.copyDict['op'] == 1 and ' event_cutted' or ' event_copied'

        typeClass = ' type-' + context.portal_type
        colorIndex = getColorIndex(context, self.request, eventPhysicalPath)
        extraClass = self.getExtraClass()
        return {"status": "ok",
                "id": "UID_%s" % context.UID(),
                "title": context.Title(),
                "description": context.Description(),
                "start": context.start().rfc822(),
                "end": context.end().rfc822(),
                "url": context.absolute_url(),
                "editable": editable,
                "allDay": allday,
                "className": "contextualContentMenuEnabled state-" + str(state) + (editable and " editable" or "")+copycut+typeClass+colorIndex+extraClass}
Esempio n. 2
0
    def __call__(self):
        request = self.context.REQUEST
        event_uid = request.get('event')

        if event_uid:
            event_uid = event_uid.split('UID_')[1]

        brains = self.context.portal_catalog(UID=event_uid)
        obj = brains[0].getObject()
        startDate, endDate = starts(obj), ends(obj)
        dayDelta, minuteDelta = float(request.get('dayDelta', 0)), float(
            request.get('minuteDelta', 0))
        startDate = startDate + dayDelta + minuteDelta / 1440.0
        endDate = endDate + dayDelta + minuteDelta / 1440.0

        if HAS_PAE and not hasattr(obj, 'setStartDate'):
            # non-Archetypes duck type: use properties for start/end,
            # along with UTC-normalized datetime.datetime values
            from plone.event.utils import pydt
            obj.start = pydt(startDate)
            obj.end = pydt(endDate)
        else:
            obj.setStartDate(startDate)
            obj.setEndDate(endDate)
        adapted = interfaces.ISFBaseEventFields(obj, None)
        if adapted:
            if request.get('allDay', None) == 'true':
                setattr(adapted, 'allDay', True)
            if request.get('allDay', None) == 'false':
                setattr(adapted, 'allDay', False)

        obj.reindexObject()
        return True
Esempio n. 3
0
    def dictFromObject(self, item):
        eventPhysicalPath = '/'.join(item.getPhysicalPath())
        wft = getToolByName(self.context, 'portal_workflow')
        state = wft.getInfoFor(self.context, 'review_state')
        member = self.context.portal_membership.getAuthenticatedMember()
        if member.has_permission('Modify portal content', item):
            editable = True

        if item.end() - item.start() > 1.0:
            allday = True
        else:
            allday = False

        adapted = interfaces.ISFBaseEventFields(item, None)
        if adapted:
            allday = adapted.allDay

        copycut = ''
        if self.copyDict and eventPhysicalPath == self.copyDict['url']:
            copycut = self.copyDict[
                'op'] == 1 and ' event_cutted' or ' event_copied'

        typeClass = ' type-' + item.portal_type
        colorIndex = getColorIndex(self.context, self.request,
                                   eventPhysicalPath)
        extraClass = self.getObjectExtraClass(item)
        if hasPloneAppEvent:
            occurences = item.occurrences()
        else:
            occurences = [(item.start().rfc822(), item.end().rfc822())]
        events = []
        for occurence_start, occurence_end in occurences:
            events.append({
                "status":
                "ok",
                "id":
                "UID_%s" % (item.UID()),
                "title":
                item.Title(),
                "description":
                item.Description(),
                "start":
                hasPloneAppEvent and occurence_start.isoformat()
                or occurence_start,
                "end":
                hasPloneAppEvent and occurence_end.isoformat()
                or occurence_end,
                "url":
                item.absolute_url(),
                "editable":
                editable,
                "allDay":
                allday,
                "className":
                "contextualContentMenuEnabled state-" + str(state) +
                (editable and " editable" or "") + copycut + typeClass +
                colorIndex + extraClass
            })

        return events
Esempio n. 4
0
    def __call__(self):
        request = self.context.REQUEST
        event_uid = request.get('event')

        if event_uid:
            event_uid = event_uid.split('UID_')[1]

        brains = self.context.portal_catalog(UID=event_uid)

        obj = brains[0].getObject()
        startDate, endDate = obj.start(), obj.end()
        dayDelta, minuteDelta = float(request.get('dayDelta')), float(
            request.get('minuteDelta'))

        startDate = startDate + dayDelta + minuteDelta / 1440.0
        endDate = endDate + dayDelta + minuteDelta / 1440.0

        obj.setStartDate(startDate)
        obj.setEndDate(endDate)

        adapted = interfaces.ISFBaseEventFields(obj, None)
        if adapted:
            if request.get('allDay', None) == 'true':
                setattr(adapted, 'allDay', True)
            if request.get('allDay', None) == 'false':
                setattr(adapted, 'allDay', False)

        obj.reindexObject()
        return True
Esempio n. 5
0
    def getEvents(self):
        context = self.context
        eventPhysicalPath = '/'.join(context.getPhysicalPath())
        wft = getToolByName(context, 'portal_workflow')
        state = wft.getInfoFor(context, 'review_state')
        member = context.portal_membership.getAuthenticatedMember()
        editable = bool(member.has_permission('Modify portal content',
                                              context))
        allday = (context.end() - context.start()) > 1.0

        adapted = interfaces.ISFBaseEventFields(context, None)
        if adapted:
            allday = adapted.allDay
        if hasattr(context, 'whole_day'):
            allday = context.whole_day
        extraClass = self.getObjectExtraClass()
        typeClass = ' type-' + context.portal_type

        if HAS_RECURRENCE_SUPPORT:
            start = DateTime(self.request.get('start'))
            end = DateTime(self.request.get('end'))
            occurences = IRecurrence(context).occurrences(limit_start=start,
                                                          limit_end=end)
        else:
            occurences = [(context.start().rfc822(), context.end().rfc822())]
        events = []
        for occurence_start, occurence_end in occurences:
            events.append({
                "status":
                "ok",
                "id":
                "UID_%s" % (context.UID()),
                "title":
                context.Title(),
                "description":
                context.Description(),
                "start":
                HAS_RECURRENCE_SUPPORT and occurence_start.isoformat()
                or occurence_start,
                "end":
                HAS_RECURRENCE_SUPPORT and occurence_end.isoformat()
                or occurence_end,
                "url":
                context.absolute_url(),
                "editable":
                editable,
                "allDay":
                allday,
                "className":
                "contextualContentMenuEnabled state-" + str(state) +
                (editable and " editable" or "") + typeClass + extraClass
            })
        return events
Esempio n. 6
0
    def dict_from_item(item):
        if hasPloneAppEvent and (IEvent.providedBy(item) or
                                 IOccurrence.providedBy(item)):
            # plone.app.event DX or AT Event
            is_occurrence = IOccurrence.providedBy(item)
            acc = IEventAccessor(item)
            return {
                "status": "ok",
                "id": "UID_%s" % (acc.uid),
                "title": acc.title,
                "description": acc.description,
                "start": acc.start.isoformat(),
                "end": acc.end.isoformat(),
                "url": acc.url,
                "editable": editable,
                "allDay": acc.whole_day,
                "className": "contextualContentMenuEnabled %s %s %s %s" % (
                                state and "state-%s" % str(state) or "",
                                editable and "editable" or "",
                                css and css or "",
                                is_occurrence and "occurrence" or ""),
                "color": color}
        elif IATEvent.providedBy(item):
            # Products.ATContentTypes ATEvent
            allday = (item.end() - item.start()) > 1.0
            adapted = interfaces.ISFBaseEventFields(item, None)
            if adapted:
                allday = adapted.allDay

            return {
                "status": "ok",
                "id": "UID_%s" % (item.UID()),
                "title": item.Title(),
                "description": item.Description(),
                "start": item.start().ISO8601(),
                "end": item.end().ISO8601(),
                "url": item.absolute_url(),
                "editable": editable,
                "allDay": allday,
                "className": "contextualContentMenuEnabled %s %s %s" % (
                                state and "state-%s" % str(state) or "",
                                editable and "editable" or "",
                                css and css or ""),
                "color": color}
        elif ICatalogBrain.providedBy(item):
            # Event catalog brain
            if type(item.end) != DateTime:
                brainend = DateTime(item.end)
                brainstart = DateTime(item.start)
            else:
                brainend = item.end
                brainstart = item.start

            allday = (brainend - brainstart) > 1.0

            if getattr(item, 'SFAllDay', None) in [False, True]:
                allday = item.SFAllDay

            return {
                "status": "ok",
                "id": "UID_%s" % (item.UID),
                "title": item.Title,
                "description": item.Description,
                "start": brainstart.ISO8601(),
                "end": brainend.ISO8601(),
                "url": item.getURL(),
                "editable": editable,
                "allDay": allday,
                "className": "contextualContentMenuEnabled %s %s %s" % (
                                state and "state-%s" % str(state) or "",
                                editable and "editable" or "",
                                css and css or ""),
                "color": color}
        else:
            raise ValueError('item type not supported for: %s' % repr(item))