Changeset - 41232cb0b4fc
[Not reviewed]
Merge default
0 3 3
Dennis Fink - 10 years ago 2015-02-15 21:54:32
dennis.fink@c3l.lu
Merged online membership form
6 files changed with 245 insertions and 12 deletions:
0 comments (0 inline, 0 general)
ennstatus/root/forms.py
Show inline comments
 
from flask_wtf import Form
 
from wtforms import SelectField
 
from wtforms.validators import DataRequired
 
from wtforms import SelectField, StringField, RadioField, BooleanField, SubmitField
 
from wtforms.validators import DataRequired, InputRequired, Email, Optional, Length
 

	
 

	
 

	
 
COUNTRIES = [
 
@@ -17,3 +18,50 @@ class BPMForm(Form):
 
    country = SelectField('Country',
 
                          validators=[DataRequired()],
 
                          choices=COUNTRIES)
 

	
 

	
 
class MembershipForm(Form):
 

	
 
    username = StringField('Username*',
 
                           validators=[
 
                               InputRequired('This field is required!')]
 
                           )
 
    email = StringField('E-Mail*',
 
                        validators=[
 
                            InputRequired('This field is required!'),
 
                            Email()
 
                        ]
 
                        )
 
    firstname = StringField('First Name',
 
                            validators=[Optional()],
 
                            )
 
    surname = StringField('Surname',
 
                          validators=[Optional()],
 
                          )
 
    street = StringField('Nr., Street',
 
                         validators=[Optional()],
 
                         )
 
    zip = StringField('ZIP-Code',
 
                      validators=[Length(max=30), Optional()],
 
                      )
 
    city = StringField('City/Town',
 
                       validators=[Optional()],
 
                       )
 
    country = StringField('Country',
 
                          validators=[Optional()],
 
                          )
 
    gpg = StringField('GPG-ID',
 
                      validators=[Optional()],
 
                      )
 

	
 
    membership = RadioField('Membership Plan*',
 
                            validators=[DataRequired()],
 
                            choices=[
 
                                ('regular', 'Regular membership (120€/year)'),
 
                                ('student', 'Student memnbership (60€/year)'),
 
                                ('starving', 'Starving Hacker - Get in touch with us at info@enn.lu'),
 
                            ]
 
                            )
 

	
 
    c3l = BooleanField('Include "Chaos Computer Club Lëtzebuerg" Membership<sup>1</sup>')
 
    submit = SubmitField('Become a member')
ennstatus/root/functions.py
Show inline comments
 
new file 100644
 
from flask import render_template, current_app
 

	
 
from flask_mail import Mail, Message
 

	
 
from ennstatus.status.functions import mail
 

	
 

	
 
def send_membership_mail(form):
 
    try:
 
        msg = Message('New membership application', sender='ennstatus@enn.lu')
 
        msg.add_recipient(current_app.config['ENNSTATUS_MEMBERSHIP_MAIL'])
 

	
 
        msg.body = render_template('root/membership_mail.txt',
 
                                   username=form.username.data,
 
                                   email=form.email.data,
 
                                   membership=form.membership.data,
 
                                   c3l=form.c3l.data,
 
                                   firstname=form.firstname.data,
 
                                   surname=form.surname.data,
 
                                   street=form.street.data,
 
                                   zip=form.zip.data,
 
                                   city=form.city.data,
 
                                   country=form.country.data,
 
                                   gpg=form.gpg.data
 
                                   )
 
        print(msg.body)
 
        mail.send(msg)
 
    except KeyError:
 
        current_app.logger.error('Membership admin not found!')
 
    except AssertionError:
 
        pass
 
    except Exception as e:
 
        current_app.logger.error('Unexpecter error: %s' % e,
 
                                 exc_info=True)
ennstatus/root/views.py
Show inline comments
 
from flask import (Blueprint, render_template, current_app,
 
                   request, redirect, url_for)
 

	
 
from ennstatus.root.forms import BPMForm
 
from ennstatus.root.forms import BPMForm, MembershipForm
 
from ennstatus.root.constants import BPM_ADDRESSES
 
from ennstatus.root.functions import send_membership_mail
 

	
 
root_page = Blueprint('root', __name__)
 

	
 
@@ -37,6 +38,20 @@ def member():
 
    return render_template('root/member.html')
 

	
 

	
 
@root_page.route('/membership', methods=('GET', 'POST'))
 
def membership():
 

	
 
    current_app.logger.info('Handling membership')
 
    form = MembershipForm()
 

	
 
    if request.method == 'POST':
 
        current_app.logger.debug('Validating form')
 
        if form.validate_on_submit():
 
            send_membership_mail(form)
 

	
 
    return render_template('root/membership.html', form=form)
 

	
 

	
 
@root_page.route('/contact', methods=('GET', 'POST'))
 
def contact():
 

	
ennstatus/templates/root/member.html
Show inline comments
 
@@ -34,14 +34,30 @@
 

	
 
    <h3>How to become a member?</h3>
 
    <p>Becoming a member is very simple. Just follow these steps:</p>
 
    <ol>
 
      <li>Download the following <a href="{{ url_for('static', filename='files/MembershipForm.pdf') }}">membership form</a> and fill in the necessary information</li>
 
      <li>Send the membership form per mail to <a href="mailto://info@enn.lu">info@enn.lu</a> or to one of our
 
          <a href="{{ url_for('donate.snailmail') }}">snailmail</a> address.</li>
 
      <li>Pay your annually membership fee. Use one of the payment methods (except <a href="{{ url_for('donate.flattr') }}">Flattr</a> or <a href="{{ url_for('donate.bpm') }}">BPM Points</a>)
 
          specified on our <a href="{{ url_for('donate.index') }}">donations</a> page.
 
      </li>
 
      <li>Wait until we get back in touch with you.</li>
 
    </ol>
 
    <table class="table table-bordered">
 
      <thead>
 
        <tr class="info">
 
          <th>Using online form</th>
 
          <th>Using PDF form</th>
 
        </tr>
 
      </thead>
 
      <tbody>
 
        <tr>
 
          <td>Fill out the <a href="{{ url_for('root.membership') }}">online form</a>.</td>
 
          <td>Download the following <a href="{{ url_for('static', filename='files/MembershipForm.pdf') }}">membership form</a> and fill in the necessary information.</td>
 
        </tr>
 
        <tr>
 
          <td>The form will automatically send a mail to our staff when you click the 'Become a member' button.</td>
 
          <td>Send the membership form per mail to <a href="mailto://info@enn.lu">info@enn.lu</a> or to one ou our <a href="{{ url_for('donate.snailmail') }}">snailmail</a> addresses.</td>
 
        </tr>
 
        <tr>
 
          <td colspan="2">Pay your annually membership fee. Use one of the payment methods (except <a href="{{ url_for('donate.flattr') }}">Flattr</a> or <a href="{{ url_for('donate.bpm') }}">BPM Points</a>)
 
              specified on our <a href="{{ url_for('donate.index') }}">donations</a> page.</td>
 
        </tr>
 
        <tr>
 
          <td colspan="2">Wait until we get back in touch with you.</td>
 
        </tr>
 
      </tbody>
 
    </table>
 
  </div>
 
{% endblock %}
ennstatus/templates/root/membership.html
Show inline comments
 
new file 100644
 
{% extends 'base.html' %}
 

	
 
{% import 'bootstrap/wtf.html' as wtf %}
 

	
 
{% set title = 'Membership' %}
 

	
 
{% block content %}
 
  <div class="col-md-12">
 
    <h2>Register as member</h2>
 
    <form method="post" class="form form-horizontal" role="form">
 
      {{ form.hidden_tag() }}
 
      <div class="form-group">
 
        {{ form.username.label(class_='control-label col-lg-2') }}
 
        <div class="col-lg-10">
 
          {{ form.username(class_='form-control') }}
 
        </div>
 
      </div>
 
      <div class="form-group">
 
        {{ form.email.label(class_='control-label col-lg-2') }}
 
        <div class="col-lg-10">
 
          {{ form.email(class_='form-control') }}
 
        </div>
 
      </div>
 
      <div class="form-group">
 
        {{ form.firstname.label(class_='control-label col-lg-2') }}
 
        <div class="col-lg-10">
 
          {{ form.firstname(class_='form-control') }}
 
        </div>
 
      </div>
 
      <div class="form-group">
 
        {{ form.surname.label(class_='control-label col-lg-2') }}
 
        <div class="col-lg-10">
 
          {{ form.surname(class_='form-control') }}
 
        </div>
 
      </div>
 
      <div class="form-group">
 
        {{ form.street.label(class_='control-label col-lg-2') }}
 
        <div class="col-lg-10">
 
          {{ form.street(class_='form-control') }}
 
        </div>
 
      </div>
 
      <div class="form-group">
 
        {{ form.zip.label(class_='control-label col-lg-2') }}
 
        <div class="col-lg-10">
 
          {{ form.zip(class_='form-control') }}
 
        </div>
 
      </div>
 
      <div class="form-group">
 
        {{ form.city.label(class_='control-label col-lg-2') }}
 
        <div class="col-lg-10">
 
          {{ form.city(class_='form-control') }}
 
        </div>
 
      </div>
 
      <div class="form-group">
 
        {{ form.country.label(class_='control-label col-lg-2') }}
 
        <div class="col-lg-10">
 
          {{ form.country(class_='form-control') }}
 
        </div>
 
      </div>
 
      <div class="form-group">
 
        {{ form.gpg.label(class_='control-label col-lg-2') }}
 
        <div class="col-lg-10">
 
          {{ form.gpg(class_='form-control') }}
 
        </div>
 
      </div>
 
      <div class="form-group">
 
        {{ form.membership.label(class_='control-label col-lg-2') }}
 
        <div class="col-lg-10">
 
        {% for field in form.membership %}
 
          <div class="radio">
 
            <label>
 
              {{ field() }} {{ field.label.text }}
 
            </label>
 
          </div>
 
        {% endfor %}
 
        </div>
 
      </div>
 
      <div class="form-group">
 
        <label class="col-lg-2 control-label">Double membership</label>
 
        <div class="col-lg-10">
 
          <div class="checkbox">
 
            <label>
 
              {{ form.c3l() }} {{ form.c3l.label.text|safe }}
 
            </label>
 
          </div>
 
        </div>
 
      </div>
 
      <div class="form-group">
 
        <div class="col-lg-offset-2 col-lg-10">
 
        {{ form.submit(class_='btn btn-primary') }}
 
        </div>
 
      </div>
 
    </div>
 
    </form>
 
    <p>Field marked with * are required!</p>
 
    <p><sup>1</sup>: If you have decided to apply for the <i>double membership</i>, the membership fees are 150€/year for the regular
 
    membership and 70€/year for the student membership.</p>
 
  </div>
 
{% endblock %}
ennstatus/templates/root/membership_mail.txt
Show inline comments
 
new file 100644
 
Hi,
 

	
 
We got a new membership application!
 

	
 
Username: {{ username }}
 
E-Mail: {{ email }}
 
Membership Plan: {{ membership }}
 
Double Membership: {{ c3l }}
 

	
 
Additional information:
 

	
 
First Name: {{ firstname }}
 
Surname: {{ surname }}
 
Nr., Street: {{ street }}
 
ZIP-Code: {{ zip }}
 
City: {{ city }}
 
Country: {{ country }}
 
GPG-ID: {{ gpg }}
 

	
 
Sincerely,
 
Ennstatus
0 comments (0 inline, 0 general)