diff --git a/equipment/admin.py b/equipment/admin.py index cd665f5..e5ae718 100644 --- a/equipment/admin.py +++ b/equipment/admin.py @@ -1,10 +1,28 @@ from django.contrib import admin +from django import forms + from .models import Equipment, EquipmentRemark +from .fields import IdField, IdWidget + +class IdForm(forms.ModelForm): + def __init__(self, *args, **kwargs): + print("looooooooooooooooooooool") + if 'min_value' in kwargs: + kwargs.pop('min_value') + super(IdForm, self).__init__(*args, **kwargs) + + for field in self.instance._meta.fields: + if isinstance(field, IdField): + self.fields[field.name].choices = list(range(1, 12)) + self.fields[field.name].widget = IdWidget() + print(self.fields[field.name].choices) + print(self.fields.values()) class EquipmentRemarkExtraInline(admin.TabularInline): model = EquipmentRemark extra = 0 + form = IdForm class EquipmentAdmin(admin.ModelAdmin): @@ -14,3 +32,4 @@ class EquipmentAdmin(admin.ModelAdmin): admin.site.register(Equipment, EquipmentAdmin) + diff --git a/equipment/fields.py b/equipment/fields.py new file mode 100644 index 0000000..a73e156 --- /dev/null +++ b/equipment/fields.py @@ -0,0 +1,86 @@ +from django.db import models +from django import forms + + +#class IdWidget(AdminMultipleChoiceFieldWidget): +class IdWidget(forms.widgets.CheckboxSelectMultiple): + # template_name = 'equipment/widgets/checkbox_select.html' + # option_template_name = 'equipment/widgets/checkbox_option.html' + def __init__(self, *args, **kwargs): + print("lol1") # DELETE ME !!! + # nb_items = kwargs.pop('nb_items') + # kwargs['choices'] = list(range(1, nb_items+1)) + super(IdWidget, self).__init__(*args, **kwargs) + + # class Media: + # css = { + # 'all': ('css/idwidget.css',) + # } + +class IdFormField(forms.MultipleChoiceField): + #widget = IdWidget + + def __init__(self, *args, **kwargs): + print("lol2") # DELETE ME !!! + if 'min_value' in kwargs: + kwargs.pop('min_value') + if 'max_value' in kwargs: + kwargs.pop('max_value') + super(IdFormField, self).__init__(*args, **kwargs) + +class IdField(models.BigIntegerField): + def parse_integer(self, n): + print("lol3") # DELETE ME !!! + res = [] + k = 1 + while(n > 0): + if n & 1: + res.append(k) + n >>= 1 + k += 1 + print(res) + return res + + def from_db_value(self, value, expression, connection, context): + print("lol4") # DELETE ME !!! + if value is None: + return value + return self.parse_integer(value) + + def to_python(self, value): + print("lol5") # DELETE ME !!! + if isinstance(value, List): + return value + + if value is None: + return value + + return self.parse_integer(value) + + def get_prep_value(self, value): + print("lol6") # DELETE ME !!! + res = 0 + for b in value: + res |= 1 << (int(b)-1) + return res + + def __init__(self, separator=",", *args, **kwargs): + print("lol7") # DELETE ME !!! + self.separator = separator + super(IdField, self).__init__(*args, **kwargs) + + def deconstruct(self): + print("lol8") # DELETE ME !!! + name, path, args, kwargs = super(IdField, self).deconstruct() + # Only include kwarg if it's not the default + if self.separator != ",": + kwargs['separator'] = self.separator + return name, path, args, kwargs + + def formfield(self, **kwargs): + print("lol10") # DELETE ME !!! + # This is a fairly standard way to set up some defaults + # while letting the caller override them. + defaults = {'form_class': IdFormField} + defaults.update(kwargs) + return super(IdField, self).formfield(**defaults) diff --git a/equipment/migrations/0004_auto_20180802_1554.py b/equipment/migrations/0004_auto_20180802_1554.py new file mode 100644 index 0000000..0036343 --- /dev/null +++ b/equipment/migrations/0004_auto_20180802_1554.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.14 on 2018-08-02 15:54 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('equipment', '0003_auto_20180713_1358'), + ] + + operations = [ + migrations.AlterField( + model_name='equipmentattribution', + name='amount', + field=models.BigIntegerField(verbose_name='quantité attribuée'), + ), + ] diff --git a/equipment/models.py b/equipment/models.py index 5e91386..8fa8a59 100644 --- a/equipment/models.py +++ b/equipment/models.py @@ -3,6 +3,8 @@ from django.core.exceptions import ValidationError from django.utils.translation import ugettext_lazy as _ from event.models import Activity, EventSpecificMixin +from .fields import IdField + from taggit.managers import TaggableManager @@ -29,13 +31,10 @@ class Equipment(EventSpecificMixin, models.Model): return self.name -class IdField(models.PositiveIntegerField): - pass - class EquipmentAttribution(models.Model): equipment = models.ForeignKey(Equipment) activity = models.ForeignKey(Activity) - amount = models.PositiveSmallIntegerField(_("quantité attribuée")) + amount = models.BigIntegerField(_("quantité attribuée")) remarks = models.TextField(_("remarques concernant l'attribution")) class Meta: diff --git a/equipment/templates/equipment/widgets/checkbox_option.html b/equipment/templates/equipment/widgets/checkbox_option.html new file mode 100644 index 0000000..bb9acba --- /dev/null +++ b/equipment/templates/equipment/widgets/checkbox_option.html @@ -0,0 +1 @@ +{% include "django/forms/widgets/input_option.html" %} diff --git a/equipment/templates/equipment/widgets/checkbox_option.html.new b/equipment/templates/equipment/widgets/checkbox_option.html.new new file mode 100644 index 0000000..5b7f08b --- /dev/null +++ b/equipment/templates/equipment/widgets/checkbox_option.html.new @@ -0,0 +1 @@ +{% include "django/forms/widgets/input.html" %} diff --git a/equipment/templates/equipment/widgets/checkbox_select.html b/equipment/templates/equipment/widgets/checkbox_select.html new file mode 100644 index 0000000..780899a --- /dev/null +++ b/equipment/templates/equipment/widgets/checkbox_select.html @@ -0,0 +1 @@ +{% include "django/forms/widgets/multiple_input.html" %} diff --git a/equipment/templates/equipment/widgets/checkbox_select.html.new b/equipment/templates/equipment/widgets/checkbox_select.html.new new file mode 100644 index 0000000..a0d3c6d --- /dev/null +++ b/equipment/templates/equipment/widgets/checkbox_select.html.new @@ -0,0 +1,5 @@ +{% with id=widget.attrs.id %}
{% endwith %} diff --git a/equipment/templates/equipment/widgets/static/css/idwidget.css b/equipment/templates/equipment/widgets/static/css/idwidget.css new file mode 100644 index 0000000..33cafda --- /dev/null +++ b/equipment/templates/equipment/widgets/static/css/idwidget.css @@ -0,0 +1,12 @@ +.nice_select input[type="checkbox"] { + display: none; +} + +.nice_select input[type="checkbox"]:checked + label { + background: red; + color:white; +} + +.nice_select ul { + display: inline-block; +} diff --git a/evenementiel/settings/common.py b/evenementiel/settings/common.py index 5c7025f..35ddec0 100644 --- a/evenementiel/settings/common.py +++ b/evenementiel/settings/common.py @@ -10,6 +10,8 @@ We also load the secrets in this file. import os from . import secret +from django.core.urlresolvers import reverse_lazy +from django.contrib import messages def import_secret(name): @@ -50,6 +52,7 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'django.contrib.sites', 'channels', 'rest_framework', @@ -57,6 +60,13 @@ INSTALLED_APPS = [ 'widget_tweaks', 'taggit', + 'allauth_ens', + 'allauth', + 'allauth.account', + 'allauth.socialaccount', + 'allauth_cas', + + 'api', 'communication', 'equipment', @@ -160,3 +170,33 @@ USE_I18N = True USE_L10N = True USE_TZ = True + +SITE_ID = 1 + +CAS_SERVER_URL = "https://cas.eleves.ens.fr/" #SPI CAS +CAS_VERIFY_URL = "https://cas.eleves.ens.fr/" +CAS_IGNORE_REFERER = True +CAS_REDIRECT_URL = reverse_lazy('shared:home') +CAS_EMAIL_FORMAT = "%s@clipper.ens.fr" +CAS_FORCE_CHANGE_USERNAME_CASE = "lower" +CAS_VERSION = 'CAS_2_SAML_1_0' + +LOGIN_URL = reverse_lazy('login') +LOGOUT_URL = reverse_lazy('logout') +LOGIN_REDIRECT_URL = reverse_lazy('shared:home') +ACCOUNT_HOME_URL = reverse_lazy('shared:home') +ACCOUNT_DETAILS_URL = reverse_lazy('shared:home') + +SOCIALACCOUNT_PROVIDERS = { + # … + + 'clipper': { + + # These settings control whether a message containing a link to + # disconnect from the CAS server is added when users log out. + 'MESSAGE_SUGGEST_LOGOUT_ON_LOGOUT': True, + 'MESSAGE_SUGGEST_LOGOUT_ON_LOGOUT_LEVEL': messages.INFO, + + }, +} + diff --git a/evenementiel/urls.py b/evenementiel/urls.py index ad68e7a..0812f16 100644 --- a/evenementiel/urls.py +++ b/evenementiel/urls.py @@ -5,7 +5,15 @@ from django.conf import settings from django.conf.urls import url, include from django.contrib import admin +#from django_cas_ng import views as django_cas_views +from allauth_ens.views import capture_login, capture_logout + + urlpatterns = [ + url(r'^compte/', include('allauth.urls')), + + url(r'^login/$', capture_login, name="login"), + url(r'^logout/$', capture_logout, name="logout"), url(r'^admin/', admin.site.urls), url(r'^event/', include('event.urls')), url(r'^user/', include('users.urls')), diff --git a/requirements.txt b/requirements.txt index f3bd984..1ca1486 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,5 +12,7 @@ django-notifications django-contrib-comments django-taggit +git+https://git.eleves.ens.fr/cof-geek/django-allauth-ens@6e77b31e0dfed7659776d + # Production specific daphne==1.3.0