@route('mailing-list', method=('post', 'options'))
    def mailing_list(self, request):
        form_class = get_form_class('mailing-list')
        if not form_class:
            raise Http404

        if request.method == 'OPTIONS':
            request.app.fire('on_preflight', request, methods=['POST'])
            return request.response

        user = request.cache.user
        data = request.body_data()
        if user.is_authenticated():
            raise MethodNotAllowed

        form = form_class(request, data=data)
        if form.is_valid():
            email = form.cleaned_data['email']
            odm = request.app.odm()
            topic = request.config['GENERAL_MAILING_LIST_TOPIC']
            with odm.begin() as session:
                q = session.query(odm.mailinglist).filter_by(email=email,
                                                             topic=topic)
                if not q.count():
                    entry = odm.mailinglist(email=email, topic=topic)
                    session.add(entry)
                    request.response.status_code = 201
                    result = json_message(request,
                                          'Email %s added to mailing list'
                                          % email)
                else:
                    result = json_message(request,
                                          'Email %s already in mailing list'
                                          % email, level='warning')
        else:
            result = form.tojson()
        return Json(result).http_response(request)
Add a given email to a mailing list
dataset/ETHPy150Open quantmind/lux/lux/extensions/auth/views.py/Authorization.mailing_list