Commit 43b709bf authored by Skia's avatar Skia
Browse files

Make file modale chooser and complete user profile

parent a8858fa7
Pipeline #110 failed with stage
in 1 minute and 52 seconds
......@@ -53,7 +53,7 @@
{% endif %}
<td>{{ o.remark }}</td>
{% if o.invoice %}
<td><a href="{{ url('core:download') + '?file=' + o.invoice.name }}">{{ o.invoice.name }}</a></td>
<td><a href="{{ url('core:download', file_id=o.invoice.id) }}">{{ o.invoice.name }}</a></td>
{% else %}
<td>-</td>
{% endif %}
......
......@@ -4,10 +4,9 @@ from django.shortcuts import render
from django.core.urlresolvers import reverse_lazy
from django.forms.models import modelform_factory
from django.forms import HiddenInput
from django.forms.extras.widgets import SelectDateWidget
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin
from core.views.forms import SelectFile
from core.views.forms import SelectFile, SelectDate
from accounting.models import BankAccount, ClubAccount, GeneralJournal, Operation, AccountingType, Company
# Accounting types
......@@ -168,7 +167,7 @@ class OperationCreateView(CanCreateMixin, CreateView):
form_class = modelform_factory(Operation,
fields=['amount', 'label', 'remark', 'journal', 'target_type', 'target_id', 'target_label', 'date', 'mode',
'cheque_number', 'invoice', 'accounting_type', 'done'],
widgets={'journal': HiddenInput, 'date': SelectDateWidget})
widgets={'journal': HiddenInput, 'date': SelectDate})
template_name = 'core/create.jinja'
def get_initial(self):
......@@ -188,7 +187,7 @@ class OperationEditView(CanEditMixin, UpdateView):
form_class = modelform_factory(Operation,
fields = ['amount', 'label', 'remark', 'target_type', 'target_id', 'target_label', 'date', 'mode', 'cheque_number',
'invoice', 'accounting_type', 'done'],
widgets={'date': SelectDateWidget, 'invoice': SelectFile})
widgets={'date': SelectDate, 'invoice': SelectFile})
template_name = 'core/edit.jinja'
# Company views
......
......@@ -38,6 +38,7 @@ class Command(BaseCommand):
is_superuser=True, is_staff=True)
root.set_password("plop")
root.save()
SithFile(parent=None, name="profiles", is_folder=True, owner=root).save()
home_root = SithFile(parent=None, name="users", is_folder=True, owner=root)
home_root.save()
club_root = SithFile(parent=None, name="clubs", is_folder=True, owner=root)
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0002_user_home'),
]
operations = [
migrations.AddField(
model_name='user',
name='avatar_pict',
field=models.OneToOneField(related_name='avatar_of', verbose_name='avatar', to='core.SithFile', null=True, blank=True),
),
migrations.AddField(
model_name='user',
name='profile_pict',
field=models.OneToOneField(related_name='profile_of', verbose_name='profile', to='core.SithFile', null=True, blank=True),
),
migrations.AddField(
model_name='user',
name='scrub_pict',
field=models.OneToOneField(related_name='scrub_of', verbose_name='scrub', to='core.SithFile', null=True, blank=True),
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0003_auto_20160810_1949'),
]
operations = [
migrations.AlterField(
model_name='user',
name='nick_name',
field=models.CharField(verbose_name='nick name', max_length=30, blank=True),
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import core.models
class Migration(migrations.Migration):
dependencies = [
('core', '0004_auto_20160811_0206'),
]
operations = [
migrations.AddField(
model_name='user',
name='department',
field=models.CharField(max_length=15, choices=[('TC', 'TC'), ('IMSI', 'IMSI'), ('IMAP', 'IMAP'), ('INFO', 'INFO'), ('GI', 'GI'), ('E', 'E'), ('EE', 'EE'), ('GESC', 'GESC'), ('GMC', 'GMC'), ('MC', 'MC'), ('EDIM', 'EDIM'), ('HUMAN', 'Humanities'), ('NA', 'N/A')], default='NA', verbose_name='department'),
),
migrations.AddField(
model_name='user',
name='dpt_option',
field=models.CharField(max_length=32, default='', verbose_name='dpt option'),
),
migrations.AddField(
model_name='user',
name='forum_signature',
field=models.TextField(max_length=256, default='', verbose_name='forum signature'),
),
migrations.AddField(
model_name='user',
name='promo',
field=models.IntegerField(blank=True, null=True, validators=[core.models.validate_promo], verbose_name='promo'),
),
migrations.AddField(
model_name='user',
name='quote',
field=models.CharField(max_length=64, default='', verbose_name='quote'),
),
migrations.AddField(
model_name='user',
name='role',
field=models.CharField(max_length=15, choices=[('STUDENT', 'Student'), ('ADMINISTRATIVE', 'Administrative agent'), ('TEACHER', 'Teacher'), ('AGENT', 'Agent'), ('DOCTOR', 'Doctor'), ('FORMER STUDENT', 'Former student'), ('SERVICE', 'Service')], default='STUDENT', verbose_name='role'),
),
migrations.AddField(
model_name='user',
name='school',
field=models.CharField(max_length=32, default='', verbose_name='school'),
),
migrations.AddField(
model_name='user',
name='semester',
field=models.CharField(max_length=5, default='', verbose_name='semester'),
),
migrations.AddField(
model_name='user',
name='sex',
field=models.CharField(max_length=10, choices=[('MAN', 'Man'), ('WOMAN', 'Woman')], default='MAN', verbose_name='sex'),
),
migrations.AddField(
model_name='user',
name='tshirt_size',
field=models.CharField(max_length=5, choices=[('-', '-'), ('XS', 'XS'), ('S', 'S'), ('M', 'M'), ('L', 'L'), ('XL', 'XL'), ('XXL', 'XXL'), ('XXXL', 'XXXL')], default='M', verbose_name='tshirt size'),
),
]
......@@ -7,7 +7,7 @@ from django.core.exceptions import ValidationError
from django.core.urlresolvers import reverse
from django.conf import settings
from django.db import transaction
from datetime import datetime, timedelta
from datetime import datetime, timedelta, date
import unicodedata
......@@ -46,6 +46,15 @@ class RealGroup(Group):
class Meta:
proxy = True
def validate_promo(value):
start_year = settings.SITH_SCHOOL_START_YEAR
delta = (date.today()+timedelta(days=180)).year - start_year
if value < 0 or delta < value:
raise ValidationError(
_('%(value)s is not a valid promo (between 0 and %(end)s)'),
params={'value': value, 'end': delta},
)
class User(AbstractBaseUser):
"""
Defines the base user class, useable in every app
......@@ -77,7 +86,7 @@ class User(AbstractBaseUser):
last_name = models.CharField(_('last name'), max_length=30)
email = models.EmailField(_('email address'), unique=True)
date_of_birth = models.DateField(_('date of birth'), blank=True, null=True)
nick_name = models.CharField(max_length=30, blank=True)
nick_name = models.CharField(_('nick name'), max_length=30, blank=True)
is_staff = models.BooleanField(
_('staff status'),
default=False,
......@@ -101,6 +110,51 @@ class User(AbstractBaseUser):
)
groups = models.ManyToManyField(RealGroup, related_name='users', blank=True)
home = models.OneToOneField('SithFile', related_name='home_of', verbose_name=_("home"), null=True, blank=True)
profile_pict = models.OneToOneField('SithFile', related_name='profile_of', verbose_name=_("profile"), null=True, blank=True)
avatar_pict = models.OneToOneField('SithFile', related_name='avatar_of', verbose_name=_("avatar"), null=True, blank=True)
scrub_pict = models.OneToOneField('SithFile', related_name='scrub_of', verbose_name=_("scrub"), null=True, blank=True)
sex = models.CharField(_("sex"), max_length=10, choices=[("MAN", _("Man")), ("WOMAN", _("Woman"))], default="MAN")
tshirt_size = models.CharField(_("tshirt size"), max_length=5, choices=[
("-", _("-")),
("XS", _("XS")),
("S", _("S")),
("M", _("M")),
("L", _("L")),
("XL", _("XL")),
("XXL", _("XXL")),
("XXXL", _("XXXL")),
], default="M")
role = models.CharField(_("role"), max_length=15, choices=[
("STUDENT", _("Student")),
("ADMINISTRATIVE", _("Administrative agent")),
("TEACHER", _("Teacher")),
("AGENT", _("Agent")),
("DOCTOR", _("Doctor")),
("FORMER STUDENT", _("Former student")),
("SERVICE", _("Service")),
], default="STUDENT")
department = models.CharField(_("department"), max_length=15, choices=[
("TC", _("TC")),
("IMSI", _("IMSI")),
("IMAP", _("IMAP")),
("INFO", _("INFO")),
("GI", _("GI")),
("E", _("E")),
("EE", _("EE")),
("GESC", _("GESC")),
("GMC", _("GMC")),
("MC", _("MC")),
("EDIM", _("EDIM")),
("HUMAN", _("Humanities")),
("NA", _("N/A")),
], default="NA")
dpt_option = models.CharField(_("dpt option"), max_length=32, default="")
semester = models.CharField(_("semester"), max_length=5, default="")
quote = models.CharField(_("quote"), max_length=64, default="")
school = models.CharField(_("school"), max_length=32, default="")
promo = models.IntegerField(_("promo"), validators=[validate_promo], null=True, blank=True)
forum_signature = models.TextField(_("forum signature"), max_length=256, default="")
# TODO: add phone numbers with https://github.com/stefanfoulis/django-phonenumber-field
objects = UserManager()
......@@ -341,6 +395,15 @@ class SithFile(models.Model):
def is_owned_by(self, user):
return user.id == self.owner.id
def can_be_viewed_by(self, user):
if hasattr(self, 'profile_of'):
return user.can_view(self.profile_of)
if hasattr(self, 'avatar_of'):
return user.can_view(self.avatar_of)
if hasattr(self, 'scrub_of'):
return user.can_view(self.scrub_of)
return False
def delete(self):
for c in self.children.all():
c.delete()
......@@ -422,6 +485,9 @@ class SithFile(models.Model):
def get_display_name(self):
return self.name
def get_download_url(self):
return reverse('core:download', kwargs={'file_id': self.id})
class LockError(Exception):
"""There was a lock error on the object"""
pass
......
......@@ -2,6 +2,11 @@
Super Form Reset
----------------------------------------------------------------------------------------------------*/
form {
margin: 0px auto;
width: 60%;
}
input,
label,
select,
......@@ -22,6 +27,10 @@ textarea
font-family: Arial;
}
label {
min-width: 50%;
}
/* Remove the stupid outer glow in Webkit */
input:focus
{
......@@ -70,7 +79,8 @@ input[type=tel],
input[type=text],
input[type=time],
input[type=url],
input[type=week]
input[type=week],
textarea
{
background-color: white;
border: 1px solid black;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment