def extract(self): """ Extracts the data from the HTML form and returns it :returns: A dictionary with the information """ values = self.request.get(self.name).splitlines() uuids = [i for i in values if i] results = dict() for index, uuid in enumerate(uuids): obj = uuidToObject(uuid) results[uuid] = { u'order': unicode(index) } custom_title = self.request.get( '{0}.custom_title.{1}'.format(self.name, uuid), '' ) if (custom_title != u'' and custom_title != obj.Title().decode('utf-8')): results[uuid][u'custom_title'] = unicode(custom_title) custom_description = self.request.get( '{0}.custom_description.{1}'.format(self.name, uuid), '' ) if (custom_description != u'' and custom_description != obj.Description().decode('utf-8')): results[uuid][u'custom_description'] = unicode(custom_description) custom_url = self.request.get( '{0}.custom_url.{1}'.format(self.name, uuid), '' ) url = obj.absolute_url() if obj.portal_type in get_types_use_view_action_in_listings(): url += '/view' if (custom_url != u'' and custom_url != url): results[uuid][u'custom_url'] = unicode(custom_url) return results
def extract(self): """ Extracts the data from the HTML form and returns it :returns: A dictionary with the information """ values = self.request.get(self.name).splitlines() uuids = [i for i in values if i] results = dict() for index, uuid in enumerate(uuids): obj = uuidToObject(uuid) results[uuid] = {u'order': six.text_type(index)} custom_title = self.request.get( '{0}.custom_title.{1}'.format(self.name, uuid), '') if (custom_title != u'' and custom_title != safe_unicode(obj.Title())): results[uuid][u'custom_title'] = six.text_type(custom_title) custom_description = self.request.get( '{0}.custom_description.{1}'.format(self.name, uuid), '') if (custom_description != u'' and custom_description != safe_unicode(obj.Description())): results[uuid][u'custom_description'] = six.text_type( custom_description) custom_url = self.request.get( '{0}.custom_url.{1}'.format(self.name, uuid), '') url = obj.absolute_url() if obj.portal_type in get_types_use_view_action_in_listings(): url += '/view' if (custom_url != u'' and custom_url != url): results[uuid][u'custom_url'] = six.text_type(custom_url) return results
def get_url(self, item): """Get the URL of the item, or the custom URL if set. :param item: [required] The item for which we want the URL :type item: Content object :returns: the item URL :rtype: str """ # First we get the url for the item itself url = item.absolute_url() if item.portal_type in get_types_use_view_action_in_listings(): url += '/view' uuid = self.get_uuid(item) data_mgr = ITileDataManager(self) data = data_mgr.get() uuids = data['uuids'] if uuid in uuids: if uuids[uuid].get('custom_url', u''): # If we had a custom url set, then get that url = uuids[uuid].get('custom_url') return url
def get_custom_url(self, uuid): """ Returns the custom URL assigned to a specific item :param uuid: [required] The object's UUID :type uuid: string :returns: The custom URL """ # Try to get custom url url = u'' uuids = self.context['uuids'] values = [uuids[i] for i in uuids if i == uuid] if values: url = values[0].get('custom_url', u'') if url: return url # If didn't find, get object url obj = uuidToObject(uuid) url = obj.absolute_url() if obj.portal_type in get_types_use_view_action_in_listings(): url += '/view' return url
def populate_with_object(self, obj): """Tile can be populated with any content type with image or getImage attribute; in this case we're not going to take care of any modification of the original object; we just copy the data to the tile and deal with it. """ if obj.portal_type not in self.accepted_ct(): return super(BannerTile, self).populate_with_object(obj) # check permissions if obj.portal_type == 'Link': try: remote_url = obj.getRemoteUrl() # Archetypes except AttributeError: remote_url = obj.remoteUrl # Dexterity else: remote_url = obj.absolute_url() if obj.portal_type in get_types_use_view_action_in_listings(): remote_url += '/view' image = self.get_image_data(obj) if image: # clear scales if new image is getting saved self.clear_scales() obj = aq_base(obj) # avoid acquisition title = safe_unicode(obj.Title()) description = safe_unicode(obj.Description()) data_mgr = ITileDataManager(self) data_mgr.set({ 'title': title, 'description': description, 'uuid': IUUID(obj), 'image': image, # FIXME: https://github.com/collective/collective.cover/issues/778 'alt_text': description or title, 'remote_url': remote_url, })