Query aleph for records with given `issn`. The lookup is directed to the
    NTK's Aleph.

    Args:
        issn (str): ISSN of the periodical.

    Returns:
        obj: :class:`Model` instances for each record.
979283
def by_issn(issn):
    
    # monkeypatched to allow search in NTK's Aleph
    old_url = aleph.ALEPH_URL
    aleph.ALEPH_URL = NTK_ALEPH_URL
    records = aleph.getISSNsXML(issn, base="STK02")
    aleph.ALEPH_URL = old_url

    # process all records
    for record in records:
        marc = MARCXMLRecord(record)

        # following values were requested by @bjackova in
        # https://github.com/WebArchivCZ/WA-KAT/issues/66
        additional_info = {
            "222": marc.get("222", None),
            "PER": marc.get("PER", None),
            "776": marc.get("776", None),
            "008": marc.get("008", None),
            "alt_end_date": ""  # just reminder that it is filled later
        }
        additional_info = {
            key: val
            for key, val in additional_info.iteritems()
            if val
        }

        # check whether there is alternative date in 008
        alt_end_date = None
        alt_creation_date = None
        if additional_info["008"]:
            # 131114c20139999xr-q||p|s||||||---a0eng-c -> 2013
            alt_creation_date = additional_info["008"][7:11]

            # 131114c20139999xr-q||p|s||||||---a0eng-c -> 9999
            alt_end_date = additional_info["008"][11:15]
            if alt_end_date in ["9999", "****"]:
                alt_creation_date += "-"  # library convention is xxxx-
                alt_end_date = None

            additional_info["alt_end_date"] = alt_end_date

        # parse author
        author = Author.parse_author(marc)

        model = Model(
            url=_first_or_none(
                marc.get("856u")
            ),
            conspect=_first_or_none(
                marc.get("072a")
            ),
            annotation_tags=_first_or_none(
                marc.get("520a")
            ),
            periodicity=_first_or_none(
                marc.get("310a")
            ),
            title_tags=_first_or_none(
                marc.get("222a")
            ),
            subtitle_tags=_first_or_none(
                marc.get("245b")
            ),
            place_tags=remove_hairs(
                _first_or_none(marc.get("260a")) or ""
            ),
            author_tags=author._asdict() if author else None,
            publisher_tags=remove_hairs(
                (
                    _first_or_none(marc.get("260b")) or
                    _first_or_none(marc.get("264b")) or
                    "",
                ),
                ", "
            ),
            creation_dates=_first_or_none(
                marc.get("260c", [alt_creation_date])
            ),
            lang_tags=_first_or_none(
                marc.get("040b")
            ),
            keyword_tags=marc.get("650a07"),
            source_info=_first_or_none(
                marc.get("500a")
            ),
            original_xml=record,
            additional_info=additional_info,
        )

        yield _add_source(model)
436054
def related_records_78708(self, key, value):
    """"""
    record = get_record_ref(maybe_int(value.get('w')), 'literature')
    if record:
        return {
            'curated_relation': record is not None,
            'record': record,
            'relation_freetext': value.get('i'),
        }
36925
def journal_history(self):
        
        jour = namedtuple('Journal', 'sourcetitle abbreviation type issn')
        path = ['author-profile', 'journal-history', 'journal']
        hist = [jour(sourcetitle=pub['sourcetitle'], issn=pub.get('issn'),
                     abbreviation=pub.get('sourcetitle-abbrev'),
                     type=pub['@type'])
                for pub in listify(chained_get(self._json, path, []))]
        return hist or None
709999
def get_pmids(self, entry):
        
        pmids = []

        for citation in entry.iterfind("./reference/citation"):

            for pubmed_ref in citation.iterfind('dbReference[@type="PubMed"]'):

                pmid_number = pubmed_ref.get('id')

                if pmid_number in self.pmids:

                    pmid_sqlalchemy_obj = self.session.query(models.Pmid)\
                        .filter(models.Pmid.pmid == pmid_number).one()

                    pmids.append(pmid_sqlalchemy_obj)

                else:
                    pmid_dict = citation.attrib
                    if not re.search('^\d+$', pmid_dict['volume']):
                        pmid_dict['volume'] = -1

                    del pmid_dict['type'] # not needed because already filtered for PubMed

                    pmid_dict.update(pmid=pmid_number)
                    title_tag = citation.find('./title')

                    if title_tag is not None:
                        pmid_dict.update(title=title_tag.text)

                    pmid_sqlalchemy_obj = models.Pmid(**pmid_dict)
                    self.session.add(pmid_sqlalchemy_obj)
                    self.session.flush()

                    pmids.append(pmid_sqlalchemy_obj)

                    self.pmids |= set([pmid_number, ]) # extend the cache of identifiers

        return pmids
