Exemple #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 Link, if the link URL changed.
        url_submitted = sanitize_url(newRequest.get('url', None))
        if instance.revision.content.url == url_submitted:
            new_video_link = Link(url=url_submitted)
            new_video_link.save()
            content = new_video_link
        else:
            content = instance.revision.content

        new_resource_revision = ResourceRevision()
        new_resource_revision.content = content
        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='Resources')
        newRequest.setlist('tags', FormUtilities.get_taglist(
            newRequest.getlist('tags'), tag_category))

        super(VideoEditForm, self).__init__(newRequest, instance=instance)
Exemple #2
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)
Exemple #3
0
        attachment_revision.save()

        #(attachment_name, attachment_name) = os.path.split(attachment.file.name)
        attachment_resource = Resource(
            revision=attachment_revision,
            title=filename,
            license=license,
            user=user,
            description="",
            visibility='public',
            cost=0.0,
            slug=slugify(filename)
        )
        attachment_resource.save()

        attachment_revision.resource = attachment_resource
        attachment_revision.save()

        user.get_profile().collection.resources.add(attachment_resource)

        attachments.append(attachment_resource)
        os.remove(attachment_path)

    img_web = urllib2.urlopen(value['image_url']).read()

    resource_response = urllib2.urlopen(
        'http://map.mathshell.org/materials/' + value['lessons'][0])

    content_disposition = resource_response.headers.get('Content-Disposition')
    resource_filename = content_disposition[content_disposition.index('filename') + 10:-1]
Exemple #4
0
        elif old.type == "attachment":
            content = Attachment(file=old.file)
            content.save()

        # Make a copy of the revision content.
        revision = ResourceRevision(
            content=content,
            log='',
            user=old.user
        )

        revision.save()
        new_resource.revision = revision
        new_resource.save()

        revision.resource = new_resource
        revision.save()

        # Find all collections where the original resource was a part and add this resource there.
        collections = Collection.objects.filter(resources__id=old.id)
        """
        for collection in collections:
            print "came in and removed an old reference"
            collection.resources.remove(old)
            collection.resources.add(new_resource)
        """

        if len(collections) == 0:
            default_collection = Collection.objects.get(title='ocrootu_root')
            default_collection.resources.add(new_resource)
    from django.template.defaultfilters import slugify
    resource = Resource(
        revision=revision,
        title=value['title'],
        license=license,
        user=user,
        created=value['published'],
        description="",
        visibility='public',
        cost=0.0,
        source="IllustrativeMathematics.org" + value['url'],
        slug=slugify(value['title'])
    )
    resource.save()

    tags=FormUtilities.get_taglist(
                value['standards'], tag_category)
    for tag in tags:
        resource.tags.add(tag)

    revision.resource = resource
    revision.save()

    # Add the resource to a collection.
    user.get_profile().collection.resources.add(resource)

    print resource.id

    # Generate thumbnail image if not generated by default.