organizations&organizationtypes

This commit is contained in:
Andreas Stephanides
2017-02-10 22:06:49 +01:00
parent 0c1b586962
commit 621e1ca1ad
19 changed files with 474 additions and 86 deletions

View File

@@ -0,0 +1,21 @@
from src.controller import BaseController
from model import Organization
from src.models import Article, Section
from src.database import db_session
class OrgController(BaseController):
__myclass__= Organization
__jsonid__ = 'organization'
def get_articles(self,id):
sid=db_session.query(Section.id).filter(Section.organization_id==id).all()
sid=map(lambda a:a[0], sid)
articles=Article.query.filter(Article.section_id.in_(sid)).all()
return articles
def get_by_key_articles(self,key):
org=self.get_by_key(key)
return self.get_articles(org.id)
def get_by_key(self,key):
return Organization.query.filter(Organization.key==key).one()
controller=OrgController()