def retrieve(self, id): member = self.__get_member(id) if id.endswith('.atom'): content = member.xml(indent=True) cherrypy.response.headers['Content-Type'] = 'application/atom+xml;type=entry' else: content = member.content member.media_type = extract_media_type(member.atom) cherrypy.response.headers['Content-Type'] = member.media_type cherrypy.response.headers['ETag'] = compute_etag_from_entry(member.atom) return content
def replace(self, id): mimetype = self.__check_content_type() length = self.__check_length() member = self.__get_member(id) if cherrypy.request.headers.get('If-Match'): try: handle_if_match(compute_etag_from_entry(member.atom), cherrypy.request.headers.elements('If-Match') or []) # We want to prevent the CherryPy Etag tool to process this header # again and break the response del cherrypy.request.headers['If-Match'] except ResourceOperationException, roe: raise cherrypy.HTTPError(roe.code, roe.msg)
def create(self, profile): mimetype = self.__check_content_type() length = self.__check_length() member = self.add_profile(profile) cherrypy.response.status = '201 Created' member_uri = member.member_uri if member_uri: member_uri = member_uri.encode('utf-8') cherrypy.response.headers['Location'] = member_uri cherrypy.response.headers['Content-Location'] = member_uri cherrypy.response.headers['Content-Type'] = u'application/atom+xml;type=entry' cherrypy.response.headers['ETag'] = compute_etag_from_entry(member.atom) return member.xml(indent=True)
def create(self): mimetype = self.__check_content_type() length = self.__check_length() slug = decode_slug(cherrypy.request.headers.get('slug', None)) member = ResourceWrapper(self.collection, media_type=mimetype) content = member.generate(mimetype, source=cherrypy.request.body, slug=slug, length=length, preserve_dates=True) member.inherit_categories_from_collection() media_content = None if not member.is_entry_mimetype(mimetype): media_content = content.read(length) # Here there is a subtle difference between the dejavu storage # and other kind of storages. # When using dejavu, you have to commit the atom and media content # in two steps so that the table integrity is kept # If you are not using dejavu as a storage you can # collapse the .attach(...) call into one single call that # will store data at once. In fact if you do use dejavu but # with two distinct databases you can also collapse both # calls into a single one. self.collection.attach(member, member_content=member.atom.xml()) self.collection.store.commit(message='Adding %s' % member.member_id) self.collection.attach(member, media_content=media_content) self.collection.store.commit(message='Adding %s' % member.media_id) # Regenerate the collection feed self.collection.feed_handler.set(self.collection.feed) cherrypy.response.status = '201 Created' member_uri = member.member_uri if member_uri: member_uri = member_uri.encode('utf-8') cherrypy.response.headers['Location'] = member_uri cherrypy.response.headers['Content-Location'] = member_uri cherrypy.response.headers['Content-Type'] = u'application/atom+xml;type=entry' cherrypy.response.headers['ETag'] = compute_etag_from_entry(member.atom) self.most_recent_member = member return member.xml(indent=True)