770749
def _get_record(self, record_type):
        
        if (not self.has_record_type(record_type) and
                record_type.get_identifier() not in self._record_type_data_sets):
            raise errors.Unsupported()
        if str(record_type) not in self._records:
            record_initialized = self._init_record(str(record_type))
            if record_initialized and str(record_type) not in self._my_map['recordTypeIds']:
                self._my_map['recordTypeIds'].append(str(record_type))
        return self._records[str(record_type)]
38550
def works(self, issn):
        

        context = '%s/%s' % (self.ENDPOINT, str(issn))
        return Works(context=context)
818682
def _joinOnAsPriv(self, model, onIndex, whatAs):
        
        if self._join:
            raise Exception("Already joined with a table!")

        self._join = model
        self._joinedField = whatAs
        table = model.table
        self._query = self._query.eq_join(onIndex, r.table(table))
        return self
3371
def find(self, symbol, chrom=None, create=False):
        
        queryset = self.get_query_set()

        # Filter by chromosome if one is specified
        if chrom:
            queryset = queryset.filter(chr=chrom)

        # Look for direct match
        matches = queryset.filter(symbol__iexact=symbol)

        try:
            return matches[0]
        except IndexError:
            pass

        # Attempt to disambiguate, only if this is the only synonym may it be
        # associated
        potential = list(
            queryset.filter(synonyms__label__iexact=symbol).distinct())

        if len(potential) == 1:
            return potential[0]

        # Only if there are no matches should we create a new record,
        # otherwise the synonym war will continue
        if create and len(potential) == 0:
            instance = self.model(chr=chrom, symbol=symbol)
            try:
                instance.save()
            except IntegrityError:
                instance = queryset.get(chr=chrom, symbol=symbol)
            return instance
1098505
def get_record(self, name):
        

        result = {}
        result.update(self.records.get(name, {}))
        return result
477743
def get_indexable(cls):
        
        model = cls.get_model()
        return model.objects.order_by('id').values_list('id', flat=True)
627768
def get_queryset(self):
        
        return self.model.published.annotate(
            count_entries_published=Count('entries')).annotate(
            last_update=Max('entries__last_update')).order_by(
            '-count_entries_published', '-last_update', '-pk')
447248
def transcribe(records, transcribe):
    
    logging.info('Applying _transcribe generator: '
                 'operation to perform is ' + transcribe + '.')
    for record in records:
        sequence = str(record.seq)
        description = record.description
        name = record.id
        if transcribe == 'dna2rna':
            dna = Seq(sequence, IUPAC.ambiguous_dna)
            rna = dna.transcribe()
            yield SeqRecord(rna, id=name, description=description)
        elif transcribe == 'rna2dna':
            rna = Seq(sequence, IUPAC.ambiguous_rna)
            dna = rna.back_transcribe()
            yield SeqRecord(dna, id=name, description=description)
559314
def list(self,table, **kparams):
        
        result = self.table_api_get(table, **kparams)
        return self.to_records(result, table)
948853
def get_sequence(cls, entry):
        
        seq_tag = entry.find("./sequence")
        seq = seq_tag.text
        seq_tag.clear()
        return models.Sequence(sequence=seq)
554173
def IdentifiersIndexer(instance):
    
    identifiers = instance.Schema()['Identifiers'].get(instance)
    return [safe_unicode(i['Identifier']) for i in identifiers]
133685
def search(**kw):
    
    portal = get_portal()
    catalog = ICatalog(portal)
    catalog_query = ICatalogQuery(catalog)
    query = catalog_query.make_query(**kw)
    return catalog(query)
1373756
def default_record_to_index(record):
    
    index_names = current_search.mappings.keys()
    schema = record.get('$schema', '')
    if isinstance(schema, dict):
        schema = schema.get('$ref', '')

    index, doc_type = schema_to_index(schema, index_names=index_names)

    if index and doc_type:
        return index, doc_type
    else:
        return (current_app.config['INDEXER_DEFAULT_INDEX'],
                current_app.config['INDEXER_DEFAULT_DOC_TYPE'])