Exemple #1
0
class RenderedLayer(AbstractPageResource):
    data_resource = ForeignKey(DataResource, 'data_resource')
    default_style = ForeignKey(Style,
                               'default_style',
                               related_name='default_for_layer')
    styles = ManyToManyField(Style, 'styles')
    parent = ForeignKey(CatalogPage,
                        'parent',
                        full=False,
                        null=True,
                        blank=True,
                        readonly=False)

    class Meta(BaseMeta):
        queryset = models.RenderedLayer.objects.all()
        resource_name = 'rendered_layer'
        detail_uri_name = "slug"

    def prepend_urls(self):
        return [
            url(r"^(?P<resource_name>%s)/(?P<slug>[\w\d_.-]+)/$" %
                self._meta.resource_name,
                self.wrap_view('dispatch_detail'),
                name="api_dispatch_detail"),
        ]
Exemple #2
0
class PolicyResource(ModelResource):
    Insurer = ForeignKey(InsurerResource, "insurer", full=True)
    customer = ForeignKey(CustomerResource, "customer", full=True)
    policy_type = CharField(attribute="policy_type__name", null=True)

    class Meta:
        queryset = Policy.objects.all().annotate()
        include_resource_uri = False
class MXAsentamientoResource(AsentamientoResource):
    municipio = ForeignKey(MunicipioResource,
                           'mx_municipio',
                           null=True,
                           full=True)
    ciudad = ForeignKey(CiudadResource, 'mx_ciudad', null=False, full=True)

    class Meta(AsentamientoResource.Meta):
        allowed_methods = ['get']
        filtering = {
            'cp': 'exact',
            'tipo_asentamiento': 'iexact',
            'municipio': ALL_WITH_RELATIONS
        }
Exemple #4
0
class UploadedDataResource(ModelResource):
    """
    API for accessing UploadedData.
    """

    user = ForeignKey(ProfileResource, 'user')
    file_size = CharField(attribute='filesize', readonly=True)
    layers = ToManyField(UploadedLayerResource, 'uploadlayer_set', full=True)
    file_url = CharField(attribute='file_url', readonly=True, null=True)

    class Meta:
        queryset = UploadedData.objects.all()
        resource_name = 'data'
        allowed_methods = ['get', 'delete']
        authorization = UserOwnsObjectAuthorization()
        authentication = SessionAuthentication()
        filtering = {'user': ALL_WITH_RELATIONS}

    def get_object_list(self, request):
        """
        Filters the list view by the current user.
        """
        queryset = super(UploadedDataResource, self).get_object_list(request)

        if not request.user.is_superuser:
            return queryset.filter(user=request.user)

        return queryset
Exemple #5
0
class TaskResource(ModelResource):
    pcap_file = Base64FileField("pcap_file", use_in=is_post)
    user = ForeignKey(UserResource, 'user', full=True)
    results = ListField(attribute='results',
                        null=True,
                        blank=True,
                        default=None)

    def obj_create(self, bundle, **kwargs):
        return super(TaskResource, self).obj_create(bundle,
                                                    user=bundle.request.user)

    def alter_list_data_to_serialize(self, request, data):
        for item in data['objects']:
            item.data['filename'] = os.path.basename(
                Task.objects.get(pk=item.data['id']).pcap_file.name)
        return data

    class Meta:
        queryset = Task.objects.all().order_by('-id')
        resource_name = 'task'
        allowed_methods = ['get', 'post']
        authentication = MultiAuthentication(BasicAuthentication(),
                                             ApiKeyAuthentication(),
                                             SessionAuthentication())
        authorization = CertegoDjangoAuthorization()
        filtering = {
            'submitted_on': ALL,
            'user': ALL,
            'status': ALL,
        }
        ordering = ['id', 'submitted_on', 'status']
Exemple #6
0
class MXMunicipioResource(MunicipioResource):
    mx_estado = ForeignKey(EstadoResource, 'mx_estado', null=True, full=True)
    # asentamientos = ToManyField(AsentamientoResource, 'municipio', full=True)

    class Meta(MunicipioResource.Meta):
        allowed_methods = ['get']
        MunicipioResource.Meta.filtering['mx_estado'] = ALL_WITH_RELATIONS
Exemple #7
0
class PostResource(ModelResource):
    user = ForeignKey(UserResource, 'user')
    comments = OneToManyField(CommentResource, 'comments', full=False)

    class Meta:
        queryset = Post.objects.all()
        resource_name = 'posts'
