def __call__(self): title = safe_unicode(self.context.title_or_id()) mtool = getToolByName(self.context, 'portal_membership') self.request.response.setHeader("Content-type","application/json") if not mtool.checkPermission('Copy or Move', self.context): message = PLMF(u'Permission denied to copy ${title}.', mapping={u'title' : title}) status = 'error' raise json.dumps({'status':status, 'message':self.context.translate(message)}) parent = aq_parent(aq_inner(self.context)) try: cp = parent.manage_copyObjects(self.context.getId()) status = 'copied' except CopyError: status = 'error' message = PLMF(u'${title} is not copyable.', mapping={u'title' : title}) return json.dumps({'status':status, 'message':parent.translate(message)}) message = PLMF(u'${title} copied.', mapping={u'title' : title}) transaction_note('Copied object %s' % self.context.absolute_url()) contextId = 'UID_' + get_uid(self.context) return json.dumps({'status':status, 'message':self.context.translate(message), 'cp':cp, 'id':contextId})
def __call__(self): title = safe_unicode(self.context.title_or_id()) mtool = getToolByName(self.context, 'portal_membership') self.request.response.setHeader("Content-type", "application/json") if not mtool.checkPermission('Copy or Move', self.context): message = PLMF(u'Permission denied to copy ${title}.', mapping={u'title': title}) status = 'error' raise json.dumps({ 'status': status, 'message': self.context.translate(message) }) parent = aq_parent(aq_inner(self.context)) try: cp = parent.manage_copyObjects(self.context.getId()) status = 'copied' except CopyError: status = 'error' message = PLMF(u'${title} is not copyable.', mapping={u'title': title}) return json.dumps({ 'status': status, 'message': parent.translate(message) }) message = PLMF(u'${title} copied.', mapping={u'title': title}) transaction_note('Copied object %s' % self.context.absolute_url()) contextId = 'UID_' + get_uid(self.context) return json.dumps({ 'status': status, 'message': self.context.translate(message), 'cp': cp, 'id': contextId })
def __call__(self): eventid = 'UID_' + get_uid(self.context) parent = self.context.aq_inner.aq_parent title = safe_unicode(self.context.title_or_id()) try: lock_info = self.context.restrictedTraverse('@@plone_lock_info') except AttributeError: lock_info = None if lock_info is not None and lock_info.is_locked(): status = 'locked' message = PLMF(u'${title} is locked and cannot be deleted.', mapping={u'title': title}) else: parent.manage_delObjects(self.context.getId()) status = 'ok' message = PLMF(u'${title} has been deleted.', mapping={u'title': title}) transaction_note('Deleted %s' % self.context.absolute_url()) self.request.response.setHeader("Content-type", "application/json") return json.dumps({ 'status': status, 'message': parent.translate(message), 'id': eventid })
def __call__(self): msg = PLMF(u'Copy or cut one or more items to paste.') self.request.response.setHeader("Content-type", "application/json") if self.context.cb_dataValid(): try: baseObject = self.portal.restrictedTraverse( self.copyDict['url']) baseId = 'UID_' + get_uid(baseObject) intervalle = ends(baseObject) - starts(baseObject) cb_copy_data = self.request['__cp'] pasteList = self.context.manage_pasteObjects( cb_copy_data=cb_copy_data) newObject = getattr(self.context, pasteList[0]['new_id']) startDate = self.startDate if self.EventAllDay: startDate = DateTime(self.startDate).strftime( '%Y-%m-%d ') + starts(baseObject).strftime('%H:%M') if HAS_PAE and not hasattr(newObject, 'setStartDate'): # non-Archetypes duck type: use properties for start/end, # along with UTC-normalized datetime.datetime values from plone.event.utils import pydt import pytz local_start = DateTime(startDate) _utc = lambda dt: pytz.UTC.normalize(dt) newObject.start = _utc(pydt(local_start)) newObject.end = _utc(pydt(local_start + intervalle)) newObject.whole_day = self.EventAllDay else: newObject.setStartDate(DateTime(startDate)) newObject.setEndDate( newObject.getField('startDate').get(newObject) + intervalle) newObject.reindexObject() transaction_note('Pasted content to %s' % (self.context.absolute_url())) return json.dumps({ 'status': 'pasted', 'event': self.createJsonEvent(newObject), 'url': newObject.absolute_url(), 'op': self.copyDict['op'], 'id': baseId }) except ConflictError: raise except ValueError: msg = PLMF(u'Disallowed to paste item(s).') except (Unauthorized, 'Unauthorized'): msg = PLMF(u'Unauthorized to paste item(s).') except CopyError: # fallback msg = PLMF(u'Paste could not find clipboard content.') return json.dumps({ 'status': 'failure', 'message': self.context.translate(msg) })
def __call__(self): msg=PLMF(u'Copy or cut one or more items to paste.') self.request.response.setHeader("Content-type","application/json") if self.context.cb_dataValid(): try: baseObject = self.portal.restrictedTraverse(self.copyDict['url']) baseId = 'UID_' + get_uid(baseObject) intervalle = ends(baseObject) - starts(baseObject) cb_copy_data = self.request['__cp'] pasteList = self.context.manage_pasteObjects(cb_copy_data=cb_copy_data) newObject = getattr(self.context, pasteList[0]['new_id']) startDate = self.startDate if self.EventAllDay: startDate = DateTime(self.startDate).strftime('%Y-%m-%d ')+starts(baseObject).strftime('%H:%M') if HAS_PAE and not hasattr(newObject, 'setStartDate'): # non-Archetypes duck type: use properties for start/end, # along with UTC-normalized datetime.datetime values from plone.event.utils import pydt import pytz local_start = DateTime(startDate) _utc = lambda dt: pytz.UTC.normalize(dt) newObject.start = _utc(pydt(local_start)) newObject.end = _utc(pydt(local_start + intervalle)) newObject.whole_day = self.EventAllDay else: newObject.setStartDate(DateTime(startDate)) newObject.setEndDate(newObject.getField('startDate').get(newObject) + intervalle) newObject.reindexObject() transaction_note('Pasted content to %s' % (self.context.absolute_url())) return json.dumps({'status':'pasted', 'event':self.createJsonEvent(newObject), 'url':newObject.absolute_url(), 'op':self.copyDict['op'], 'id':baseId}) except ConflictError: raise except ValueError: msg=PLMF(u'Disallowed to paste item(s).') except (Unauthorized, 'Unauthorized'): msg=PLMF(u'Unauthorized to paste item(s).') except CopyError: # fallback msg=PLMF(u'Paste could not find clipboard content.') return json.dumps({'status':'failure', 'message':self.context.translate(msg)})
def __call__(self): eventid = 'UID_' + get_uid(self.context) parent = self.context.aq_inner.aq_parent title = safe_unicode(self.context.title_or_id()) try: lock_info = self.context.restrictedTraverse('@@plone_lock_info') except AttributeError: lock_info = None if lock_info is not None and lock_info.is_locked(): status = 'locked' message = PLMF(u'${title} is locked and cannot be deleted.', mapping={u'title' : title}) else: parent.manage_delObjects(self.context.getId()) status = 'ok' message = PLMF(u'${title} has been deleted.', mapping={u'title' : title}) transaction_note('Deleted %s' % self.context.absolute_url()) self.request.response.setHeader("Content-type","application/json") return json.dumps({'status':status, 'message':parent.translate(message), 'id':eventid})