Exemplo n.º 1
0
    def save_snippet(self, request):
        ''' Save a new version of a content snippet. '''

        if request.snippet_keyname is not None:
            self.api.memcache.delete(
                'Snippet//' +
                hashlib.sha256(request.snippet_keyname).hexdigest())

        if request.snippet_key is not None:
            self.api.memcache.delete(
                'Snippet//' + hashlib.sha256(request.snippet_key).hexdigest())

        snippet = ContentSnippet(key=self.ext.ndb.Key('ContentSnippet',
                                                      request.snippet_keyname),
                                 content=request.inner_html)
        snippet.put()

        if snippet.key.string_id() is not None:
            self.api.memcache.set(
                'Snippet//' +
                hashlib.sha256(snippet.key.string_id()).hexdigest(),
                snippet.content)
        self.api.memcache.set(
            'Snippet//' + hashlib.sha256(snippet.key.urlsafe()).hexdigest(),
            snippet.content)

        return messages.ContentResponse(snippet_key=str(snippet.key.urlsafe()),
                                        snippet_keyname=str(
                                            snippet.key.string_id()),
                                        inner_html=request.inner_html)
Exemplo n.º 2
0
    def get_snippet(self, request):

        ''' Retrieve a named or keyed snippet. '''

        if request.snippet_keyname is not None:
            snippet = ContentSnippet.get_by_key_name(request.snippet_keyname)
        else:
            snippet = ContentSnippet.get(self.api.db.Key(request.snippet_key))

        if snippet is not None:
            return messages.ContentResponse(snippet_key=str(snippet.key()), snippet_keyname=snippet.key().name(), inner_html=snippet.content)
        else:
            raise SnippetNotFoundError('Could not resolve snippet.')
Exemplo n.º 3
0
    def get_snippet(self, request):
        ''' Retrieve a named or keyed snippet. '''

        if request.snippet_keyname is not None:
            snippet = ContentSnippet.get_by_key_name(request.snippet_keyname)
        else:
            snippet = ContentSnippet.get(self.api.db.Key(request.snippet_key))

        if snippet is not None:
            return messages.ContentResponse(
                snippet_key=str(snippet.key()),
                snippet_keyname=snippet.key().name(),
                inner_html=snippet.content)
        else:
            raise SnippetNotFoundError('Could not resolve snippet.')
Exemplo n.º 4
0
    def save_snippet(self, request):

        ''' Save a new version of a content snippet. '''

        if request.snippet_keyname is not None:
            self.api.memcache.delete('Snippet//' + hashlib.sha256(request.snippet_keyname).hexdigest())

        if request.snippet_key is not None:
            self.api.memcache.delete('Snippet//' + hashlib.sha256(request.snippet_key).hexdigest())

        snippet = ContentSnippet(key=self.ext.ndb.Key('ContentSnippet', request.snippet_keyname), content=request.inner_html)
        snippet.put()

        if snippet.key.string_id() is not None:
            self.api.memcache.set('Snippet//' + hashlib.sha256(snippet.key.string_id()).hexdigest(), snippet.content)
        self.api.memcache.set('Snippet//' + hashlib.sha256(snippet.key.urlsafe()).hexdigest(), snippet.content)

        return messages.ContentResponse(snippet_key=str(snippet.key.urlsafe()), snippet_keyname=str(snippet.key.string_id()), inner_html=request.inner_html)
Exemplo n.º 5
0
    def get(self):
        global footer_content
        global support_work_top_mow_content

        content_snippets = []

        footer_address = ContentSnippet(key_name='footer_address')
        footer_address.content = footer_content

        support_work_top_mow = ContentSnippet(key_name='support_work_top_mow')
        support_work_top_mow.content = support_work_top_mow_content

        content_snippets.append(footer_address)
        content_snippets.append(support_work_top_mow)

        for snippet in content_snippets:
            key = snippet.put()
            self.logging.info('====Put content snippet at key "%s"' % str(key))
            self.response.write('<b>Put key:</b> %s<br />' % str(key))
Exemplo n.º 6
0
    def get(self):
        global footer_content
        global support_work_top_mow_content

        content_snippets = []

        footer_address = ContentSnippet(key_name='footer_address')
        footer_address.content = footer_content

        support_work_top_mow = ContentSnippet(key_name='support_work_top_mow')
        support_work_top_mow.content = support_work_top_mow_content

        content_snippets.append(footer_address)
        content_snippets.append(support_work_top_mow)

        for snippet in content_snippets:
            key = snippet.put()
            self.logging.info('====Put content snippet at key "%s"' % str(key))
            self.response.write('<b>Put key:</b> %s<br />' % str(key))