コード例 #1
0
ファイル: views.py プロジェクト: jartieda/wstore
    def read(self, request):

        # Get data contained in query string
        querytext = request.GET.get('q', '')
        indexname = request.GET.get('namespace', '')

        # if indexname is empty, builds error response
        if indexname is '':
            return build_response(request, 400, 'The "namespace" field is required.')

        # if indexname does not exist, builds error response
        if not ResourceBrowser.is_stored(indexname):
            return build_response(request, 400, 'The "namespace" field does not exist.')

        # Search for stored resources
        response = ResourceBrowser.search(indexname, querytext)

        return HttpResponse(json.dumps(response), content_type='application/json')
コード例 #2
0
ファイル: updateindex.py プロジェクト: Fiware/apps.Wstore
    def handle(self, *args, **options):

        # Loop over the namespaces
        for namespace in args:

            # Clear the index of this type of resource
            ix = ResourceBrowser.clear_index(namespace)

            if ix is None:
                raise CommandError('Resource "%s" does not exist' % namespace)

            # Get the model of this type of resource
            model = ResourceBrowser.get_resource_model(namespace)

            # Add model fields for each resource
            for resource in model.objects.all():
                ResourceBrowser.add_resource(namespace, resource=resource)

            self.stdout.write('The index of "%s" resource was updated successfully.\n' % namespace)
コード例 #3
0
    def read(self, request):

        # Get data contained in query string
        querytext = request.GET.get('q', '')
        indexname = request.GET.get('namespace', '')

        # if indexname is empty, builds error response
        if indexname is '':
            return build_response(request, 400,
                                  'The "namespace" field is required.')

        # if indexname does not exist, builds error response
        if not ResourceBrowser.is_stored(indexname):
            return build_response(request, 400,
                                  'The "namespace" field does not exist.')

        # Search for stored resources
        response = ResourceBrowser.search(indexname, querytext)

        return HttpResponse(json.dumps(response),
                            content_type='application/json')
コード例 #4
0
    def handle(self, *args, **options):

        # Loop over the namespaces
        for namespace in args:

            # Clear the index of this type of resource
            ix = ResourceBrowser.clear_index(namespace)

            if ix is None:
                raise CommandError('Resource "%s" does not exist' % namespace)

            # Get the model of this type of resource
            model = ResourceBrowser.get_resource_model(namespace)

            # Add model fields for each resource
            for resource in model.objects.all():
                ResourceBrowser.add_resource(namespace, resource=resource)

            self.stdout.write(
                'The index of "%s" resource was updated successfully.\n' %
                namespace)
コード例 #5
0
def create_user_profile(sender, instance, created, **kwargs):

    if created:
        # Create a private organization for the user
        default_organization = Organization.objects.get_or_create(
            name=instance.username)
        default_organization[0].managers.append(instance.pk)
        default_organization[0].save()

        profile, created = UserProfile.objects.get_or_create(
            user=instance,
            organizations=[{
                'organization': default_organization[0].pk,
                'roles': ['customer', 'developer']
            }],
            current_organization=default_organization[0])
        if instance.first_name and instance.last_name:
            profile.complete_name = instance.first_name + ' ' + instance.last_name
            profile.save()

    # User search is only used for organization view that is
    # not needed when using external authentication
    if not settings.OILAUTH:
        ResourceBrowser.add_resource('user', resource=instance)
コード例 #6
0
ファイル: models.py プロジェクト: perezdf/wstore
def create_user_profile(sender, instance, created, **kwargs):

    if created:
        # Create a private organization for the user
        default_organization = Organization.objects.get_or_create(name=instance.username)
        default_organization[0].managers.append(instance.pk)
        default_organization[0].save()

        profile, created = UserProfile.objects.get_or_create(
            user=instance,
            organizations=[{
                'organization': default_organization[0].pk,
                'roles': ['customer', 'developer']
            }],
            current_organization=default_organization[0]
        )
        if instance.first_name and instance.last_name:
            profile.complete_name = instance.first_name + ' ' + instance.last_name
            profile.save()

    # User search is only used for organization view that is
    # not needed when using external authentication
    if not settings.OILAUTH:
        ResourceBrowser.add_resource('user', resource=instance)