caca
This commit is contained in:
parent
123d524eab
commit
0be9e5eb3a
12 changed files with 198 additions and 4 deletions
|
@ -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)
|
||||
|
||||
|
|
86
equipment/fields.py
Normal file
86
equipment/fields.py
Normal file
|
@ -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)
|
20
equipment/migrations/0004_auto_20180802_1554.py
Normal file
20
equipment/migrations/0004_auto_20180802_1554.py
Normal file
|
@ -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'),
|
||||
),
|
||||
]
|
|
@ -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:
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{% include "django/forms/widgets/input_option.html" %}
|
|
@ -0,0 +1 @@
|
|||
{% include "django/forms/widgets/input.html" %}<label{% if widget.attrs.id %} for="{{ widget.attrs.id }}"{% endif %}>{{ widget.label }}</label>
|
|
@ -0,0 +1 @@
|
|||
{% include "django/forms/widgets/multiple_input.html" %}
|
|
@ -0,0 +1,5 @@
|
|||
{% with id=widget.attrs.id %}<ul{% if id %} id="{{ id }}"{% endif %}{% if widget.attrs.class %} class="{{ widget.attrs.class }} nice_select"{% endif %}>{% for group, options, index in widget.optgroups %}{% if group %}
|
||||
<li>{{ group }}<ul{% if id %} id="{{ id }}_{{ index }}"{% endif %}>{% endif %}{% for option in options %}
|
||||
<li>{% include option.template_name with widget=option %}</li>{% endfor %}{% if group %}
|
||||
</ul></li>{% endif %}{% endfor %}
|
||||
</ul>{% endwith %}
|
|
@ -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;
|
||||
}
|
|
@ -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,
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -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')),
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue