Beispiel #1
0
def edit_resource(request, group, resource_name,  
                  template_name='plus_resources/upload.html', success_url=None, current_app="plus_groups", **kwargs) :

    try:
        secure_upload = Resource.objects.plus_get(request.user, name=resource_name, in_agent=group.get_ref())
    except Resource.DoesNotExist:
        raise Http404
 
    if not success_url :
        success_url = reverse(current_app + ':group',args=(group.id,))

    if request.POST :
        form = UploadFileForm(request.POST, request.FILES)
        if form.is_valid() :
            handle_uploaded_file(request.user, group, form, request.FILES['resource'])
            return HttpResponseRedirect(success_url)
        else :
            print form.errors


    else :
        form = UploadFileForm()
        form.data['title'] = secure_upload.title
        form.data['name'] = secure_upload.name
    
    return render_to_response(template_name, {
        'form' : form,
        'page_title' : 'Upload a resource',
    }, context_instance=RequestContext(request, current_app=current_app))
Beispiel #2
0
def edit_resource(request,
                  group,
                  resource_name,
                  template_name='plus_resources/upload.html',
                  success_url=None,
                  current_app="plus_groups",
                  **kwargs):

    if not group:
        raise Http404(_('This group does not exist'))

    try:
        secure_upload = Resource.objects.plus_get(request.user,
                                                  name=resource_name,
                                                  in_agent=group.get_ref())
    except Resource.DoesNotExist:
        raise Http404

    if secure_upload.name:
        old_name = secure_upload.name
    else:
        old_name = ''

    try:
        secure_upload.get_all_sliders
        perms_bool = True
    except PlusPermissionsNoAccessException:
        perms_bool = False

    if request.POST:
        post_kwargs = request.POST.copy()
        post_kwargs['obj'] = secure_upload

        if "delete_submit" in post_kwargs:
            if post_kwargs.has_key('delete_check'):
                secure_upload.delete()
                return HttpResponseRedirect(
                    reverse(current_app + ':group', args=[group.id]))

        if "move_resource_submit" in post_kwargs:
            form = MoveResourceForm(post_kwargs)
            form.user = request.user  # essential, user is checked inside form validation
            if form.is_valid():
                new_parent_group = form.cleaned_data['new_parent_group']
                try:
                    secure_upload.move_to_new_group(new_parent_group)
                except Exception, e:
                    print e

                return HttpResponseRedirect(
                    reverse(current_app + ':group',
                            args=[form.cleaned_data['new_parent_group'].id]))

        form = UploadFileForm(post_kwargs, request.FILES, user=request.user)

        if form.is_valid():
            a_file = form.cleaned_data['resource']

            resource = update_attributes(
                secure_upload,
                request.user,
                title=form.cleaned_data['title'],
                name=form.cleaned_data['name'],
                license=form.cleaned_data['license'],
                author=form.cleaned_data['author'],
                description=form.cleaned_data['description'],
                resource=a_file)

            resource.stub = False
            resource.in_agent = group.get_ref()

            # don't allow name to change as this affects the url
            if old_name:
                resource.name = old_name
            resource.save()

            if not success_url:
                success_url = reverse(current_app + ':view_Resource',
                                      args=(group.id, resource.name))

            from apps.plus_feed.models import FeedItem
            FeedItem.post_UPLOAD(request.user, resource)

            return HttpResponseRedirect(success_url)

        else:
            pass
Beispiel #3
0
            resource.save()

            if not success_url:
                success_url = reverse(current_app + ':view_Resource',
                                      args=(group.id, resource.name))

            from apps.plus_feed.models import FeedItem
            FeedItem.post_UPLOAD(request.user, resource)

            return HttpResponseRedirect(success_url)

        else:
            pass

    else:
        form = UploadFileForm()
        form.data['title'] = secure_upload.title
        form.data['name'] = secure_upload.name

    tags = get_tags_for_object(secure_upload, request.user)

    return render_to_response(
        template_name,
        {
            'upload': TemplateSecureWrapper(secure_upload),
            'resource': TemplateSecureWrapper(
                secure_upload
            ),  # let's us use resource_common included template
            'data': form.data,
            'errors': form.errors,
            'form_action': '',
Beispiel #4
0
                resource.name = old_name
            resource.save()
            
            if not success_url :
                success_url = reverse(current_app + ':view_Resource', args=(group.id, resource.name))
           
            from apps.plus_feed.models import FeedItem
            FeedItem.post_UPLOAD(request.user, resource)

            return HttpResponseRedirect(success_url)
                 
        else:
            pass

    else :
        form = UploadFileForm()
        form.data['title'] = secure_upload.title
        form.data['name'] = secure_upload.name
    
    tags = get_tags_for_object(secure_upload, request.user)

    return render_to_response(template_name, {
        'upload': TemplateSecureWrapper(secure_upload),
        'resource':TemplateSecureWrapper(secure_upload), # let's us use resource_common included template
        'data' : form.data,
        'errors': form.errors,
        'form_action':'',
        'form_encoding':'enctype=multipart/form-data',
        'permissions':perms_bool,
        'tags':tags,
        'pages':[p.get_ref() for p in group.get_resources_of_class(WikiPage)],