Exemplo n.º 1
0
    def _POST(self, id):
        """
        Create a new entry.

        """
        entry = parse_request(self.environ, output_type='python')

        # Set id, if POSTed to specific resource.
        if id is not None:
            entry.setdefault('id', id)
            if not id == entry['id']: raise httpexceptions.HTTPConflict()
        
        # Create the entry.
        entry = self.em.create_entry(entry)

        # Generate new resource location.
        store = construct_url(self.environ, with_query_string=False, with_path_info=False)
        location = urljoin(store, entry['id'])
        app = self.format.responder(entry,
                                    content_type='application/json',
                                    headers=[('Location', location)])

        # Fake start response to return 201 status.
        def start(status, headers):
            return self.start("201 Created", headers)

        return app(self.environ, start)
Exemplo n.º 2
0
    def _PUT(self, id):
        """
        Update an existing entry.

        """
        entry = parse_request(self.environ, output_type='python')

        if id is not None:
            entry.setdefault('id', id)
            if not id == entry['id']: raise httpexceptions.HTTPConflict()

        # Update entry.
        entry = self.em.update_entry(entry)

        app = self.format.responder(entry, content_type='application/json')
        return app(self.environ, self.start)