Exemple #1
0
    def upload_complete(self, request, filename):
        """
        Create a RelatedUpload object.
        """
        super(PANDARelatedUploadBackend, self).upload_complete(request, filename)

        root, ext = os.path.splitext(filename)
        path = os.path.join(settings.MEDIA_ROOT, filename)
        size = os.path.getsize(path)

        dataset = Dataset.objects.get(slug=request.REQUEST["dataset_slug"])

        upload = RelatedUpload.objects.create(
            filename=filename,
            original_filename=self._original_filename,
            size=size,
            creator=request.user,
            dataset=dataset,
        )

        dataset.update_full_text()

        resource = RelatedUploadResource()
        bundle = resource.build_bundle(obj=upload, request=request)
        data = resource.full_dehydrate(bundle).data

        # django-ajax-upoader does not use the Tastypie serializer
        # so we must 'manually' serialize the embedded resource bundle
        resource = UserResource()
        bundle = data["creator"]
        user_data = resource.full_dehydrate(bundle).data

        data["creator"] = user_data

        return data
Exemple #2
0
    def upload_complete(self, request, filename):
        """
        Create a RelatedUpload object.
        """
        try:
            super(PANDARelatedUploadBackend, self).upload_complete(request, filename)

            root, ext = os.path.splitext(filename)
            path = os.path.join(settings.MEDIA_ROOT, filename)
            size = os.path.getsize(path)

            dataset = Dataset.objects.get(slug=request.REQUEST['dataset_slug'])

            # Because users may have authenticated via headers the request.user may
            # not be a full User instance. To be sure, we fetch one.
            creator = UserProxy.objects.get(id=request.user.id)

            upload = RelatedUpload.objects.create(
                filename=filename,
                original_filename=self._original_filename,
                size=size,
                creator=creator,
                dataset=dataset)

            dataset.update_full_text()

            resource = RelatedUploadResource()
            bundle = resource.build_bundle(obj=upload, request=request)
            data = resource.full_dehydrate(bundle).data

            # django-ajax-upoader does not use the Tastypie serializer
            # so we must 'manually' serialize the embedded resource bundle
            resource = UserResource()
            bundle = data['creator']
            user_data = resource.full_dehydrate(bundle).data

            data['creator'] = user_data
        except Exception, e:
            # This global error handler is a kludge to ensure IE8 can properly handle the responses
            return { 'error_message': e.message, 'success': False }
Exemple #3
0
    def upload_complete(self, request, filename):
        """
        Create a RelatedUpload object.
        """
        try:
            super(PANDARelatedUploadBackend,
                  self).upload_complete(request, filename)

            root, ext = os.path.splitext(filename)
            path = os.path.join(settings.MEDIA_ROOT, filename)
            size = os.path.getsize(path)

            dataset = Dataset.objects.get(slug=request.REQUEST['dataset_slug'])

            # Because users may have authenticated via headers the request.user may
            # not be a full User instance. To be sure, we fetch one.
            creator = UserProxy.objects.get(id=request.user.id)

            upload = RelatedUpload.objects.create(
                filename=filename,
                original_filename=self._original_filename,
                size=size,
                creator=creator,
                dataset=dataset)

            dataset.update_full_text()

            resource = RelatedUploadResource()
            bundle = resource.build_bundle(obj=upload, request=request)
            data = resource.full_dehydrate(bundle).data

            # django-ajax-upoader does not use the Tastypie serializer
            # so we must 'manually' serialize the embedded resource bundle
            resource = UserResource()
            bundle = data['creator']
            user_data = resource.full_dehydrate(bundle).data

            data['creator'] = user_data
        except Exception, e:
            # This global error handler is a kludge to ensure IE8 can properly handle the responses
            return {'error_message': e.message, 'success': False}
Exemple #4
0
from django.conf.urls.defaults import include, patterns, url
from tastypie.api import Api
from tastypie.utils.urls import trailing_slash

from panda.api import ActivityLogResource, CategoryResource, DatasetResource, DataUploadResource, ExportResource, NotificationResource, RelatedUploadResource, SearchSubscriptionResource, TaskResource, UserResource
from panda import views

api_1_0 = Api(api_name='1.0')
api_1_0.register(ActivityLogResource())
api_1_0.register(CategoryResource())
api_1_0.register(DatasetResource())
api_1_0.register(DataUploadResource())
api_1_0.register(ExportResource())
api_1_0.register(NotificationResource())
api_1_0.register(RelatedUploadResource())
api_1_0.register(SearchSubscriptionResource())
api_1_0.register(TaskResource())
api_1_0.register(UserResource())

urlpatterns = patterns(
    '',
    url(r'^login%s$' % trailing_slash(), views.panda_login, name="login"),
    url(r'^logout%s$' % trailing_slash(), views.panda_logout, name="logout"),
    url(r'^check_activation_key/(?P<activation_key>[\w\d]+)%s$' %
        trailing_slash(),
        views.check_activation_key,
        name="check_activation_key"),
    url(r'^activate%s$' % trailing_slash(), views.activate, name="activate"),
    url(r'^forgot_password%s$' % trailing_slash(),
        views.forgot_password,