diff --git a/graphene_django/forms/forms.py b/graphene_django/forms/forms.py index 1ceab7f..16e946d 100644 --- a/graphene_django/forms/forms.py +++ b/graphene_django/forms/forms.py @@ -1,7 +1,7 @@ import binascii -from django import forms from django.core.exceptions import ValidationError +from django import forms from django.forms import CharField, Field, MultipleChoiceField from django.utils.translation import gettext_lazy as _ @@ -28,19 +28,6 @@ class GlobalIDFormField(Field): return value - -class GlobalIDMultipleChoiceField(MultipleChoiceField): - default_error_messages = { - "invalid_choice": _("One of the specified IDs was invalid (%(value)s)."), - "invalid_list": _("Enter a list of values."), - } - - def valid_value(self, value): - # Clean will raise a validation error if there is a problem - GlobalIDFormField().clean(value) - return True - - class HeaderForm(forms.Form): # make a ChoiceField for 'JWT' and other methods -- use a widget? headers = forms.CharField(help_text="Enter auth method to be stored in the as HTTP_AUTHORIZATION", initial="JWT ") @@ -52,3 +39,4 @@ class HeaderForm(forms.Form): # Remember to always return the cleaned data. return data + diff --git a/graphene_django/settings.py b/graphene_django/settings.py index 9a5e8a9..05eae80 100644 --- a/graphene_django/settings.py +++ b/graphene_django/settings.py @@ -36,13 +36,14 @@ DEFAULTS = { # Max items returned in ConnectionFields / FilterConnectionFields "RELAY_CONNECTION_MAX_LIMIT": 100, "CAMELCASE_ERRORS": False, + "SOURCE": None } if settings.DEBUG: DEFAULTS["MIDDLEWARE"] += ("graphene_django.debug.DjangoDebugMiddleware",) # List of settings that may be in string import notation. -IMPORT_STRINGS = ("MIDDLEWARE", "SCHEMA") +IMPORT_STRINGS = ("MIDDLEWARE", "SCHEMA", "SOURCE") def perform_import(val, setting_name): diff --git a/graphene_django/templates/graphene/base.html b/graphene_django/templates/graphene/base.html index 673e85e..5a29b32 100755 --- a/graphene_django/templates/graphene/base.html +++ b/graphene_django/templates/graphene/base.html @@ -6,7 +6,7 @@ - {% if 'cdn' == TEMPLATE_SOURCE %} - - - - - - {% endif %} - - {% if 'static' == TEMPLATE_SOURCE %} - - - - - - {% endif %} - + + + + + {% block title %}{% endblock %} diff --git a/graphene_django/templates/graphene/graphiql.html b/graphene_django/templates/graphene/graphiql.html index 9d3ebf6..2533dfa 100755 --- a/graphene_django/templates/graphene/graphiql.html +++ b/graphene_django/templates/graphene/graphiql.html @@ -6,6 +6,7 @@ {% block additional_headers %}{{ auth_header }}{% endblock %} {% block content %} +
{% csrf_token %} {% endblock %} diff --git a/graphene_django/views.py b/graphene_django/views.py index 05d5706..bd4d847 100644 --- a/graphene_django/views.py +++ b/graphene_django/views.py @@ -18,7 +18,7 @@ from graphql.execution import ExecutionResult from graphql.type.schema import GraphQLSchema from graphene_django.settings import graphene_settings -from graphene_django.forms.forms import HeaderForm + class HttpError(Exception): def __init__(self, response, message=None, *args, **kwargs): @@ -97,7 +97,7 @@ class GraphQLView(APIView): assert isinstance( self.schema, GraphQLSchema ), "A Schema is required to be provided to GraphQLView." - assert not all((graphiql, batch)), "Use either graphiql or batch processing" + assert not all((graphiql_headers, graphiql, batch)), "Use either graphiql, graphiql_headers, or batch processing" # noinspection PyUnusedLocal def get_root_value(self, request): @@ -114,9 +114,18 @@ class GraphQLView(APIView): @method_decorator(ensure_csrf_cookie) def dispatch(self, request, *args, **kwargs): - GET_FROM_CDN = kwargs.get('GET_FROM_CDN', None) - if GET_FROM_CDN is None: - GET_FROM_CDN = 'static' # this is diconnected + # if specified in settings.py: + # GRAPHENE = { + # why does this not make it???? + # 'SOURCE': 'cdn' + # } + try: + GET_FROM_CDN = graphene_settings.SOURCE # get IF it exists + if GET_FROM_CDN is None: + # should not need + GET_FROM_CDN = 'static' + except: + GET_FROM_CDN = 'static' # this is diconnected by default graphiql_arguments = {} if GET_FROM_CDN == 'cdn': @@ -128,7 +137,7 @@ class GraphQLView(APIView): graphiql_arguments.update({'graphiql_template': 'graphene/graphiql.html'}) graphiql_arguments.update({'TEMPLATE_SOURCE': 'static'}) else: - print('Unsuppored option in setting. Choose or ') + print('The option %s is unsuppored option in setting. Choose or ' % GET_FROM_CDN) try: if request.method.lower() not in ("get", "post"): @@ -386,6 +395,8 @@ class GraphQLView(APIView): return content_type.split(";", 1)[0].lower() def _get_auth_header(iQLView, request, graphiql_arguments): + from libs.graphene_django_auth.forms import HeaderForm + # If this is a POST request then process the Form data if request.method == 'POST': @@ -396,7 +407,7 @@ def _get_auth_header(iQLView, request, graphiql_arguments): if form.is_valid(): # process the data in form.cleaned_data as required (here we just write it to the model due_back field) auth_header = form.cleaned_data['headers'] - + # return extra stuff to put in META tag for graphiql: request.session['HTTP_AUTHORIZATION'] = auth_header request.session['use_graphiql'] = True