コード例 #1
0
    def post(self):
        serializer = SqlSerializer(data=self.data)
        serializer.is_valid(raise_exception=True)

        try:
            response = Response(serializer.execute())
            self.write_response(response)
        except SqlError as e:
            self.set_status(400)
            self.write_response(Response({'error': e.detail.string}))
コード例 #2
0
ファイル: model.py プロジェクト: user-geliang/jet-bridge
    def group(self, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())

        x_column = self.get_argument('_x_column')
        x_lookup_name = self.get_argument('_x_lookup', None)
        y_func = self.get_argument('_y_func').lower()
        y_column = self.get_argument('_y_column', self.lookup_field)

        model_serializer = self.get_serializer()

        # x_serializers = list(filter(lambda x: x.field_name == x_column, model_serializer.fields))
        # x_serializer = x_serializers[0]

        # y_serializers = list(filter(lambda x: x.field_name == y_column, model_serializer.fields))
        # y_serializer = y_serializers[0]

        filter_instance = ModelGroupFilter()
        filter_instance.model = self.model
        queryset = filter_instance.filter(queryset, {
            'x_column': x_column,
            'x_lookup': x_lookup_name,
            'y_func': y_func,
            'y_column': y_column
        })
        serializer = ModelGroupSerializer(
            instance=queryset,
            many=True,
            # TODO: Refactor serializer
            # group_serializer=x_serializer,
            # y_func_serializer=y_serializer
        )

        self.write_response(Response(serializer.representation_data))
コード例 #3
0
ファイル: register.py プロジェクト: rbhushan90/jet-bridge
    def get(self, *args, **kwargs):
        try:
            session = Session()
            token, created = register_token(session)

            if not token:
                return

            if is_token_activated(session):
                response = Response(
                    {'message': 'Project token is already activated'})
                self.write_response(response)
                return

            if settings.WEB_BASE_URL.startswith(
                    'https'
            ) and not self.request.full_url().startswith('https'):
                web_base_url = 'http{}'.format(settings.WEB_BASE_URL[5:])
            else:
                web_base_url = settings.WEB_BASE_URL

            url = '{}/projects/register/{}'.format(web_base_url, token.token)
            query_string = 'referrer={}'.format(
                quote(self.request.full_url().encode('utf8')))

            self.redirect('%s?%s' % (url, query_string))
        finally:
            session.close()
コード例 #4
0
    def post(self):
        # TODO: Move to serializer
        file = self.request.files.get('file', [])[0]
        path = self.get_body_argument('path')
        filename = self.get_body_argument('filename', file.filename)

        upload_path = os.path.join(settings.MEDIA_ROOT, path, filename)
        upload_path = self.get_available_name(upload_path)

        relative_upload_path = upload_path[len(settings.MEDIA_ROOT) + 1:]

        # TODO: Add validations

        if not os.path.exists(os.path.dirname(upload_path)):
            try:
                os.makedirs(os.path.dirname(upload_path))
            except OSError:
                raise

        with open(upload_path, 'wb') as f:
            f.write(file['body'])

        response = Response({
            'uploaded_path':
            relative_upload_path,
            'uploaded_url':
            self.build_absolute_uri('/media/{}'.format(relative_upload_path))
        })
        self.write_response(response)
コード例 #5
0
ファイル: create.py プロジェクト: user-geliang/jet-bridge
 def create(self, *args, **kwargs):
     serializer = self.get_serializer(data=self.data)
     serializer.is_valid(raise_exception=True)
     self.perform_create(serializer)
     self.write_response(
         Response(serializer.representation_data,
                  status=status.HTTP_201_CREATED))
コード例 #6
0
ファイル: model.py プロジェクト: user-geliang/jet-bridge
    def reset_order(self, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())
        ResetOrderSerializer = get_reset_order_serializer(self.get_model(), queryset, self.session)

        serializer = ResetOrderSerializer(data=self.data)
        serializer.is_valid(raise_exception=True)
        serializer.save()

        self.write_response(Response(serializer.representation_data))
