Enrich the dict glossary['link'] with an identifier onto the model
967088
def _enrich_link(self, glossary):
        
        try:
            Model = apps.get_model(*glossary['link']['model'].split('.'))
            obj = Model.objects.get(pk=glossary['link']['pk'])
            glossary['link'].update(identifier=str(obj))
        except (KeyError, ObjectDoesNotExist):
            pass
1043388
def generate(self):
        
        t = (self.context.identifier, RDF.type, META.Provenance)
        if t not in self.context.graph:
            self.context.graph.add(t)
        for name, value in self.data.items():
            pat = (self.context.identifier, META[name], None)
            if pat in self.context.graph:
                self.context.graph.remove(pat)
            self.context.graph.add((pat[0], META[name], Literal(value)))
835285
def _serialize_model_helper(self, model, field_dict=None):
        
        field_dict = field_dict or self.dot_field_list_to_dict()
        if model is None:
            return None

        if isinstance(model, Query):
            model = model.all()

        if isinstance(model, (list, set)):
            return [self.serialize_model(m, field_dict=field_dict) for m in model]

        model_dict = {}
        for name, sub in six.iteritems(field_dict):
            value = getattr(model, name)
            if sub:
                value = self.serialize_model(value, field_dict=sub)
            model_dict[name] = value
        return model_dict
300728
def resource_for_link(link, includes, resources=None, locale=None):
    """"""

    if resources is not None:
        cache_key = "{0}:{1}:{2}".format(
            link['sys']['linkType'],
            link['sys']['id'],
            locale
        )
        if cache_key in resources:
            return resources[cache_key]

    for i in includes:
        if (i['sys']['id'] == link['sys']['id'] and
                i['sys']['type'] == link['sys']['linkType']):
            return i
    return None
109424
def param_keywords(self):
        
        return dict((key, self[key]) for key in self if key not in self.extra_keywords())
335227
def _to_dict(self):
        """"""
        _dict = {}
        if hasattr(self, 'link') and self.link is not None:
            _dict['link'] = self.link
        return _dict
252586
def _build_dictionary(self, models):
        
        for model in models:
            key = getattr(model, self._morph_type, None)
            if key:
                foreign = getattr(model, self._foreign_key)
                if key not in self._dictionary:
                    self._dictionary[key] = {}

                if foreign not in self._dictionary[key]:
                    self._dictionary[key][foreign] = []

                self._dictionary[key][foreign].append(model)
384125
def link(self):
        """"""

        type_specs = {}
        types = []

        for name, type_spec in self.scope.type_specs.items():
            type_spec = type_spec.link(self.scope)
            type_specs[name] = type_spec

            if type_spec.surface is not None:
                self.scope.add_surface(name, type_spec.surface)
                types.append(type_spec.surface)

        self.scope.type_specs = type_specs
        self.scope.add_surface('__types__', tuple(types))
1372497
def linkify(self):
        
        for t_id in self.items:
            timeperiod = self.items[t_id]
            timeperiod.linkify(self)
667470
def urlencode(params):
    """"""

    # Not doing duck typing here. Will make debugging easier.
    if not isinstance(params, dict):
        raise TypeError("Only dicts are supported.")

    params = flatten(params)

    url_params = OrderedDict()
    for param in params:
        value = param.pop()

        name = parametrize(param)
        if isinstance(value, (list, tuple)):
            name += "[]"

        url_params[name] = value

    return urllib_urlencode(url_params, doseq=True)
1129668
def decode_link(self, link):
        

        if link.HasField("bucket"):
            bucket = bytes_to_str(link.bucket)
        else:
            bucket = None
        if link.HasField("key"):
            key = bytes_to_str(link.key)
        else:
            key = None
        if link.HasField("tag"):
            tag = bytes_to_str(link.tag)
        else:
            tag = None

        return (bucket, key, tag)
217102
def new_link(model_class, html_options: {}, &block)
      return if unauthorized? :new, model_class
      html_options, block = LinkOptionsNormalizer.normalize(
        html_options, block,
        class: 'resource__create',
        block: -> { t 'links.new', model: to_model_label(model_class) }
      )

      link_to new_path(model_class), html_options, &block
    end
619517
def ident_dict(self):
        """"""

        SKIP_KEYS = ['name','vname','fqname','vid','cache_key']
        return {k: v for k, v in iteritems(self.dict) if k not in SKIP_KEYS}
446121
def link_to(self, model, idx, self_idx):
        
        if model in self.system.loaded_groups:

            # access group instance
            grp = self.system.__dict__[model]

            # doing it one by one
            for i, self_i in zip(idx, self_idx):
                # query model name and access model instance
                mdl_name = grp._idx_model[i]
                mdl = self.system.__dict__[mdl_name]

                # query the corresponding uid
                u = mdl.get_uid(i)

                # update `mdl_from`
                name_idx_pair = (self._name, self_i)
                if name_idx_pair not in mdl.mdl_from[u]:
                    mdl.mdl_from[u].append(name_idx_pair)

        else:
            # access model instance
            mdl = self.system.__dict__[model]
            uid = mdl.get_uid(idx)

            for u, self_i in zip(uid, self_idx):
                name_idx_pair = (self._name, self_i)

                if name_idx_pair not in mdl.mdl_from[u]:
                    mdl.mdl_from[u].append(name_idx_pair)
871477
def asDictionary(self):
        
        template = {"type" : self._type,
                    "mapLayerId" : self._mapLayerId}
        if not self._gdbVersion is None and\
           self._gdbVersion != "":
            template['gdbVersion'] = self._gdbVersion
        return template
120785
def build_additional_match(self, ident, node_set):
        
        source_ident = ident

        for key, value in node_set.must_match.items():
            if isinstance(value, dict):
                label = ':' + value['node_class'].__label__
                stmt = _rel_helper(lhs=source_ident, rhs=label, ident='', **value)
                self._ast['where'].append(stmt)
            else:
                raise ValueError("Expecting dict got: " + repr(value))

        for key, val in node_set.dont_match.items():
            if isinstance(val, dict):
                label = ':' + val['node_class'].__label__
                stmt = _rel_helper(lhs=source_ident, rhs=label, ident='', **val)
                self._ast['where'].append('NOT ' + stmt)
            else:
                raise ValueError("Expecting dict got: " + repr(val))
96021
def derive_link_fields(self, context):
        
        if self.link_fields is not None:
            return self.link_fields

        else:
            link_fields = set()
            if self.fields:
                for field in self.fields:
                    if field != 'is_active':
                        link_fields.add(field)
                        break

        return link_fields