Compare commits

..

No commits in common. "f2c1a76a1bffe9c42b63e0bb7a0900552b867f5c" and "7c1cd322ed8e8e55ca8a1e9ad9ea25d9945dc184" have entirely different histories.

8 changed files with 21 additions and 33 deletions

View File

@ -1,15 +1,8 @@
Changelog Changelog
========= =========
0.7.1
-----
* Fix login view
* Fix initial roles in user form
0.7 0.7
--- ---
* Enhance sidebar menu * Enhance sidebar menu
* Use all css files on login template * Use all css files on login template
* Make user admin section optional * Make user admin section optional

View File

@ -1,5 +1,6 @@
from django.apps import AppConfig from django.apps import AppConfig
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.db.models.signals import post_migrate
class GASConfig(AppConfig): class GASConfig(AppConfig):

View File

@ -25,7 +25,6 @@ class UserForm(forms.ModelForm):
label=_('roles'), label=_('roles'),
required=False, required=False,
) )
class Meta: class Meta:
model = User model = User
fields = ( fields = (
@ -34,8 +33,8 @@ class UserForm(forms.ModelForm):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
if self.instance.pk is not None: if 'roles' not in self.initial and self.instance.pk is not None:
self.initial['roles'] = list(self.instance.user_roles.values_list('role', flat=True)) self.initial['roles'] = self.instance.user_roles.values_list('role', flat=True)
def save(self, commit=True): def save(self, commit=True):
obj = super().save(commit=False) obj = super().save(commit=False)

View File

@ -6,30 +6,14 @@ from django.views.generic import TemplateView
from gas.views import GASMixin from gas.views import GASMixin
from gas import gas_settings
class GASLoginView(GASMixin, LoginView):
class GASLoginView(LoginView):
template_name = "gas/login.html" template_name = "gas/login.html"
def get_success_url(self): def get_success_url(self):
url = self.get_redirect_url() url = self.get_redirect_url()
return url or resolve_url('gas:index') return url or resolve_url('gas:index')
def get_context_data(self, **kwargs):
ctx = super().get_context_data(**kwargs)
css = gas_settings.MEDIA['css']
js = gas_settings.MEDIA['js']
if gas_settings.EXTRA_MEDIA:
css = css + gas_settings.EXTRA_MEDIA.get('css', [])
js = js + gas_settings.EXTRA_MEDIA.get('js', [])
ctx.update({
'logo_static_url': gas_settings.LOGO,
'css': css,
'js': js,
})
return ctx
class GASPasswordChangeView(GASMixin, PasswordChangeView): class GASPasswordChangeView(GASMixin, PasswordChangeView):
template_name = 'gas/base_form.html' template_name = 'gas/base_form.html'
@ -37,7 +21,6 @@ class GASPasswordChangeView(GASMixin, PasswordChangeView):
title = _('Change your password') title = _('Change your password')
success_message = _('Password changed.') success_message = _('Password changed.')
class Index(GASMixin, TemplateView): class Index(GASMixin, TemplateView):
main_menu = 'index' main_menu = 'index'
template_name = "gas/index.html" template_name = "gas/index.html"

View File

@ -1,6 +1,9 @@
from collections import namedtuple
from django.urls import include, re_path from django.urls import include, re_path
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.utils.module_loading import autodiscover_modules from django.utils.module_loading import autodiscover_modules
from django.utils.translation import gettext_lazy as _
class Entry: class Entry:

View File

@ -148,7 +148,13 @@ class SiteTestCase(TestCase):
class SampleAppIntegrationTest(TestCase): class SampleAppIntegrationTest(TestCase):
def test_gas_autodiscover(self): def test_gas_autodiscover(self):
# urls registered # urls registered
reverse('gas:index') reverse('gas:user_list')
# menu registered
self.assertIn(
'users',
site._registry['menu'],
)
# role registered # role registered
self.assertIn( self.assertIn(

View File

@ -1,10 +1,11 @@
import datetime
import json import json
from django.contrib import messages from django.contrib import messages
from django.contrib.admin.utils import NestedObjects from django.contrib.admin.utils import NestedObjects
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.db import router from django.db import router
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseBadRequest from django.http import HttpResponse, HttpResponseRedirect, HttpResponseBadRequest, HttpResponseNotAllowed
from django.urls import reverse from django.urls import reverse
from django.utils.encoding import force_text from django.utils.encoding import force_text
from django.utils.html import escape, escapejs from django.utils.html import escape, escapejs
@ -12,7 +13,9 @@ from django.utils.text import capfirst
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views.generic import ListView, CreateView, UpdateView, DeleteView from django.views.generic import ListView, CreateView, UpdateView, DeleteView
from . import forms
from . import gas_settings from . import gas_settings
from .sites import site
class AjaxCommandsMixin: class AjaxCommandsMixin:
@ -49,8 +52,8 @@ class GASMixin:
roles.add(self.base_role) roles.add(self.base_role)
access_denied = ( access_denied = (
not user.is_authenticated or ( not user.is_authenticated or (
not user.is_superuser not user.is_superuser
and user.user_roles.filter(role__in=roles).count() == 0 and user.user_roles.filter(role__in=roles).count() == 0
) )
) )
if access_denied: if access_denied:

View File

@ -1,6 +1,6 @@
[metadata] [metadata]
name = django-gas name = django-gas
version = 0.7.1 version = 0.7
description = An alternative to django admin description = An alternative to django admin
long_description = file: readme.md, changelog.md long_description = file: readme.md, changelog.md
long_description_content_type = text/markdown long_description_content_type = text/markdown