Beispiel #1
0
    def post(self, p_id, p_key):
        if self.throttler and self.throttler.reject(self.request):
            return response.throttled(self)

        content = self.get_post_content()
        if not content and p_key:  # Looks like a delete
            if not self.paestdb.delete_paest(p_id, p_key):
                return response.bad_id_or_key(self)
            else:
                return response.paest_deleted(self)
        else:  # Not a delete, try create/update

            paest = None
            updated = False
            if p_key:
                # paest updated.
                updated = self.paestdb.update_paest(p_id, p_key, content)

            if not updated:  # Wasn't an update, or at least failed to update
                # Implement the update_or_create logic
                paest = self.paestdb.create_paest(p_id, p_key, content)
                if paest:
                    p_id = paest.pid
                    p_key = paest.key

            if paest or updated:  # Create or update succeded
                return response.paest_links(self, p_id, p_key)
            else:
                return response.paest_failed(self)
Beispiel #2
0
    def get(self, p_id, p_key):
        # p_key is not used during get requests
        # pylint: disable=W0613
        if self.throttler and self.throttler.reject(self.request):
            return response.throttled(self)

        paest = self.paestdb.get_paest(p_id)

        if paest is None:
            return response.not_found(self)
        else:
            return response.raw(self, paest.content)