Fix deprecation warnings
This commit is contained in:
parent
b3588b5e6c
commit
0f18e59d67
6 changed files with 67 additions and 75 deletions
|
@ -24,10 +24,11 @@ SITE_NAME = basename(DJANGO_ROOT)
|
|||
|
||||
# ######### END PATH CONFIGURATION
|
||||
|
||||
GVA_ENVIRONMENT = get_env_variable("GVA_ENVIRONMENT", default="prod")
|
||||
|
||||
# ######### DEBUG CONFIGURATION
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
|
||||
DEBUG = False
|
||||
DEBUG = (GVA_ENVIRONMENT == "local")
|
||||
# ######### END DEBUG CONFIGURATION
|
||||
|
||||
|
||||
|
@ -351,8 +352,6 @@ GVA_LINK_PHPPGADMIN = get_env_variable(
|
|||
)
|
||||
# ######### END CUSTOM APP CONFIGURATION
|
||||
|
||||
GVA_ENVIRONMENT = get_env_variable("GVA_ENVIRONMENT", default="prod")
|
||||
|
||||
# ######### STATIC FILE CONFIGURATION
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-root
|
||||
STATIC_ROOT = "/srv/gva/static/"
|
||||
|
@ -362,11 +361,19 @@ def show_debug_toolbar(request):
|
|||
return DEBUG and GVA_ENVIRONMENT == "local"
|
||||
|
||||
|
||||
if GVA_ENVIRONMENT == "local":
|
||||
# ######### DEBUG CONFIGURATION
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
|
||||
DEBUG = True
|
||||
# ######### TOOLBAR CONFIGURATION
|
||||
# See: http://django-debug-toolbar.readthedocs.org/en/latest/installation.html#explicit-setup # noqa
|
||||
INSTALLED_APPS += ("debug_toolbar",)
|
||||
|
||||
MIDDLEWARE += ["debug_toolbar.middleware.DebugToolbarMiddleware"]
|
||||
|
||||
DEBUG_TOOLBAR_CONFIG = {
|
||||
"SHOW_TOOLBAR_CALLBACK": "gnuviechadmin.settings.show_debug_toolbar"
|
||||
}
|
||||
# ######### END TOOLBAR CONFIGURATION
|
||||
|
||||
|
||||
if GVA_ENVIRONMENT == "local":
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug
|
||||
TEMPLATES[0]["OPTIONS"]["debug"] = DEBUG
|
||||
# ######### END DEBUG CONFIGURATION
|
||||
|
@ -381,12 +388,6 @@ if GVA_ENVIRONMENT == "local":
|
|||
CACHES = {"default": {"BACKEND": "django.core.cache.backends.locmem.LocMemCache"}}
|
||||
# ######### END CACHE CONFIGURATION
|
||||
|
||||
# ######### TOOLBAR CONFIGURATION
|
||||
# See: http://django-debug-toolbar.readthedocs.org/en/latest/installation.html#explicit-setup # noqa
|
||||
INSTALLED_APPS += ("debug_toolbar",)
|
||||
|
||||
MIDDLEWARE += ["debug_toolbar.middleware.DebugToolbarMiddleware"]
|
||||
|
||||
LOGGING["handlers"].update(
|
||||
{
|
||||
"console": {
|
||||
|
@ -419,13 +420,6 @@ if GVA_ENVIRONMENT == "local":
|
|||
]
|
||||
)
|
||||
)
|
||||
|
||||
DEBUG_TOOLBAR_PATCH_SETTINGS = False
|
||||
DEBUG_TOOLBAR_CONFIG = {
|
||||
"SHOW_TOOLBAR_CALLBACK": "gnuviechadmin.settings.show_debug_toolbar"
|
||||
}
|
||||
|
||||
# ######### END TOOLBAR CONFIGURATION
|
||||
elif GVA_ENVIRONMENT == "test":
|
||||
ALLOWED_HOSTS = ["localhost"]
|
||||
PASSWORD_HASHERS = ("django.contrib.auth.hashers.MD5PasswordHasher",)
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import debug_toolbar
|
||||
from django.conf.urls import include, url
|
||||
from django.conf import settings
|
||||
|
||||
from django.contrib import admin
|
||||
from django.contrib.flatpages import views
|
||||
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
||||
from django.urls import path
|
||||
|
||||
admin.autodiscover()
|
||||
|
||||
|
@ -28,9 +28,7 @@ urlpatterns = [
|
|||
# Uncomment the next line to serve media files in dev.
|
||||
# urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
|
||||
if settings.DEBUG: # pragma: no cover
|
||||
import debug_toolbar
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^__debug__/', include(debug_toolbar.urls)),
|
||||
] + staticfiles_urlpatterns() + urlpatterns
|
||||
urlpatterns += staticfiles_urlpatterns()
|
||||
urlpatterns += [
|
||||
path('__debug__/', include(debug_toolbar.urls)),
|
||||
]
|
||||
|
|
|
@ -7,24 +7,20 @@ from __future__ import unicode_literals
|
|||
from django.db import models
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from passlib.hash import sha512_crypt
|
||||
from model_utils.models import TimeStampedModel
|
||||
from passlib.hash import sha512_crypt
|
||||
|
||||
from domains.models import MailDomain
|
||||
from fileservertasks.tasks import create_file_mailbox, delete_file_mailbox
|
||||
from osusers.models import User as OsUser
|
||||
|
||||
from fileservertasks.tasks import (
|
||||
create_file_mailbox,
|
||||
delete_file_mailbox,
|
||||
)
|
||||
|
||||
|
||||
class ActivateAbleMixin(models.Model):
|
||||
"""
|
||||
Mixin for model classes that can be active or inactive.
|
||||
|
||||
"""
|
||||
|
||||
active = models.BooleanField(default=True)
|
||||
|
||||
class Meta:
|
||||
|
@ -51,10 +47,8 @@ class MailboxManager(models.Manager):
|
|||
mailboxformat = "{0}p{1:02d}"
|
||||
mailboxname = mailboxformat.format(osuser.username, count)
|
||||
|
||||
for box in self.values('username').filter(osuser=osuser).order_by(
|
||||
'username'
|
||||
):
|
||||
if box['username'] == mailboxname:
|
||||
for box in self.values("username").filter(osuser=osuser).order_by("username"):
|
||||
if box["username"] == mailboxname:
|
||||
count += 1
|
||||
mailboxname = mailboxformat.format(osuser.username, count)
|
||||
else:
|
||||
|
@ -69,9 +63,10 @@ class MailboxManager(models.Manager):
|
|||
|
||||
"""
|
||||
return self.filter(
|
||||
models.Q(mailaddressmailbox__isnull=True) |
|
||||
models.Q(mailaddressmailbox__mailaddress=mailaddress),
|
||||
active=True, osuser=osuser,
|
||||
models.Q(mailaddressmailbox__isnull=True)
|
||||
| models.Q(mailaddressmailbox__mailaddress=mailaddress),
|
||||
active=True,
|
||||
osuser=osuser,
|
||||
)
|
||||
|
||||
def unused(self, osuser):
|
||||
|
@ -82,7 +77,8 @@ class MailboxManager(models.Manager):
|
|||
"""
|
||||
return self.filter(
|
||||
mailaddressmailbox__isnull=True,
|
||||
active=True, osuser=osuser,
|
||||
active=True,
|
||||
osuser=osuser,
|
||||
)
|
||||
|
||||
def create_mailbox(self, osuser, password=None, commit=True):
|
||||
|
@ -97,7 +93,8 @@ class MailboxManager(models.Manager):
|
|||
|
||||
"""
|
||||
mailbox = self.create(
|
||||
osuser=osuser, username=self.get_next_mailbox_name(osuser))
|
||||
osuser=osuser, username=self.get_next_mailbox_name(osuser)
|
||||
)
|
||||
if password is not None:
|
||||
mailbox.set_password(password)
|
||||
return mailbox
|
||||
|
@ -109,6 +106,7 @@ class Mailbox(ActivateAbleMixin, TimeStampedModel):
|
|||
This is the model class for a mailbox.
|
||||
|
||||
"""
|
||||
|
||||
osuser = models.ForeignKey(OsUser, on_delete=models.CASCADE)
|
||||
username = models.CharField(max_length=128, unique=True)
|
||||
password = models.CharField(max_length=255)
|
||||
|
@ -116,9 +114,9 @@ class Mailbox(ActivateAbleMixin, TimeStampedModel):
|
|||
objects = MailboxManager()
|
||||
|
||||
class Meta:
|
||||
ordering = ['osuser', 'username']
|
||||
verbose_name = _('Mailbox')
|
||||
verbose_name_plural = _('Mailboxes')
|
||||
ordering = ["osuser", "username"]
|
||||
verbose_name = _("Mailbox")
|
||||
verbose_name_plural = _("Mailboxes")
|
||||
|
||||
def set_password(self, password):
|
||||
"""
|
||||
|
@ -127,7 +125,7 @@ class Mailbox(ActivateAbleMixin, TimeStampedModel):
|
|||
:param str password: the clear text password
|
||||
|
||||
"""
|
||||
self.password = sha512_crypt.encrypt(password)
|
||||
self.password = sha512_crypt.hash(password)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
# TODO: refactor to use signals
|
||||
|
@ -144,11 +142,9 @@ class Mailbox(ActivateAbleMixin, TimeStampedModel):
|
|||
Get a list of mail addresses assigned to this mailbox.
|
||||
|
||||
"""
|
||||
addrs = [
|
||||
mbadr.mailaddress for mbadr in
|
||||
self.mailaddressmailbox_set.all()
|
||||
]
|
||||
addrs = [mbadr.mailaddress for mbadr in self.mailaddressmailbox_set.all()]
|
||||
return addrs
|
||||
|
||||
mailaddresses = property(get_mailaddresses)
|
||||
|
||||
def __str__(self):
|
||||
|
@ -161,15 +157,17 @@ class MailAddress(ActivateAbleMixin, TimeStampedModel, models.Model):
|
|||
This is the model class for a mail address.
|
||||
|
||||
"""
|
||||
localpart = models.CharField(_('local part'), max_length=128)
|
||||
|
||||
localpart = models.CharField(_("local part"), max_length=128)
|
||||
domain = models.ForeignKey(
|
||||
MailDomain, verbose_name=_('domain'), on_delete=models.CASCADE)
|
||||
MailDomain, verbose_name=_("domain"), on_delete=models.CASCADE
|
||||
)
|
||||
|
||||
class Meta:
|
||||
ordering = ['domain', 'localpart']
|
||||
unique_together = ('localpart', 'domain')
|
||||
verbose_name = _('Mail address')
|
||||
verbose_name_plural = _('Mail addresses')
|
||||
ordering = ["domain", "localpart"]
|
||||
unique_together = ("localpart", "domain")
|
||||
verbose_name = _("Mail address")
|
||||
verbose_name_plural = _("Mail addresses")
|
||||
|
||||
def __str__(self):
|
||||
return "{0}@{1}".format(self.localpart, self.domain)
|
||||
|
@ -220,8 +218,7 @@ class MailAddress(ActivateAbleMixin, TimeStampedModel, models.Model):
|
|||
if MailAddressMailbox.objects.filter(mailaddress=self).exists():
|
||||
mabox = MailAddressMailbox.objects.get(mailaddress=self)
|
||||
mabox.delete()
|
||||
forwards = MailAddressForward.objects.filter(
|
||||
mailaddress=self).all()
|
||||
forwards = MailAddressForward.objects.filter(mailaddress=self).all()
|
||||
for item in forwards:
|
||||
if item.target not in addresses:
|
||||
item.delete()
|
||||
|
@ -250,14 +247,19 @@ class MailAddressMailbox(TimeStampedModel, models.Model):
|
|||
This is the model class to assign a mail address to a mailbox.
|
||||
|
||||
"""
|
||||
|
||||
mailaddress = models.OneToOneField(
|
||||
MailAddress, verbose_name=_('mailaddress'), primary_key=True,
|
||||
on_delete=models.CASCADE)
|
||||
MailAddress,
|
||||
verbose_name=_("mailaddress"),
|
||||
primary_key=True,
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
mailbox = models.ForeignKey(
|
||||
Mailbox, verbose_name=_('mailbox'), on_delete=models.CASCADE)
|
||||
Mailbox, verbose_name=_("mailbox"), on_delete=models.CASCADE
|
||||
)
|
||||
|
||||
class Meta:
|
||||
unique_together = ('mailaddress', 'mailbox')
|
||||
unique_together = ("mailaddress", "mailbox")
|
||||
|
||||
def __str__(self):
|
||||
return self.mailbox.username
|
||||
|
@ -268,8 +270,9 @@ class MailAddressForward(TimeStampedModel, models.Model):
|
|||
This is a model class to map mail addresses to forwarding addresses.
|
||||
|
||||
"""
|
||||
|
||||
mailaddress = models.ForeignKey(MailAddress, on_delete=models.CASCADE)
|
||||
target = models.EmailField(max_length=254)
|
||||
|
||||
class Meta:
|
||||
unique_together = ('mailaddress', 'target')
|
||||
unique_together = ("mailaddress", "target")
|
||||
|
|
|
@ -3,22 +3,19 @@ This module defines the database models of operating system users.
|
|||
|
||||
"""
|
||||
import base64
|
||||
from datetime import date
|
||||
import logging
|
||||
import os
|
||||
from datetime import date
|
||||
|
||||
from django.db import models, transaction
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import models, transaction
|
||||
from django.dispatch import Signal
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from model_utils.models import TimeStampedModel
|
||||
|
||||
from passlib.hash import sha512_crypt
|
||||
from passlib.utils import generate_password
|
||||
|
||||
from passlib.pwd import genword
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -150,7 +147,7 @@ class UserManager(models.Manager):
|
|||
|
||||
If username is None the result of :py:meth:`get_next_username` is used.
|
||||
If password is None a new password will be generated using passlib's
|
||||
:py:func:`generate_password`.
|
||||
:py:func:`genword`.
|
||||
|
||||
:param customer: Django User instance this user is associated to
|
||||
:param str username: the username or None
|
||||
|
@ -166,7 +163,7 @@ class UserManager(models.Manager):
|
|||
if username is None:
|
||||
username = self.get_next_username()
|
||||
if password is None:
|
||||
password = generate_password()
|
||||
password = genword(entropy=128)
|
||||
homedir = os.path.join(settings.OSUSER_HOME_BASEPATH, username)
|
||||
group = Group.objects.create(groupname=username, gid=gid)
|
||||
user = self.create(
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% load staticfiles i18n account %}<!DOCTYPE html>
|
||||
{% load static i18n account %}<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
"""
|
||||
This module defines Celery_ tasks to manage website configurations.
|
||||
This module defines Celery tasks to manage website configurations.
|
||||
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
|
Loading…
Reference in a new issue