def index(self): from ckanext.dgu.model.commitment import Commitment, ODS_ORGS c.publishers = model.Session.query(model.Group)\ .filter(model.Group.state=='active')\ .filter(model.Group.name.in_(ODS_ORGS.values()))\ .order_by(model.Group.title).all() c.commitments = model.Session.query(Commitment).filter(Commitment.state=='active').all() return render('commitment/index.html')
def index(self): from ckanext.dgu.model.commitment import Commitment, ODS_ORGS c.publishers = model.Session.query(model.Group)\ .filter(model.Group.state=='active')\ .filter(model.Group.name.in_(ODS_ORGS.values()))\ .order_by(model.Group.title).all() c.commitments = model.Session.query(Commitment).filter( Commitment.state == 'active').all() return render('commitment/index.html')
def process_row(row): """ Reads each row and tries to create a new commitment database entry after trying to determine if a matching one already exists. """ import ckan.model as model from ckanext.dgu.model.commitment import Commitment from ckanext.dgu.model.commitment import ODS_ORGS, ODS_LINKS short_org = row[0].strip() org_name = ODS_ORGS.get(short_org, None) if not org_name: raise ingest.IngestException("Failed to lookup group {0}".format(short_org), True) org = model.Group.get(org_name) if not org: raise ingest.IngestException("Failed to find group {0}".format(org_name), True) dataset = None # Handle multiple values in the URL field parts = row[6].strip().split() if parts: dataset_name = self._url_to_dataset_name(parts[0]) dataset = model.Session.query(model.Package)\ .filter(model.Package.name==dataset_name)\ .filter(model.Package.state=='active').first() if not dataset: if parts and parts[0].startswith('http'): dataset = parts[0] else: dataset = "" source = row[1] name = row[2] text = row[3] notes = row[4] or '' published = row[5] # Delete a record that matches based on source and name c = model.Session.query(Commitment)\ .filter(Commitment.source==source)\ .filter(Commitment.dataset_name==name)\ .filter(Commitment.commitment_text==text)\ .filter(Commitment.publisher==org.name).first() if not c: c = Commitment() log.info("Creating new commitment") else: log.info("Updating existing commitment") c.source = source c.commitment_text = text c.notes = notes c.publisher = org.name c.author = '' c.dataset_name = name if dataset and hasattr(dataset, 'name'): c.dataset = dataset.name else: c.dataset = dataset c.state = 'active' model.Session.add(c) model.Session.commit()