コード例 #1
0
    def save_instance(self, instance, using_transactions=True, dry_run=False):
        try:
            ex_article = Article.objects.get(
                current_revision__title='Locus--Locus')
        except AttributeError:
            raise Exception(
                "Xposition Import: Please create Construal 'Locus--Locus' to use as a model!"
            )

        m = instance

        if not m.role and not m.function and ms.Construal.objects.filter(
                special=m.special):
            return
        if m.role and m.function and ms.Construal.objects.filter(
                role__pk=m.role.pk, function__pk=m.function.pk):
            return

        role_name = deepest_instance(
            m.role.current_revision).name if m.role else None
        function_name = deepest_instance(
            m.function.current_revision).name if m.function else None
        name = self.get_construal_slug(role_name, function_name, m.special)
        # slug will be the same as name
        newarticle = ArticleMetadataFormFunctions(
            ADMIN_REQUEST).newArticle_without_category(name=name,
                                                       slug=name,
                                                       ex_article=ex_article,
                                                       parent=None)
        m.article = newarticle
        m.save()
コード例 #2
0
def metadata_display(context):
    if 'article' not in context:
        return ''

    article = context['article']
    c = article.current_revision
    if hasattr(c, 'metadata_revision'):
        meta = deepest_instance(c.metadata_revision)
    else:
        articleplugins = [
            deepest_instance(z) for z in article.articleplugin_set.all()
        ]
        meta = [
            z for z in articleplugins if isinstance(z, SimpleMetadata)
        ]  # not Metadata, because that will have an article_revision pointer and be handled above
        assert 0 <= len(meta) <= 1
        if meta:
            meta = meta[0]
        else:
            return

    #meta = deepest_instance(metadata)
    #if hasattr(meta, 'current_revision'):
    #    meta = deepest_instance(meta.current_revision)
    generic_flds = MetadataRevision._meta.get_fields(
    ) + SimpleMetadata._meta.get_fields()
    display = '<h4 id="metadata">Metadata'
    if hasattr(meta, 'editurl'):
        editurl = meta.editurl(context['urlpath'])
        display += ' <a href="' + editurl + '" style="float: right;"><i class="fa fa-edit" alt="edit metadata"></i></a>'
    display += '</h4>\n<table class="metadata">\n'
    for fld in meta._meta.get_fields(include_hidden=False):
        if fld.name == 'description' or fld not in generic_flds and not fld.name.endswith(
                '_ptr'):
            display += f'    <tr><th style="padding: 10px;">{fld.name}</th><td>'
            v = getattr(meta, fld.name)
            if hasattr(v, 'html'):
                display += v.html() if callable(v.html) else v.html
            elif hasattr(fld, 'choices') and fld.choices:
                choices = dict(fld.choices)
                if v is not None:  # if None, display nothing
                    v = str(choices[int(v)])
                    display += str(v)
            elif isinstance(fld, BitField):
                display += ', '.join(case for case, allowed in v if allowed)
            elif isinstance(fld, URLField):
                display += format_html('<a href="{}">{}</a>', v, v)
            elif fld.name == 'description' and hasattr(meta,
                                                       'descriptionhtml'):
                display += meta.descriptionhtml()
            else:
                display += str(v)
            display += '</td></tr>\n'
    display += '</table>'
    display += '<!--' + str(meta) + '-->'
    return mark_safe(display)
コード例 #3
0
ファイル: metadata_tags.py プロジェクト: ablodge/Xposition
def langs_display(context):
    """Display a list of languages recorded in the database."""
    if 'article' not in context:
        return ''

    article = context['article']
    s = ''
    for lang in Language.with_nav_links().order_by('name'):
        langart = lang.article
        s += '<li'
        if context['article']==langart \
            or (hasattr(article, 'metadata') and getattr(context['article'].metadata, 'language', None)==lang) \
            or (hasattr(article.current_revision, 'metadata_revision') and getattr(deepest_instance(context['article'].current_revision.metadata_revision), 'lang', None)==lang):
            s += ' class="active"'
        s += '><a href="' + langart.get_absolute_url(
        ) + '">' + lang.name + '</a></li>"'
    return mark_safe(s)
コード例 #4
0
            return


        adp_article = m.adposition.article
        # code taken from wiki/plugins/metadata/forms.py
        if len([key for key,set in m.adposition
                                    .current_revision
                                    .metadatarevision
                                    .adpositionrevision
                                    .obj_cases.iteritems() if set])<2:
            case = None
        else:
            case = ms.Case.shortname(m.obj_case)
        caseSlug = '<'+case+'>' if case else ''
        construalSlug = m.construal.article.urlpath_set.all()[0].slug
        name = self.get_usage_name(deepest_instance(m.adposition.current_revision).name,
                                   str(m.construal),
                                   case)
        newarticle = ArticleMetadataFormFunctions(ADMIN_REQUEST).newArticle_without_category(ex_article=self.ex_article,
                                                                                                         parent=adp_article.urlpath_set.all()[0],
                                                                                                         name=name,
                                                                                                         slug=caseSlug + construalSlug)
        # associate the article with the UsageRevision
        m.article = newarticle
        m.name = name

        # create the Usage, add the article, category, and revision
        u = ms.Usage()
        u.article = newarticle
        u.add_revision(m, ADMIN_REQUEST, article_revision=newarticle.current_revision, save=True) # cannot delay saving the new adposition revision
コード例 #5
0
            return

        adp_article = m.adposition.article
        # code taken from wiki/plugins/metadata/forms.py
        if len([
                key
                for key, set in m.adposition.current_revision.metadatarevision.
                adpositionrevision.obj_cases.iteritems() if set
        ]) < 2:
            case = None
        else:
            case = ms.Case.shortname(m.obj_case)
        caseSlug = '<' + case + '>' if case else ''
        construalSlug = m.construal.article.urlpath_set.all()[0].slug
        name = self.get_usage_name(
            deepest_instance(m.adposition.current_revision).name,
            str(m.construal), case)
        newarticle = ArticleMetadataFormFunctions(
            ADMIN_REQUEST).newArticle_without_category(
                ex_article=self.ex_article,
                parent=adp_article.urlpath_set.all()[0],
                name=name,
                slug=caseSlug + construalSlug)
        # associate the article with the UsageRevision
        m.article = newarticle
        m.name = name

        # create the Usage, add the article, category, and revision
        u = ms.Usage()
        u.article = newarticle
        u.add_revision(