Browse Source

Rend l'affichage des mails locaux plus intuitif

override_mails
Hugo LEVY-FALK 7 years ago
parent
commit
680b8a7ec7
  1. 8
      CHANGELOG.md
  2. 17
      static/js/email_address.js
  3. 11
      users/forms.py
  4. 30
      users/migrations/0074_auto_20180814_1059.py
  5. 20
      users/migrations/0076_auto_20180811_0425.py
  6. 9
      users/models.py
  7. 6
      users/templates/users/profil.html
  8. 3
      users/templates/users/user.html
  9. 4
      users/views.py

8
CHANGELOG.md

@ -128,3 +128,11 @@ You need to ensure that your database character set is utf-8.
```sql ```sql
ALTER DATABASE re2o CHARACTER SET utf8; ALTER DATABASE re2o CHARACTER SET utf8;
``` ```
## MR 247: Fix des comptes mails
Fix several issues with email accounts, you need to collect the static files.
```bash
./manage.py collectstatic
```

17
static/js/email_address.js

@ -0,0 +1,17 @@
/** To enable the redirection has no meaning if the local email adress is not
* enabled. Thus this function enable the checkbox if needed and changes its
* state.
*/
function enable_redirection_chkbox() {
var redirect = document.getElementById('id_User-local_email_redirect');
var enabled = document.getElementById('id_User-local_email_enabled').checked;
if(!enabled)
{
redirect.checked = false;
}
redirect.disabled = !enabled;
}
var enabled_chkbox = document.getElementById('id_User-local_email_enabled');
enabled_chkbox.onclick = enable_redirection_chkbox;
enable_redirection_chkbox();

11
users/forms.py

@ -634,18 +634,11 @@ class EmailSettingsForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__) prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(EmailSettingsForm, self).__init__(*args, prefix=prefix, **kwargs) super(EmailSettingsForm, self).__init__(*args, prefix=prefix, **kwargs)
self.fields['email'].label = "Contact email address" self.fields['email'].label = "Main email address"
if 'local_email_redirect' in self.fields: if 'local_email_redirect' in self.fields:
self.fields['local_email_redirect'].label = "Redirect local emails" self.fields['local_email_redirect'].label = "Redirect local emails"
self.fields['local_email_redirect'].help_text = (
"Enable the automated redirection of the local email address "
"to the contact email address"
)
if 'local_email_enabled' in self.fields: if 'local_email_enabled' in self.fields:
self.fields['local_email_enabled'].label = "Use local emails" self.fields['local_email_enabled'].label = "Use local emails"
self.fields['local_email_enabled'].help_text = (
"Enable the use of the local email account"
)
def clean_email(self): def clean_email(self):
if not OptionalUser.objects.first().local_email_domain in self.cleaned_data.get('email'): if not OptionalUser.objects.first().local_email_domain in self.cleaned_data.get('email'):
@ -655,4 +648,4 @@ class EmailSettingsForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
class Meta: class Meta:
model = User model = User
fields = ['email', 'local_email_redirect', 'local_email_enabled'] fields = ['email','local_email_enabled', 'local_email_redirect']

30
users/migrations/0074_auto_20180814_1059.py

@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-08-14 08:59
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0073_auto_20180629_1614'),
]
operations = [
migrations.AlterField(
model_name='user',
name='email',
field=models.EmailField(blank=True, help_text='External email address allowing us to contact you.', max_length=254),
),
migrations.AlterField(
model_name='user',
name='local_email_enabled',
field=models.BooleanField(default=False, help_text='Enable the local email account.'),
),
migrations.AlterField(
model_name='user',
name='local_email_redirect',
field=models.BooleanField(default=False, help_text='Enable redirection of the local email messages to the main email.'),
),
]

20
users/migrations/0076_auto_20180811_0425.py

@ -1,20 +0,0 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-08-11 02:25
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0075_auto_20180811_0420'),
]
operations = [
migrations.AlterField(
model_name='user',
name='email',
field=models.EmailField(max_length=254, unique=True),
),
]

9
users/models.py

