def langdoccomplexquery(request): res = { 'dt': None, 'doctypes': DBSession.query(Doctype).order_by(Doctype.id), 'macroareas': DBSession.query(Macroarea).order_by(Macroarea.id), 'ms': {} } for name, cls, kw in [ ('languoids', LanguoidsMultiSelect, dict(url=request.route_url('glottolog.childnodes'))), ('macroareas', MultiSelect, dict(collection=res['macroareas'])), ('doctypes', MultiSelect, dict(collection=res['doctypes'])), ]: res['ms'][name] = cls(request, name, 'ms' + name, **kw) res['params'], reqparams = get_params(request.params, **res) res['refs'] = getRefs(res['params']) if res['refs']: res['dt'] = Refs(request, Source, cq=1, **reqparams) fmt = request.params.get('format') if fmt: db = bibtex.Database([ref.bibtex() for ref in res['refs']]) for name, adapter in request.registry.getAdapters([db], IRepresentation): if name == fmt: return adapter.render_to_response(db, request) return HTTPNotAcceptable() return res
def langdoccomplexquery(request): res = { 'dt': None, 'doctypes': DBSession.query(Doctype).order_by(Doctype.id), 'macroareas': DBSession.query(Macroarea).order_by(Macroarea.id), 'ms': {} } for name, cls, kw in [ ('languoids', LanguoidsMultiSelect, dict( url=request.route_url('glottolog.childnodes'))), ('macroareas', MultiSelect, dict(collection=res['macroareas'])), ('doctypes', MultiSelect, dict(collection=res['doctypes'])), ]: res['ms'][name] = cls(request, name, 'ms' + name, **kw) res['params'], reqparams = get_params(request.params, **res) res['refs'] = getRefs(res['params']) if res['refs']: res['dt'] = Refs(request, Source, cq=1, **reqparams) fmt = request.params.get('format') if fmt: db = bibtex.Database([ref.bibtex() for ref in res['refs']]) for name, adapter in request.registry.getAdapters([db], IRepresentation): if name == fmt: return adapter.render_to_response(db, request) return HTTPNotAcceptable() return res
def base_query(self, query): if self.language: query = query.join(LanguageSource)\ .join(TreeClosureTable, TreeClosureTable.child_pk == LanguageSource.language_pk)\ .filter(TreeClosureTable.parent_pk == self.language.pk) query = query.outerjoin(Refdoctype, Ref.pk == Refdoctype.ref_pk)\ .distinct() elif self.complexquery: query = getRefs(self.complexquery[0]) return query
def base_query(self, query): if self.language: query = query.join(LanguageSource)\ .join(TreeClosureTable, TreeClosureTable.child_pk == LanguageSource.language_pk)\ .filter(TreeClosureTable.parent_pk == self.language.pk)\ .distinct() elif self.complexquery: query = getRefs(self.complexquery[0]) return query
def base_query(self, query): query = query.options(joinedload(Ref.doctypes), joinedload(Ref.providers)) if self.language: subquery = DBSession.query(LanguageSource)\ .filter_by(source_pk=Ref.pk)\ .join(TreeClosureTable, TreeClosureTable.child_pk == LanguageSource.language_pk)\ .filter(TreeClosureTable.parent_pk == self.language.pk) query = query.filter(subquery.exists()) elif self.complexquery: query = getRefs(self.complexquery[0]) return query