Пример #1
0
    def __init__(self, request, user, instance):
        newRequest = request.copy()

        # For now, default to the previous values of user, slug & cost
        newRequest.setdefault('user', instance.user.id)
        newRequest.setdefault('cost', instance.cost)
        newRequest.setdefault('slug', instance.slug)

        # Create and save new Document.
        new_document = Document()
        new_document.save()

        new_resource_revision = ResourceRevision()
        new_resource_revision.content = new_document
        new_resource_revision.resource = instance
        new_resource_revision.user = user
        new_resource_revision.save()

        newRequest.setdefault('revision', new_resource_revision.id);

        from meta.models import TagCategory
        tag_category = TagCategory.objects.get(title='Document')
        newRequest.setlist('tags', FormUtilities.get_taglist(
            newRequest.getlist('tags'), tag_category))

        super(DocumentEditForm, self).__init__(newRequest, instance=instance)
Пример #2
0
        cost=old.cost,
        views=old.views,
        image=old.image,
        source=old.source,
        slug=slugify(old.title),
        id=old.id
    )

    # Add collaborators.
    for person in old.collaborators.all():
        new_resource.collaborators.add(person)

    try:
        # Based on its type, create appropriate content.
        if old.type == "article":
            content = Document()
            content.save()

            element = Element(body=json.loads('{"type": "textblock", "data": "' + old.body_markdown_html + '"}'))
            element.save()

            document_element = DocumentElement(
                document=content,
                element=element,
                position=1
            )
            document_element.save()

        elif old.type == "url":
            content = Link(url=old.url)
            content.save()