mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-07-11 16:52:25 +03:00
Apply black
This commit is contained in:
parent
858ffd4fbb
commit
96c07d8034
16
docs/conf.py
16
docs/conf.py
|
@ -60,18 +60,18 @@ source_suffix = ".rst"
|
||||||
master_doc = "index"
|
master_doc = "index"
|
||||||
|
|
||||||
# General information about the project.
|
# General information about the project.
|
||||||
project = u"Graphene Django"
|
project = "Graphene Django"
|
||||||
copyright = u"Graphene 2017"
|
copyright = "Graphene 2017"
|
||||||
author = u"Syrus Akbary"
|
author = "Syrus Akbary"
|
||||||
|
|
||||||
# The version info for the project you're documenting, acts as replacement for
|
# The version info for the project you're documenting, acts as replacement for
|
||||||
# |version| and |release|, also used in various other places throughout the
|
# |version| and |release|, also used in various other places throughout the
|
||||||
# built documents.
|
# built documents.
|
||||||
#
|
#
|
||||||
# The short X.Y version.
|
# The short X.Y version.
|
||||||
version = u"1.0"
|
version = "1.0"
|
||||||
# The full version, including alpha/beta/rc tags.
|
# The full version, including alpha/beta/rc tags.
|
||||||
release = u"1.0.dev"
|
release = "1.0.dev"
|
||||||
|
|
||||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||||
# for a list of supported languages.
|
# for a list of supported languages.
|
||||||
|
@ -276,7 +276,7 @@ latex_elements = {
|
||||||
# (source start file, target name, title,
|
# (source start file, target name, title,
|
||||||
# author, documentclass [howto, manual, or own class]).
|
# author, documentclass [howto, manual, or own class]).
|
||||||
latex_documents = [
|
latex_documents = [
|
||||||
(master_doc, "Graphene.tex", u"Graphene Documentation", u"Syrus Akbary", "manual")
|
(master_doc, "Graphene.tex", "Graphene Documentation", "Syrus Akbary", "manual")
|
||||||
]
|
]
|
||||||
|
|
||||||
# The name of an image file (relative to this directory) to place at the top of
|
# The name of an image file (relative to this directory) to place at the top of
|
||||||
|
@ -317,7 +317,7 @@ latex_documents = [
|
||||||
# One entry per manual page. List of tuples
|
# One entry per manual page. List of tuples
|
||||||
# (source start file, name, description, authors, manual section).
|
# (source start file, name, description, authors, manual section).
|
||||||
man_pages = [
|
man_pages = [
|
||||||
(master_doc, "graphene_django", u"Graphene Django Documentation", [author], 1)
|
(master_doc, "graphene_django", "Graphene Django Documentation", [author], 1)
|
||||||
]
|
]
|
||||||
|
|
||||||
# If true, show URL addresses after external links.
|
# If true, show URL addresses after external links.
|
||||||
|
@ -334,7 +334,7 @@ texinfo_documents = [
|
||||||
(
|
(
|
||||||
master_doc,
|
master_doc,
|
||||||
"Graphene-Django",
|
"Graphene-Django",
|
||||||
u"Graphene Django Documentation",
|
"Graphene Django Documentation",
|
||||||
author,
|
author,
|
||||||
"Graphene Django",
|
"Graphene Django",
|
||||||
"One line description of project.",
|
"One line description of project.",
|
||||||
|
|
|
@ -16,15 +16,12 @@
|
||||||
|
|
||||||
|
|
||||||
class Query(object):
|
class Query(object):
|
||||||
category = graphene.Field(CategoryType,
|
category = graphene.Field(CategoryType, id=graphene.Int(), name=graphene.String())
|
||||||
id=graphene.Int(),
|
|
||||||
name=graphene.String())
|
|
||||||
all_categories = graphene.List(CategoryType)
|
all_categories = graphene.List(CategoryType)
|
||||||
|
|
||||||
|
ingredient = graphene.Field(
|
||||||
ingredient = graphene.Field(IngredientType,
|
IngredientType, id=graphene.Int(), name=graphene.String()
|
||||||
id=graphene.Int(),
|
)
|
||||||
name=graphene.String())
|
|
||||||
all_ingredients = graphene.List(IngredientType)
|
all_ingredients = graphene.List(IngredientType)
|
||||||
|
|
||||||
def resolve_all_categories(self, info, **kwargs):
|
def resolve_all_categories(self, info, **kwargs):
|
||||||
|
@ -34,8 +31,8 @@
|
||||||
return Ingredient.objects.all()
|
return Ingredient.objects.all()
|
||||||
|
|
||||||
def resolve_category(self, info, **kwargs):
|
def resolve_category(self, info, **kwargs):
|
||||||
id = kwargs.get('id')
|
id = kwargs.get("id")
|
||||||
name = kwargs.get('name')
|
name = kwargs.get("name")
|
||||||
|
|
||||||
if id is not None:
|
if id is not None:
|
||||||
return Category.objects.get(pk=id)
|
return Category.objects.get(pk=id)
|
||||||
|
@ -46,8 +43,8 @@
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def resolve_ingredient(self, info, **kwargs):
|
def resolve_ingredient(self, info, **kwargs):
|
||||||
id = kwargs.get('id')
|
id = kwargs.get("id")
|
||||||
name = kwargs.get('name')
|
name = kwargs.get("name")
|
||||||
|
|
||||||
if id is not None:
|
if id is not None:
|
||||||
return Ingredient.objects.get(pk=id)
|
return Ingredient.objects.get(pk=id)
|
||||||
|
|
|
@ -10,24 +10,46 @@ class Migration(migrations.Migration):
|
||||||
|
|
||||||
initial = True
|
initial = True
|
||||||
|
|
||||||
dependencies = [
|
dependencies = []
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='Category',
|
name="Category",
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
(
|
||||||
('name', models.CharField(max_length=100)),
|
"id",
|
||||||
|
models.AutoField(
|
||||||
|
auto_created=True,
|
||||||
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
verbose_name="ID",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
("name", models.CharField(max_length=100)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='Ingredient',
|
name="Ingredient",
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
(
|
||||||
('name', models.CharField(max_length=100)),
|
"id",
|
||||||
('notes', models.TextField()),
|
models.AutoField(
|
||||||
('category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ingredients', to='ingredients.Category')),
|
auto_created=True,
|
||||||
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
verbose_name="ID",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
("name", models.CharField(max_length=100)),
|
||||||
|
("notes", models.TextField()),
|
||||||
|
(
|
||||||
|
"category",
|
||||||
|
models.ForeignKey(
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
related_name="ingredients",
|
||||||
|
to="ingredients.Category",
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -8,13 +8,13 @@ from django.db import migrations, models
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('ingredients', '0001_initial'),
|
("ingredients", "0001_initial"),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.AlterField(
|
migrations.AlterField(
|
||||||
model_name='ingredient',
|
model_name="ingredient",
|
||||||
name='notes',
|
name="notes",
|
||||||
field=models.TextField(blank=True, null=True),
|
field=models.TextField(blank=True, null=True),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -6,12 +6,12 @@ from django.db import migrations
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('ingredients', '0002_auto_20161104_0050'),
|
("ingredients", "0002_auto_20161104_0050"),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.AlterModelOptions(
|
migrations.AlterModelOptions(
|
||||||
name='category',
|
name="category",
|
||||||
options={'verbose_name_plural': 'Categories'},
|
options={"verbose_name_plural": "Categories"},
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -11,26 +11,62 @@ class Migration(migrations.Migration):
|
||||||
initial = True
|
initial = True
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('ingredients', '0001_initial'),
|
("ingredients", "0001_initial"),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='Recipe',
|
name="Recipe",
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
(
|
||||||
('title', models.CharField(max_length=100)),
|
"id",
|
||||||
('instructions', models.TextField()),
|
models.AutoField(
|
||||||
|
auto_created=True,
|
||||||
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
verbose_name="ID",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
("title", models.CharField(max_length=100)),
|
||||||
|
("instructions", models.TextField()),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='RecipeIngredient',
|
name="RecipeIngredient",
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
(
|
||||||
('amount', models.FloatField()),
|
"id",
|
||||||
('unit', models.CharField(choices=[('kg', 'Kilograms'), ('l', 'Litres'), ('', 'Units')], max_length=20)),
|
models.AutoField(
|
||||||
('ingredient', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='used_by', to='ingredients.Ingredient')),
|
auto_created=True,
|
||||||
('recipes', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='amounts', to='recipes.Recipe')),
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
verbose_name="ID",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
("amount", models.FloatField()),
|
||||||
|
(
|
||||||
|
"unit",
|
||||||
|
models.CharField(
|
||||||
|
choices=[("kg", "Kilograms"), ("l", "Litres"), ("", "Units")],
|
||||||
|
max_length=20,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"ingredient",
|
||||||
|
models.ForeignKey(
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
related_name="used_by",
|
||||||
|
to="ingredients.Ingredient",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"recipes",
|
||||||
|
models.ForeignKey(
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
related_name="amounts",
|
||||||
|
to="recipes.Recipe",
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -8,18 +8,26 @@ from django.db import migrations, models
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('recipes', '0001_initial'),
|
("recipes", "0001_initial"),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.RenameField(
|
migrations.RenameField(
|
||||||
model_name='recipeingredient',
|
model_name="recipeingredient",
|
||||||
old_name='recipes',
|
old_name="recipes",
|
||||||
new_name='recipe',
|
new_name="recipe",
|
||||||
),
|
),
|
||||||
migrations.AlterField(
|
migrations.AlterField(
|
||||||
model_name='recipeingredient',
|
model_name="recipeingredient",
|
||||||
name='unit',
|
name="unit",
|
||||||
field=models.CharField(choices=[(b'unit', b'Units'), (b'kg', b'Kilograms'), (b'l', b'Litres'), (b'st', b'Shots')], max_length=20),
|
field=models.CharField(
|
||||||
|
choices=[
|
||||||
|
(b"unit", b"Units"),
|
||||||
|
(b"kg", b"Kilograms"),
|
||||||
|
(b"l", b"Litres"),
|
||||||
|
(b"st", b"Shots"),
|
||||||
|
],
|
||||||
|
max_length=20,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -6,13 +6,21 @@ from django.db import migrations, models
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('recipes', '0002_auto_20161104_0106'),
|
("recipes", "0002_auto_20161104_0106"),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.AlterField(
|
migrations.AlterField(
|
||||||
model_name='recipeingredient',
|
model_name="recipeingredient",
|
||||||
name='unit',
|
name="unit",
|
||||||
field=models.CharField(choices=[('unit', 'Units'), ('kg', 'Kilograms'), ('l', 'Litres'), ('st', 'Shots')], max_length=20),
|
field=models.CharField(
|
||||||
|
choices=[
|
||||||
|
("unit", "Units"),
|
||||||
|
("kg", "Kilograms"),
|
||||||
|
("l", "Litres"),
|
||||||
|
("st", "Shots"),
|
||||||
|
],
|
||||||
|
max_length=20,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -10,24 +10,46 @@ class Migration(migrations.Migration):
|
||||||
|
|
||||||
initial = True
|
initial = True
|
||||||
|
|
||||||
dependencies = [
|
dependencies = []
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='Category',
|
name="Category",
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
(
|
||||||
('name', models.CharField(max_length=100)),
|
"id",
|
||||||
|
models.AutoField(
|
||||||
|
auto_created=True,
|
||||||
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
verbose_name="ID",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
("name", models.CharField(max_length=100)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='Ingredient',
|
name="Ingredient",
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
(
|
||||||
('name', models.CharField(max_length=100)),
|
"id",
|
||||||
('notes', models.TextField()),
|
models.AutoField(
|
||||||
('category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ingredients', to='ingredients.Category')),
|
auto_created=True,
|
||||||
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
verbose_name="ID",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
("name", models.CharField(max_length=100)),
|
||||||
|
("notes", models.TextField()),
|
||||||
|
(
|
||||||
|
"category",
|
||||||
|
models.ForeignKey(
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
related_name="ingredients",
|
||||||
|
to="ingredients.Category",
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -8,13 +8,13 @@ from django.db import migrations, models
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('ingredients', '0001_initial'),
|
("ingredients", "0001_initial"),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.AlterField(
|
migrations.AlterField(
|
||||||
model_name='ingredient',
|
model_name="ingredient",
|
||||||
name='notes',
|
name="notes",
|
||||||
field=models.TextField(blank=True, null=True),
|
field=models.TextField(blank=True, null=True),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -11,26 +11,62 @@ class Migration(migrations.Migration):
|
||||||
initial = True
|
initial = True
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('ingredients', '0001_initial'),
|
("ingredients", "0001_initial"),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='Recipe',
|
name="Recipe",
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
(
|
||||||
('title', models.CharField(max_length=100)),
|
"id",
|
||||||
('instructions', models.TextField()),
|
models.AutoField(
|
||||||
|
auto_created=True,
|
||||||
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
verbose_name="ID",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
("title", models.CharField(max_length=100)),
|
||||||
|
("instructions", models.TextField()),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='RecipeIngredient',
|
name="RecipeIngredient",
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
(
|
||||||
('amount', models.FloatField()),
|
"id",
|
||||||
('unit', models.CharField(choices=[('kg', 'Kilograms'), ('l', 'Litres'), ('', 'Units')], max_length=20)),
|
models.AutoField(
|
||||||
('ingredient', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='used_by', to='ingredients.Ingredient')),
|
auto_created=True,
|
||||||
('recipes', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='amounts', to='recipes.Recipe')),
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
verbose_name="ID",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
("amount", models.FloatField()),
|
||||||
|
(
|
||||||
|
"unit",
|
||||||
|
models.CharField(
|
||||||
|
choices=[("kg", "Kilograms"), ("l", "Litres"), ("", "Units")],
|
||||||
|
max_length=20,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"ingredient",
|
||||||
|
models.ForeignKey(
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
related_name="used_by",
|
||||||
|
to="ingredients.Ingredient",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"recipes",
|
||||||
|
models.ForeignKey(
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
related_name="amounts",
|
||||||
|
to="recipes.Recipe",
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -8,18 +8,26 @@ from django.db import migrations, models
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('recipes', '0001_initial'),
|
("recipes", "0001_initial"),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.RenameField(
|
migrations.RenameField(
|
||||||
model_name='recipeingredient',
|
model_name="recipeingredient",
|
||||||
old_name='recipes',
|
old_name="recipes",
|
||||||
new_name='recipe',
|
new_name="recipe",
|
||||||
),
|
),
|
||||||
migrations.AlterField(
|
migrations.AlterField(
|
||||||
model_name='recipeingredient',
|
model_name="recipeingredient",
|
||||||
name='unit',
|
name="unit",
|
||||||
field=models.CharField(choices=[(b'unit', b'Units'), (b'kg', b'Kilograms'), (b'l', b'Litres'), (b'st', b'Shots')], max_length=20),
|
field=models.CharField(
|
||||||
|
choices=[
|
||||||
|
(b"unit", b"Units"),
|
||||||
|
(b"kg", b"Kilograms"),
|
||||||
|
(b"l", b"Litres"),
|
||||||
|
(b"st", b"Shots"),
|
||||||
|
],
|
||||||
|
max_length=20,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -66,7 +66,10 @@ class DjangoListField(Field):
|
||||||
_type = _type.of_type
|
_type = _type.of_type
|
||||||
django_object_type = _type.of_type.of_type
|
django_object_type = _type.of_type.of_type
|
||||||
return partial(
|
return partial(
|
||||||
self.list_resolver, django_object_type, parent_resolver, self.get_manager(),
|
self.list_resolver,
|
||||||
|
django_object_type,
|
||||||
|
parent_resolver,
|
||||||
|
self.get_manager(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -60,8 +60,7 @@ if VERSION[0] < 2:
|
||||||
|
|
||||||
|
|
||||||
def setup_filterset(filterset_class):
|
def setup_filterset(filterset_class):
|
||||||
""" Wrap a provided filterset in Graphene-specific functionality
|
"""Wrap a provided filterset in Graphene-specific functionality"""
|
||||||
"""
|
|
||||||
return type(
|
return type(
|
||||||
"Graphene{}".format(filterset_class.__name__),
|
"Graphene{}".format(filterset_class.__name__),
|
||||||
(filterset_class, GrapheneFilterSetMixin),
|
(filterset_class, GrapheneFilterSetMixin),
|
||||||
|
@ -70,8 +69,7 @@ def setup_filterset(filterset_class):
|
||||||
|
|
||||||
|
|
||||||
def custom_filterset_factory(model, filterset_base_class=FilterSet, **meta):
|
def custom_filterset_factory(model, filterset_base_class=FilterSet, **meta):
|
||||||
""" Create a filterset for the given model using the provided meta data
|
"""Create a filterset for the given model using the provided meta data"""
|
||||||
"""
|
|
||||||
meta.update({"model": model})
|
meta.update({"model": model})
|
||||||
meta_class = type(str("Meta"), (object,), meta)
|
meta_class = type(str("Meta"), (object,), meta)
|
||||||
filterset = type(
|
filterset = type(
|
||||||
|
|
|
@ -92,10 +92,22 @@ def Query(Event, EventType):
|
||||||
def resolve_events(self, info, **kwargs):
|
def resolve_events(self, info, **kwargs):
|
||||||
|
|
||||||
events = [
|
events = [
|
||||||
Event(name="Live Show", tags=["concert", "music", "rock"],),
|
Event(
|
||||||
Event(name="Musical", tags=["movie", "music"],),
|
name="Live Show",
|
||||||
Event(name="Ballet", tags=["concert", "dance"],),
|
tags=["concert", "music", "rock"],
|
||||||
Event(name="Speech", tags=[],),
|
),
|
||||||
|
Event(
|
||||||
|
name="Musical",
|
||||||
|
tags=["movie", "music"],
|
||||||
|
),
|
||||||
|
Event(
|
||||||
|
name="Ballet",
|
||||||
|
tags=["concert", "dance"],
|
||||||
|
),
|
||||||
|
Event(
|
||||||
|
name="Speech",
|
||||||
|
tags=[],
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
STORE["events"] = events
|
STORE["events"] = events
|
||||||
|
|
|
@ -52,13 +52,22 @@ def reporter_article_data():
|
||||||
first_name="Jane", last_name="Doe", email="janedoe@example.com", a_choice=2
|
first_name="Jane", last_name="Doe", email="janedoe@example.com", a_choice=2
|
||||||
)
|
)
|
||||||
Article.objects.create(
|
Article.objects.create(
|
||||||
headline="Article Node 1", reporter=john, editor=john, lang="es",
|
headline="Article Node 1",
|
||||||
|
reporter=john,
|
||||||
|
editor=john,
|
||||||
|
lang="es",
|
||||||
)
|
)
|
||||||
Article.objects.create(
|
Article.objects.create(
|
||||||
headline="Article Node 2", reporter=john, editor=john, lang="en",
|
headline="Article Node 2",
|
||||||
|
reporter=john,
|
||||||
|
editor=john,
|
||||||
|
lang="en",
|
||||||
)
|
)
|
||||||
Article.objects.create(
|
Article.objects.create(
|
||||||
headline="Article Node 3", reporter=jane, editor=jane, lang="en",
|
headline="Article Node 3",
|
||||||
|
reporter=jane,
|
||||||
|
editor=jane,
|
||||||
|
lang="en",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,7 +87,13 @@ def test_filter_enum_on_connection(schema, reporter_article_data):
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
expected = {"allArticles": {"edges": [{"node": {"headline": "Article Node 1"}},]}}
|
expected = {
|
||||||
|
"allArticles": {
|
||||||
|
"edges": [
|
||||||
|
{"node": {"headline": "Article Node 1"}},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
result = schema.execute(query)
|
result = schema.execute(query)
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
|
|
|
@ -1208,13 +1208,23 @@ def test_filter_string_contains():
|
||||||
result = schema.execute(query, variables={"filter": "Ja"})
|
result = schema.execute(query, variables={"filter": "Ja"})
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
assert result.data == {
|
assert result.data == {
|
||||||
"people": {"edges": [{"node": {"name": "Jack"}}, {"node": {"name": "Jane"}},]}
|
"people": {
|
||||||
|
"edges": [
|
||||||
|
{"node": {"name": "Jack"}},
|
||||||
|
{"node": {"name": "Jane"}},
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result = schema.execute(query, variables={"filter": "o"})
|
result = schema.execute(query, variables={"filter": "o"})
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
assert result.data == {
|
assert result.data == {
|
||||||
"people": {"edges": [{"node": {"name": "Joe"}}, {"node": {"name": "Bob"}},]}
|
"people": {
|
||||||
|
"edges": [
|
||||||
|
{"node": {"name": "Joe"}},
|
||||||
|
{"node": {"name": "Bob"}},
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -374,16 +374,28 @@ def test_enum_in_filter(query):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Reporter.objects.create(
|
Reporter.objects.create(
|
||||||
first_name="John", last_name="Doe", email="john@doe.com", reporter_type=1
|
first_name="John",
|
||||||
|
last_name="Doe",
|
||||||
|
email="john@doe.com",
|
||||||
|
reporter_type=1,
|
||||||
)
|
)
|
||||||
Reporter.objects.create(
|
Reporter.objects.create(
|
||||||
first_name="Jean", last_name="Bon", email="jean@bon.com", reporter_type=2
|
first_name="Jean",
|
||||||
|
last_name="Bon",
|
||||||
|
email="jean@bon.com",
|
||||||
|
reporter_type=2,
|
||||||
)
|
)
|
||||||
Reporter.objects.create(
|
Reporter.objects.create(
|
||||||
first_name="Jane", last_name="Doe", email="jane@doe.com", reporter_type=2
|
first_name="Jane",
|
||||||
|
last_name="Doe",
|
||||||
|
email="jane@doe.com",
|
||||||
|
reporter_type=2,
|
||||||
)
|
)
|
||||||
Reporter.objects.create(
|
Reporter.objects.create(
|
||||||
first_name="Jack", last_name="Black", email="jack@black.com", reporter_type=None
|
first_name="Jack",
|
||||||
|
last_name="Black",
|
||||||
|
email="jack@black.com",
|
||||||
|
reporter_type=None,
|
||||||
)
|
)
|
||||||
|
|
||||||
schema = Schema(query=query)
|
schema = Schema(query=query)
|
||||||
|
|
|
@ -103,13 +103,22 @@ def test_typed_filter_schema(schema):
|
||||||
def test_typed_filters_work(schema):
|
def test_typed_filters_work(schema):
|
||||||
reporter = Reporter.objects.create(first_name="John", last_name="Doe", email="")
|
reporter = Reporter.objects.create(first_name="John", last_name="Doe", email="")
|
||||||
Article.objects.create(
|
Article.objects.create(
|
||||||
headline="A", reporter=reporter, editor=reporter, lang="es",
|
headline="A",
|
||||||
|
reporter=reporter,
|
||||||
|
editor=reporter,
|
||||||
|
lang="es",
|
||||||
)
|
)
|
||||||
Article.objects.create(
|
Article.objects.create(
|
||||||
headline="B", reporter=reporter, editor=reporter, lang="es",
|
headline="B",
|
||||||
|
reporter=reporter,
|
||||||
|
editor=reporter,
|
||||||
|
lang="es",
|
||||||
)
|
)
|
||||||
Article.objects.create(
|
Article.objects.create(
|
||||||
headline="C", reporter=reporter, editor=reporter, lang="en",
|
headline="C",
|
||||||
|
reporter=reporter,
|
||||||
|
editor=reporter,
|
||||||
|
lang="en",
|
||||||
)
|
)
|
||||||
|
|
||||||
query = "query { articles (lang_In: [ES]) { edges { node { headline } } } }"
|
query = "query { articles (lang_In: [ES]) { edges { node { headline } } } }"
|
||||||
|
|
|
@ -99,7 +99,9 @@ def get_filtering_args_from_filterset(filterset_class, type):
|
||||||
field_type = graphene.List(field_type)
|
field_type = graphene.List(field_type)
|
||||||
|
|
||||||
args[name] = graphene.Argument(
|
args[name] = graphene.Argument(
|
||||||
type=field_type, description=filter_field.label, required=required,
|
type=field_type,
|
||||||
|
description=filter_field.label,
|
||||||
|
required=required,
|
||||||
)
|
)
|
||||||
|
|
||||||
return args
|
return args
|
||||||
|
|
|
@ -50,7 +50,7 @@ class Reporter(models.Model):
|
||||||
"Reporter Type",
|
"Reporter Type",
|
||||||
null=True,
|
null=True,
|
||||||
blank=True,
|
blank=True,
|
||||||
choices=[(1, u"Regular"), (2, u"CNN Reporter")],
|
choices=[(1, "Regular"), (2, "CNN Reporter")],
|
||||||
)
|
)
|
||||||
|
|
||||||
def __str__(self): # __unicode__ on Python 2
|
def __str__(self): # __unicode__ on Python 2
|
||||||
|
@ -109,7 +109,7 @@ class Article(models.Model):
|
||||||
"Importance",
|
"Importance",
|
||||||
null=True,
|
null=True,
|
||||||
blank=True,
|
blank=True,
|
||||||
choices=[(1, u"Very important"), (2, u"Not as important")],
|
choices=[(1, "Very important"), (2, "Not as important")],
|
||||||
)
|
)
|
||||||
|
|
||||||
def __str__(self): # __unicode__ on Python 2
|
def __str__(self): # __unicode__ on Python 2
|
||||||
|
|
|
@ -1444,7 +1444,11 @@ def test_connection_should_enable_offset_filtering():
|
||||||
result = schema.execute(query)
|
result = schema.execute(query)
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
expected = {
|
expected = {
|
||||||
"allReporters": {"edges": [{"node": {"firstName": "Some", "lastName": "Guy"}},]}
|
"allReporters": {
|
||||||
|
"edges": [
|
||||||
|
{"node": {"firstName": "Some", "lastName": "Guy"}},
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
assert result.data == expected
|
assert result.data == expected
|
||||||
|
|
||||||
|
@ -1484,7 +1488,9 @@ def test_connection_should_enable_offset_filtering_higher_than_max_limit(
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
expected = {
|
expected = {
|
||||||
"allReporters": {
|
"allReporters": {
|
||||||
"edges": [{"node": {"firstName": "Some", "lastName": "Lady"}},]
|
"edges": [
|
||||||
|
{"node": {"firstName": "Some", "lastName": "Lady"}},
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert result.data == expected
|
assert result.data == expected
|
||||||
|
@ -1551,6 +1557,10 @@ def test_connection_should_allow_offset_filtering_with_after():
|
||||||
result = schema.execute(query, variable_values=dict(after=after))
|
result = schema.execute(query, variable_values=dict(after=after))
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
expected = {
|
expected = {
|
||||||
"allReporters": {"edges": [{"node": {"firstName": "Jane", "lastName": "Roe"}},]}
|
"allReporters": {
|
||||||
|
"edges": [
|
||||||
|
{"node": {"firstName": "Jane", "lastName": "Roe"}},
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
assert result.data == expected
|
assert result.data == expected
|
||||||
|
|
|
@ -7,4 +7,4 @@ def test_to_const():
|
||||||
|
|
||||||
|
|
||||||
def test_to_const_unicode():
|
def test_to_const_unicode():
|
||||||
assert to_const(u"Skoða þetta unicode stöff") == "SKODA_THETTA_UNICODE_STOFF"
|
assert to_const("Skoða þetta unicode stöff") == "SKODA_THETTA_UNICODE_STOFF"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user