Exemple #8
0
class FavorisResource(ModelResource):
    customer = ForeignKey(AuthResource, 'customer', null=True, full=True)
    product = ForeignKey(ProductResource, 'product', null=True, full=True)

    class Meta:
        queryset = customer_controller.get_all_favoris()
        list_allowed_methods = ['get']
        detail_allowed_methods = ['get']
        resource_name = 'favoris'
        filtering = {
            'slug': ALL,
            'customer': ALL_WITH_RELATIONS,
            'created': ['exact', 'range', 'gt', 'gte', 'lt', 'lte'],
        }
        authorization = Authorization()

    def determine_format(self, request):
        return API_FORMAT
Exemple #9
0
class ProductResource(ModelResource):
    type_form = ForeignKey(TypeFormResource, 'type_form', full=True)
    category = ForeignKey(CategoryResource, 'category', full=True)

    class Meta:
        queryset = product_controller.get_all_products()
        list_allowed_methods = ['get']
        detail_allowed_methods = ['get']
        resource_name = 'products'
        filtering = {
            'slug': ALL,
            'created': ['exact', 'range', 'gt', 'gte', 'lt', 'lte'],
            'category': ALL_WITH_RELATIONS,
            'name': ['startswith', 'contains'],
        }
        authorization = Authorization()

    def determine_format(self, request):
        return 'application/json'
Exemple #10
0
class VirtualAliasResource(ModelResource):
    """Api resource for virtual aliases.
    """

    domain = ForeignKey(VirtualDomainResource, "domain")

    class Meta:
        queryset = VirtualAlias.objects.all()
        authentication = ApiKeyAuthentication()
        authorization = DjangoAuthorization()
class ReviewsResource(ModelResource):
    book = ForeignKey(BookResource, 'book', full=True, null=True)

    class Meta:
        allowed_methods = ['get', 'post']
        authorization = Authorization()
        queryset = Reviews.objects.all()
        resource_name = 'reviews'

    def obj_create(self, bundle, **kwargs):
        print(bundle.data)
        return super(ReviewsResource, self).obj_create(bundle, **kwargs)
Exemple #12
0
class APNSDeviceResource(ModelResource):
    user = ForeignKey(User, 'user')

    class Meta:
        queryset = APNSDevice.objects.all()
        authorization = Authorization()
        validation = TokenValidation()
        authentication = ApiKeyAuthentication()

    def hydrate(self, bundle):
        bundle.data['user'] = bundle.request.user
        return bundle
Exemple #13
0
class VirtualUserResource(ModelResource):
    """Api resource for virtual users.

    The password field is voluntarily excluded as a special resource is set for this field.
    """

    domain = ForeignKey(VirtualDomainResource, "domain")

    class Meta:
        queryset = VirtualUser.objects.all()
        authentication = ApiKeyAuthentication()
        authorization = DjangoAuthorization()
        fields = ("email", "quota", "id")
Exemple #14
0
class CustomerTestResource(MongoResource):
    """
        Used to test FK
    """
    person          =   ForeignKey(to='test_app.api.resources.PersonTestResource',
                                   attribute='person',
                                  )
    class Meta:
        object_class        =   CustomerTest
        queryset            =   CustomerTest.objects.all()
        allowed_methods     =   ['get', 'post', 'put', 'delete']
        authorization       =   Authorization()
        authentication      =   Authentication()
Exemple #15
0
class UploadedDataResource(ModelResource):
    """
    API for accessing UploadedData.
    """

    user = ForeignKey(UserResource, 'user')
    file_size = CharField(attribute='filesize', readonly=True, null=True)
    layers = ToManyField(UploadedLayerResource, 'uploadlayer_set', full=True)
    file_url = CharField(attribute='file_url', readonly=True, null=True)

    class Meta:
        queryset = UploadedData.objects.all()
        resource_name = 'data'
        allowed_methods = ['get', 'delete']
        authorization = UserOwnsObjectAuthorization()
        authentication = SessionAuthentication()
        filtering = {'user': ALL_WITH_RELATIONS}

    def get_object_list(self, request):
        """
        Filters the list view by the current user.
        """
        queryset = super(UploadedDataResource, self).get_object_list(request)

        if not request.user.is_superuser:
            return queryset.filter(user=request.user)

        return queryset

    def import_all_layers(self,
                          request,
                          api_name=None,
                          resource_name=None,
                          pk=None):
        ud = UploadedData.objects.get(id=pk)
        n_layers_imported = import_all_layers(ud, owner=request.user)
        resp = self.create_response(request,
                                    {'layer_count': n_layers_imported})
        return resp

    def prepend_urls(self):
        pu = super(UploadedDataResource, self).prepend_urls()
        pu.extend([
            url(r'^(?P<resource_name>{0})/(?P<pk>\w[\w/-]*)/import_all_layers{1}$'
                .format(self._meta.resource_name, trailing_slash()),
                self.wrap_view('import_all_layers'),
                name='import_all_data')
        ])
        return pu
