Skip to content

Instantly share code, notes, and snippets.

@HarryMcCarney
Last active August 29, 2015 14:08
Show Gist options
  • Save HarryMcCarney/d0e6e5ffd2c9ee19bba9 to your computer and use it in GitHub Desktop.
Save HarryMcCarney/d0e6e5ffd2c9ee19bba9 to your computer and use it in GitHub Desktop.
from pyramid.httpexceptions import HTTPBadRequest
from scotty import DBSession
from scotty.cms.models import CmsContent
__author__ = 'Harry'
def set_content(params):
if not isinstance(params, list):
raise HTTPBadRequest("Must submit list of keys as root level.")
for p in params:
print p['key']
DBSession.query(CmsContent).filter(CmsContent.key == p['key']).delete()
#content = CmsContent(key=p.key, value=p.value)
#DBSession.add(content)
#DBSession.flush()
return
def get_content(params):
if not isinstance(params, list):
raise HTTPBadRequest("Must submit list of keys in query string.")
keys = filter(None, params.get('keys', '').split(','))
content = DBSession.query(CmsContent).filter(CmsContent.key.in_(keys)).all()
return content
#############################
from scotty.models.meta import Base
from sqlalchemy import Column, String
__author__ = 'Harry'
class CmsContent(Base):
__tablename__ = 'cms_content'
key = Column(String(512), nullable=False, primary_key=True)
value = Column(String(4000), nullable=False)
def __json__(self, request):
return {"key": self.key, "value": self.value}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment