Skip to content

Fixes for Django 2.0 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
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
40 changes: 40 additions & 0 deletions eoxs_allauth/adapter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#-------------------------------------------------------------------------------
#
# Project: EOxServer - django-allauth integration.
# Authors: Fabian Schindler <[email protected]>
#
#-------------------------------------------------------------------------------
# Copyright (C) 2020 EOX IT Services GmbH
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies of this Software or works derived from this Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#-------------------------------------------------------------------------------
# pylint: disable=missing-docstring, unused-argument

from allauth.account.adapter import DefaultAccountAdapter


class NoNewUsersAccountAdapter(DefaultAccountAdapter):
def is_open_for_signup(self, request):
"""
Checks whether or not the site is open for signups.
Next to simply returning True/False you can also intervene the
regular flow by raising an ImmediateHttpResponse
(Comment reproduced from the overridden method.)
"""
return False
20 changes: 4 additions & 16 deletions eoxs_allauth/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@

from django.apps import AppConfig
from django.db.models.signals import post_migrate
from django.contrib.auth.models import User
from .models import UserProfile
from . import signals # needed to initialize signal receivers
from allauth.account.adapter import DefaultAccountAdapter
from . import signals # needed to initialize signal receivers


class EOxServerAllauthConfig(AppConfig):
Expand All @@ -41,20 +38,11 @@ class EOxServerAllauthConfig(AppConfig):
def ready(self):

def create_profiles(sender, **kwargs):
from django.contrib.auth.models import User
from .models import UserProfile

if sender.name == self.name:
for user in User.objects.all():
UserProfile.objects.get_or_create(user=user)

post_migrate.connect(create_profiles, sender=self)



class NoNewUsersAccountAdapter(DefaultAccountAdapter):
def is_open_for_signup(self, request):
"""
Checks whether or not the site is open for signups.
Next to simply returning True/False you can also intervene the
regular flow by raising an ImmediateHttpResponse
(Comment reproduced from the overridden method.)
"""
return False
69 changes: 69 additions & 0 deletions eoxs_allauth/management/commands/_common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#-------------------------------------------------------------------------------
#
# Common command utilities.
#
# Authors: Martin Paces <[email protected]>
#-------------------------------------------------------------------------------
# Copyright (C) 2019 EOX IT Services GmbH
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies of this Software or works derived from this Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#-------------------------------------------------------------------------------
# pylint: disable=missing-docstring, too-few-public-methods

import sys
from logging import INFO, WARNING, ERROR

_LABEL2LOGLEVEL = {
"INFO": INFO,
"WARNING": WARNING,
"ERROR": ERROR,
}


JSON_OPTS = {
'sort_keys': False,
'indent': 2,
'separators': (',', ': '),
}


def datetime_to_string(dtobj):
""" datetime.datetime to string conversion. """
return dtobj if dtobj is None else dtobj.isoformat('T')


class ConsoleOutput():
logger = None
@classmethod
def info(cls, message, *args, **kwargs):
cls.print_message("INFO", message, *args, **kwargs)

@classmethod
def warning(cls, message, *args, **kwargs):
cls.print_message("WARNING", message, *args, **kwargs)

@classmethod
def error(cls, message, *args, **kwargs):
cls.print_message("ERROR", message, *args, **kwargs)

@classmethod
def print_message(cls, label, message, *args, **kwargs):
print("%s: %s" % (label, message % args), file=sys.stderr)
if kwargs.get('log') and cls.logger:
cls.logger.log(_LABEL2LOGLEVEL[label], message, *args)
17 changes: 7 additions & 10 deletions eoxs_allauth/management/commands/auth_export_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,15 @@
import json
from functools import partial
from collections import OrderedDict
from optparse import make_option
from django.core.management.base import BaseCommand
from django.contrib.auth.models import User
from eoxserver.resources.coverages.management.commands import (
CommandOutputMixIn,
)
from ._common import ConsoleOutput
from ...models import UserProfile

JSON_OPTS = {'sort_keys': False, 'indent': 2, 'separators': (',', ': ')}


class Command(CommandOutputMixIn, BaseCommand):
class Command(ConsoleOutput, BaseCommand):
args = "<username> [<username> ...]"
help = (
"Print information about the AllAuth users. The users are selected "
Expand All @@ -52,14 +49,14 @@ class Command(CommandOutputMixIn, BaseCommand):
"user can be obtained by '--info' option. The '--json' option produces "
"full user profile dump in JSON format."
)
option_list = BaseCommand.option_list + (
make_option(

def add_arguments(self, parser):
parser.add_argument(
"-f", "--file-name", dest="file", default="-", help=(
"Optional file-name the output is written to. "
"By default it is written to the standard output."
)
),
)
)

def handle(self, *args, **kwargs):
query = User.objects
Expand All @@ -72,7 +69,7 @@ def handle(self, *args, **kwargs):
data = [serialize_user(user) for user in query]

filename = kwargs["file"]
with (sys.stdout if filename == "-" else open(filename, "wb")) as file_:
with (sys.stdout if filename == "-" else open(filename, "w")) as file_:
json.dump(data, file_, **JSON_OPTS)


Expand Down
Loading