You've already forked Mailu
							
							
				mirror of
				https://github.com/Mailu/Mailu.git
				synced 2025-10-30 23:37:43 +02:00 
			
		
		
		
	Use a single domain form
This commit is contained in:
		| @@ -9,19 +9,14 @@ class LoginForm(Form): | ||||
|     submit = fields.SubmitField('Sign in') | ||||
|  | ||||
|  | ||||
| class DomainCreateForm(Form): | ||||
| class DomainForm(Form): | ||||
|     name = fields.StringField('Domain name', [validators.DataRequired()]) | ||||
|     max_users = fields_.DecimalField('Maximum user count', default=10) | ||||
|     max_aliases = fields_.DecimalField('Maximum alias count', default=10) | ||||
|     comment = fields.StringField('Comment') | ||||
|     submit = fields.SubmitField('Create') | ||||
|  | ||||
|  | ||||
| class DomainEditForm(Form): | ||||
|     max_users = fields.IntegerField('Maximum mailbox count') | ||||
|     max_aliases = fields.IntegerField('Maximum aliases count') | ||||
|     comment = fields.StringField('Comment') | ||||
|     submit = fields.SubmitField('Save') | ||||
|  | ||||
|  | ||||
| class UserForm(Form): | ||||
|     localpart = fields.StringField('E-mail', [validators.DataRequired()]) | ||||
|     pw = fields.PasswordField('Password', [validators.DataRequired()]) | ||||
|   | ||||
| @@ -36,8 +36,8 @@ class Domain(Base): | ||||
|     name = db.Column(db.String(80), primary_key=True, nullable=False) | ||||
|     admins = db.relationship('User', secondary=admins, | ||||
|         backref=db.backref('admin_of'), lazy='dynamic') | ||||
|     max_users = db.Column(db.Integer, nullable=True) | ||||
|     max_aliases = db.Column(db.Integer, nullable=True) | ||||
|     max_users = db.Column(db.Integer, nullable=False, default=0) | ||||
|     max_aliases = db.Column(db.Integer, nullable=False, default=0) | ||||
|  | ||||
|     def has_address(self, localpart): | ||||
|         for address in self.users + self.aliases: | ||||
|   | ||||
| @@ -1,5 +1,15 @@ | ||||
| {% extends "form.html" %} | ||||
| {% extends "base.html" %} | ||||
|  | ||||
| {% block title %} | ||||
| New domain | ||||
| {% endblock %} | ||||
|  | ||||
| {% block box_content %} | ||||
| <form class="form" method="post" role="form"> | ||||
|   {{ form.hidden_tag() }} | ||||
|   {{ macros.form_field(form.name) }} | ||||
|   {{ macros.form_fields((form.max_users, form.max_aliases)) }} | ||||
|   {{ macros.form_field(form.comment) }} | ||||
|   {{ macros.form_field(form.submit) }} | ||||
| </form> | ||||
| {% endblock %} | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| {% extends "form.html" %} | ||||
| {% extends "domain/create.html" %} | ||||
|  | ||||
| {% block title %} | ||||
| Edit domain | ||||
|   | ||||
| @@ -3,6 +3,7 @@ from flask.ext import login as flask_login | ||||
|  | ||||
| import os | ||||
| import flask | ||||
| import wtforms_components | ||||
|  | ||||
|  | ||||
| @app.route('/domain', methods=['GET']) | ||||
| @@ -15,12 +16,14 @@ def domain_list(): | ||||
| @flask_login.login_required | ||||
| def domain_create(): | ||||
|     utils.require_global_admin() | ||||
|     form = forms.DomainCreateForm() | ||||
|     form = forms.DomainForm() | ||||
|     if form.validate_on_submit(): | ||||
|         if models.Domain.query.filter_by(name=form.name.data).first(): | ||||
|             flask.flash('Domain %s is already used' % form.name.data, 'error') | ||||
|         else: | ||||
|             domain = models.Domain(name=form.name.data) | ||||
|             domain.max_users = int(form.max_users.data) | ||||
|             domain.max_aliases = int(form.max_aliases.data) | ||||
|             domain.comment = form.comment.data | ||||
|             db.session.add(domain) | ||||
|             db.session.commit() | ||||
| @@ -34,10 +37,11 @@ def domain_create(): | ||||
| def domain_edit(domain_name): | ||||
|     utils.require_global_admin() | ||||
|     domain = utils.get_domain_admin(domain_name) | ||||
|     form = forms.DomainEditForm(obj=domain) | ||||
|     form = forms.DomainForm(obj=domain) | ||||
|     wtforms_components.read_only(form.name) | ||||
|     if form.validate_on_submit(): | ||||
|         domain.max_users = form.max_users.data | ||||
|         domain.max_aliases = form.max_aliases.data | ||||
|         domain.max_users = int(form.max_users.data) | ||||
|         domain.max_aliases = int(form.max_aliases.data) | ||||
|         domain.comment = form.comment.data | ||||
|         db.session.add(domain) | ||||
|         db.session.commit() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user