@ -195,14 +195,17 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
help_text="Doit contenir uniquement des lettres, chiffres, ou tirets", help_text="Doit contenir uniquement des lettres, chiffres, ou tirets",
validators=[linux_user_validator] validators=[linux_user_validator]
) )
email = models.EmailField(unique=True) email = models.EmailField(
blank=True,
help_text="External email address allowing us to contact you."
)
local_email_redirect = models.BooleanField( local_email_redirect = models.BooleanField(
default=False, default=False,
help_text="Whether or not to redirect the local email messages to the main email." help_text="Enable redirection of the local email messages to the main email."
) )
local_email_enabled = models.BooleanField( local_email_enabled = models.BooleanField(
default=False, default=False,
help_text="Wether or not to enable the local email account." help_text="Enable the local email account."
) )
school = models.ForeignKey( school = models.ForeignKey(
'School', 'School',

6
users/templates/users/profil.html

@ -27,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% load acl %} {% load acl %}
{% load logs_extra %} {% load logs_extra %}
{% load design %} {% load design %}
{% load i18n %}
{% block title %}Profil{% endblock %} {% block title %}Profil{% endblock %}
@ -437,7 +438,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<table class="table"> <table class="table">
<tr> <tr>
<th colspan="2">Contact email address</th> <th colspan="2">Contact email address</th>
<td colspan="2">{{ users.email }}</td> <td colspan="2">{{ users.get_mail }}</td>
</tr> </tr>
<tr> <tr>
<th>Enable the local email account</th> <th>Enable the local email account</th>
@ -446,6 +447,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<td>{{ users.local_email_redirect | tick }}</td> <td>{{ users.local_email_redirect | tick }}</td>
</tr> </tr>
</table> </table>
<p>{% blocktrans %}The Contact email is the email address where we send email to contact you. If you would like to use your external email address for that, you can either disable your local email address or enable the local email redirection.{% endblocktrans %}</p>
</div> </div>
{% if users.local_email_enabled %} {% if users.local_email_enabled %}
{% can_create EMailAddress users.id %} {% can_create EMailAddress users.id %}
@ -462,7 +464,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<table class="table"> <table class="table">
<tr> <tr>
<th>Contact email address</th> <th>Contact email address</th>
<td>{{ users.email }}</td> <td>{{ users.get_mail }}</td>
</tr> </tr>
</table> </table>
</div> </div>

3
users/templates/users/user.html

@ -36,6 +36,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% massive_bootstrap_form userform 'room,school,administrators,members' %} {% massive_bootstrap_form userform 'room,school,administrators,members' %}
{% bootstrap_button action_name button_type="submit" icon="star" %} {% bootstrap_button action_name button_type="submit" icon="star" %}
</form> </form>
{% if load_js_file %}
<script src="{{ load_js_file }}"></script>
{% endif %}
<br> <br>
{% if showCGU %} {% if showCGU %}
<p>En cliquant sur Créer ou modifier, l'utilisateur s'engage à respecter les <a href="/media/{{ GTU }}" download="CGU" >règles d'utilisation du réseau</a>.</p> <p>En cliquant sur Créer ou modifier, l'utilisateur s'engage à respecter les <a href="/media/{{ GTU }}" download="CGU" >règles d'utilisation du réseau</a>.</p>

4
users/views.py

@ -541,7 +541,8 @@ def edit_emailaddress(request, emailaddress_instance, **_kwargs):
return form( return form(
{'userform': emailaddress, {'userform': emailaddress,
'showCGU': False, 'showCGU': False,
'action_name': 'Edit a local email account'}, 'action_name': 'Edit a local email account',
},
'users/user.html', 'users/user.html',
request request
) )
@ -585,6 +586,7 @@ def edit_email_settings(request, user_instance, **_kwargs):
return form( return form(
{'userform': email_settings, {'userform': email_settings,
'showCGU': False, 'showCGU': False,
'load_js_file': '/static/js/email_address.js',
'action_name': 'Edit the email settings'}, 'action_name': 'Edit the email settings'},
'users/user.html', 'users/user.html',
request request

Loading…
Cancel
Save