Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ on:

jobs:
build:
name: Build and test on Python ${{ matrix.python-version }}
name: Build and test on Python ${{ matrix.python-version }} / Django ${{ matrix.django-version }}
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10']
python-version: ['3.10', '3.11', '3.12']
Comment thread
qarlosh marked this conversation as resolved.
django-version: ['4.2', '5.2']
services:
mongo:
image: mongo:5
Expand All @@ -37,6 +38,9 @@ jobs:
python -m pip install --upgrade pip
pip install poetry
poetry install
- name: Pin Django version under test
run: |
poetry run pip install "Django~=${{ matrix.django-version }}.0"
- name: Linting
run: |
poetry run flake8
Expand Down Expand Up @@ -70,7 +74,7 @@ jobs:
poetry run pytest
- name: Fix coverage report for Sonar
run: |
sed -i 's/\/home\/runner\/work\/django-mongoengine-rql\/django-mongoengine-rql\//\/github\/workspace\//g' ./tests/reports/coverage.xml
sed -i "s|$(pwd)/|${GITHUB_WORKSPACE}/|g" ./tests/reports/coverage.xml
- name: SonarCloud
uses: SonarSource/sonarcloud-github-action@master
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
python-version: ['3.10']
steps:
- uses: actions/checkout@v2
with:
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
RQL (Resource query language) is designed for modern application development. It is built for the web, ready for NoSQL, and highly extensible with simple syntax.
This is a query language for fast and convenient database interaction. RQL was designed for use in URLs to request object-style data structures.

This library is a Django-Mongoengine specific implementation of RQL filtering.
This library is a Mongoengine-specific implementation of RQL filtering.

[RQL Reference](https://connect.cloudblue.com/community/api/rql/)

[Django RQL](https://github.com/cloudblue/django-rql)

[Django Mongoengine](https://github.com/MongoEngine/django-mongoengine)
[Mongoengine](https://github.com/MongoEngine/mongoengine)

## Install

Expand Down Expand Up @@ -85,15 +85,15 @@ Due to implementation and Mongo engine features there may be some limitations in

## Development

1. Python 3.8+
1. Python 3.10+
2. Install dependencies `pip install poetry && poetry install`
3. We use `isort` library to order and format our imports, and `black` - to format the code.
We check it using `flake8-isort` and `flake8-black` libraries (automatically on `flake8` run).
For convenience you may run `docker compose run format` to format the code.

## Testing

1. Python 3.8+
1. Python 3.10+
0. Install dependencies `pip install poetry && poetry install`

Check code style: `poetry run flake8`
Expand Down
4 changes: 2 additions & 2 deletions dj_mongoengine_rql/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
#

from dj_rql.constants import FilterTypes
from django_mongoengine import fields
from mongoengine import fields


class MongoengineFilterTypes(FilterTypes):
mapper = [
(fields.BooleanField, FilterTypes.BOOLEAN),
(fields.DateTimeField, FilterTypes.DATETIME),
(fields.DateField, FilterTypes.DATE),
(fields.DateTimeField, FilterTypes.DATETIME),
Comment thread
qarlosh marked this conversation as resolved.
(fields.DecimalField, FilterTypes.DECIMAL),
(fields.FloatField, FilterTypes.FLOAT),
(fields.IntField, FilterTypes.INT),
Expand Down
35 changes: 31 additions & 4 deletions dj_mongoengine_rql/filter_cls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

from dj_rql.constants import DjangoLookups
from dj_rql.filter_cls import RQLFilterClass
from django_mongoengine.fields.djangoflavor import DjangoField
from py_rql.constants import FilterLookups
from django.core.exceptions import FieldDoesNotExist
from mongoengine.base import BaseField
from py_rql.constants import FilterLookups, RQL_EMPTY

from dj_mongoengine_rql.constants import MongoengineFilterTypes
from dj_mongoengine_rql.q import Q
Expand All @@ -25,11 +26,17 @@ def _is_valid_model_cls(cls, model):

@classmethod
def _is_field_supported(cls, field):
return isinstance(field, DjangoField)
return isinstance(field, BaseField)

@staticmethod
def _is_blank(field):
if hasattr(field, 'required'):
return not field.required
return getattr(field, 'blank', False)

@classmethod
def _is_field_nullable(cls, field):
return field.blank or field.primary_key
return cls._is_blank(field) or field.primary_key

@classmethod
def _get_field_related_model(cls, field):
Expand All @@ -39,6 +46,26 @@ def _get_field_related_model(cls, field):
def _get_decimal_field_precision(cls, field):
return field.precision

@classmethod
def _get_model_field(cls, model, field_name):
try:
return model._fields[field_name]
except KeyError:
raise FieldDoesNotExist(
'{0} has no field named {1!r}'.format(model.__name__, field_name),
)

@classmethod
def _convert_value(cls, django_field, str_value, use_repr=False):
if cls.remove_quotes(str_value) == RQL_EMPTY:
ft = cls.FILTER_TYPES_CLS
filter_type = ft.field_filter_type(django_field)
if filter_type in (ft.STRING, ft.INT):
if filter_type == ft.INT or not cls._is_blank(django_field):
raise ValueError
return ''
return super()._convert_value(django_field, str_value, use_repr=use_repr)

def _build_django_q(self, filter_item, django_lookup, filter_lookup, typed_value):
if django_lookup in (DjangoLookups.EXACT, DjangoLookups.NULL):
v = typed_value if django_lookup == DjangoLookups.EXACT else None
Expand Down
Loading
Loading