コード例 #7
0
ファイル: api.py プロジェクト: user-geliang/jet-bridge
 def get(self):
     media_url_base = settings.MEDIA_BASE_URL + '{}' if settings.MEDIA_BASE_URL \
         else self.build_absolute_uri('/media/{}')
     response = Response({
         'version': VERSION,
         'type': 'jet_bridge',
         'media_url_template': media_url_base
     })
     self.write_response(response)
コード例 #8
0
 def get_paginated_response(self, data):
     return Response(
         OrderedDict([
             ('count', self.count),
             ('next', self.get_next_link()),
             ('previous', self.get_previous_link()),
             ('results', data),
             ('num_pages', self.get_pages_count()),
             ('per_page', self.page_size),
         ]))
コード例 #9
0
 def get(self):
     response = Response({
         'version':
         VERSION,
         'type':
         'jet_bridge',
         'media_url_template':
         self.build_absolute_uri('/media/{}')
     })
     self.write_response(response)
コード例 #10
0
ファイル: model.py プロジェクト: user-geliang/jet-bridge
    def get_siblings(self, *args, **kwargs):
        lookup_url_kwarg = self.lookup_url_kwarg or 'pk'

        assert lookup_url_kwarg in self.path_kwargs

        model_field = getattr(self.get_model(), self.lookup_field)
        obj = self.get_queryset().filter(getattr(model_field, '__eq__')(self.path_kwargs[lookup_url_kwarg])).first()

        self.check_object_permissions(obj)

        queryset = self.filter_queryset(self.get_queryset())

        self.write_response(Response(get_model_siblings(self.model, obj, queryset)))
コード例 #11
0
    def list(self, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())

        page = self.paginate_queryset(queryset)
        if page is not None:
            serializer = self.get_serializer(instance=page, many=True)
            response = self.get_paginated_response(serializer.representation_data)
            self.write_response(response)
            return

        serializer = self.get_serializer(instance=queryset, many=True)
        response = Response(serializer.representation_data)
        self.write_response(response)
コード例 #12
0
ファイル: model.py プロジェクト: user-geliang/jet-bridge
    def aggregate(self, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())

        y_func = self.get_argument('_y_func').lower()
        y_column = self.get_argument('_y_column', self.lookup_field)

        model_serializer = self.get_serializer()

        y_serializers = list(filter(lambda x: x.field_name == y_column, model_serializer.fields))
        y_serializer = y_serializers[0]

        filter_instance = ModelAggregateFilter()
        filter_instance.model = self.model
        queryset = filter_instance.filter(queryset, {
            'y_func': y_func,
            'y_column': y_column
        })

        result = y_serializer.to_representation(queryset[0])  # TODO: Refactor serializer

        self.write_response(Response({
            'y_func': result
        }))
コード例 #13
0
 def retrieve(self, *args, **kwargs):
     instance = self.get_object()
     serializer = self.get_serializer(instance=instance)
     self.write_response(Response(serializer.representation_data))
コード例 #14
0
 def get(self, *args, **kwargs):
     queryset = self.get_queryset()
     serializer = self.serializer_class(instance=queryset, many=True)
     response = Response(serializer.representation_data)
     self.write_response(response)
コード例 #15
0
ファイル: sql.py プロジェクト: aabouissa/jet-bridge
    def post(self):
        serializer = SqlSerializer(data=self.data)
        serializer.is_valid(raise_exception=True)

        response = Response(serializer.execute())
        self.write_response(response)
コード例 #16
0
ファイル: destroy.py プロジェクト: user-geliang/jet-bridge
 def delete(self, *args, **kwargs):
     instance = self.get_object()
     self.perform_destroy(instance)
     self.write_response(Response(status=status.HTTP_204_NO_CONTENT))