Exemple #16
0
class ChatResource(ModelResource):
    user = ForeignKey(UserResource, 'user')

    class Meta:
        queryset = Chat.objects.all()
        resource_name = 'chat'
        allowed_methods = ['post']
        authorization = Authorization()

        always_return_data = True

    def dehydrate(self, bundle):
        bundle.data['follow_up'] = True
        response = detect_intent_texts(bundle.data['user'].split('/')[-2],
                                       bundle.data['message'])
        try:
            if response.query_result.HasField("diagnostic_info"):
                r_data = json.loads(MessageToJson(response.query_result))
                print(r_data)
                if r_data.get("outputContexts"):
                    param_dict = {}
                    for d in r_data['outputContexts']:
                        param_dict = {**param_dict, **d['parameters']}
                    print(d)
                    source = param_dict['geo-city-source']
                    destination = param_dict['geo-city-destination']
                    date = param_dict['date']
                else:
                    source = r_data['parameters']['geo-city-source']
                    destination = r_data['parameters']['geo-city-destination']
                    date = r_data['parameters']['date']
                bundle.data['follow_up'] = False
                bundle.data['source-city'] = source
                bundle.data['destination-city'] = destination
                bundle.data['date'] = date
                bundle.data['data'] = search_trains(source, destination, date)
            else:
                bundle.data[
                    'follow_up_message'] = response.query_result.fulfillment_text
                if not bundle.data['follow_up_message']:
                    bundle.data['follow_up_message'] = "Sorry I have no idea"
                    bundle.data['follow_up'] = False
        except:
            bundle.data[
                'follow_up_message'] = "Something went wrong. Please check your internet connection"
        return bundle
Exemple #17
0
class Style(AbstractPageResource):
    parent = ForeignKey(CatalogPage,
                        'parent',
                        full=False,
                        null=True,
                        blank=True,
                        readonly=False)

    class Meta(BaseMeta):
        queryset = models.Style.objects.all()
        resource_name = "style"
        detail_uri_name = "slug"

    def prepend_urls(self):
        return [
            url(r"^(?P<resource_name>%s)/(?P<slug>[\w\d_.-]+)/$" %
                self._meta.resource_name,
                self.wrap_view('dispatch_detail'),
                name="api_dispatch_detail"),
        ]
Exemple #18
0
class DataResource(AbstractPageResource):
    parent = ForeignKey(CatalogPage,
                        'parent',
                        full=False,
                        null=True,
                        blank=True,
                        readonly=False)

    class Meta(BaseMeta):
        queryset = models.DataResource.objects.all()
        resource_name = 'data'
        fields = [
            'title', 'status', 'content', 'resource_file', 'resource_url',
            'resource_irods_file', 'kind', 'driver', 'parent'
        ]
        detail_uri_name = "slug"

    def prepend_urls(self):
        return [
            url(r"^(?P<resource_name>%s)/(?P<slug>[\w\d_.-]+)/$" %
                self._meta.resource_name,
                self.wrap_view('dispatch_detail'),
                name="api_dispatch_detail"),
        ]
class MXCiudadResource(CiudadResource):
    mx_estado = ForeignKey(EstadoResource, 'mx_estado', null=True, full=True)

    class Meta(CiudadResource.Meta):
        allowed_methods = ['get']
        CiudadResource.Meta.filtering['mx_estado'] = ALL_WITH_RELATIONS
Exemple #20
0
class UploadedDataResource(UploadedDataResource):  # noqa
    """
    API for accessing UploadedData.
    """

    user = ForeignKey(ProfileResource, 'user')