Пример #1
0
def create_recipient():
    '''
        Create Recipient
    '''
    data = request.get_json() or {}
    if 'message_id' not in data:
        return bad_request('must include message_id')
    if 'email' not in data:
        return bad_request('recipient must have an email')
    if 'delivered' not in data:
        return bad_request('must include delivery status')
    if Recipient.query.filter_by(message_id=data['message_id'],
                                 email=data['email']).first():
        return bad_request('message already has this recipient email')
    recipient = Recipient()
    recipient.from_dict(data)
    db.session.add(recipient)
    db.session.commit()
    response = jsonify(recipient.to_dict())
    response.status_code = 201

    # response.headers['Location'] = url_for(
    #     'api.get_recipient', recipient=recipient.id
    # )
    return response
Пример #2
0
def register(user_type):

    if current_user.is_authenticated:
        return redirect(url_for('deliveries', username=current_user.username))

    form = RecipientRegistrationForm(
    ) if user_type == 'recipient' else VolunteerRegistrationForm()
    header = f'{user_type.capitalize()} Registration'

    if form.validate_on_submit():
        if user_type == 'volunteer':
            user = Volunteer(name=form.name.data,
                             username=form.username.data,
                             email=form.email.data,
                             phone=form.phone.data)
        elif user_type == 'recipient':
            user = Recipient(name=form.name.data,
                             username=form.username.data,
                             email=form.email.data,
                             phone=form.phone.data,
                             address=form.address.data,
                             address_notes=form.address_notes.data)

        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Thank you for registering for Hanover Helpers!')
        login_user(user)
        return redirect(url_for('deliveries', username=current_user.username))

    return render_template('standard_form.html', header=header, form=form)
Пример #3
0
def get_recipients(message_id):
    '''
        Retrieve collection of recpients for a message
    '''
    page = request.args.get('page', 1, type=int)
    per_page = min(request.args.get('per_page', 10, type=int), 100)
    m = Message.query.get_or_404(message_id)
    data = Recipient.to_collection_dict(m.recipients,
                                        page,
                                        per_page,
                                        'api.get_recipients',
                                        message_id=message_id)
    return jsonify(data)
Пример #4
0
def recipient_add():
    recipient_form = RecipientForm()

    var_list = []
    for a in Person.__table__.columns:
        print('att', a.doc, a.name)
        d = {}
        d['doc'] = a.doc
        d['var'] = a.name
        var_list.append(d)

    if request.method == 'POST':
        data = request.form
        try:
            recipient_data = {}
            if data:
                for d in data:
                    print(d, data[d])
                    if hasattr(Recipient, d):
                        recipient_data[d] = data[d]

            new_recipient = Recipient(**recipient_data)
            new_recipient.save_to_db()

        except Exception as e:
            print("<add_recipient error>", e)
            flash(e)
            return render_template("recipient_form.html",
                                   form=recipient_form,
                                   var=var_list)

        return redirect(url_for('main.recipients_list'))

    return render_template("recipient_form.html",
                           form=recipient_form,
                           var=var_list)
Пример #5
0
def _store_recipient(logger, data, message_id):
    '''
    Creates new Recipient entry if Message has already been created
    '''
    logger.info('Creating Recipient.')
    r = Recipient(
        message_id=message_id,
        action=data['action'],
        reason=data['reason'],
        reason_extra=data['reason_extra'],
        delivered=data['delivered'],
        delivery_detail=data['delivery_detail'],
        email=data['email'],
    )
    try:
        _add(r)
    except Exception as e:
        raise Exception(e)
Пример #6
0
 def test_transaction_assign_recipient_volunteer(self):
     t = Transaction()
     r = Recipient(username='******')
     v = Volunteer(username='******')
     db.session.add_all([t, r, v])
     db.session.commit()
     t.assign_recipient(r)
     self.assertEqual(t.recipient, r)
     self.assertEqual(t.recipient_id, r.id)
     self.assertFalse(t.claimed)
     self.assertEqual(r.transactions[0], t)
     t.assign_volunteer(v)
     db.session.add(t)
     db.session.commit()
     self.assertEqual(t.volunteer, v)
     self.assertEqual(t.volunteer_id, v.id)
     self.assertTrue(t.claimed)
     self.assertEqual(v.transactions[0], t)
Пример #7
0
    def setUp(self):
        """
        Will be called before every test
        """

        db.create_all()

        # create test event
        event = Event(event_id='31',
                      event_subject='Nowaday',
                      event_content='Test content',
                      timestamp=datetime.datetime(2019, 5, 17))

        recipient = Recipient(name="Grant",
                              email="*****@*****.**",
                              event_id="31")

        # save event to database
        db.session.add(event)
        db.session.add(recipient)
        db.session.commit()
Пример #8
0
    def test_add_recipient(self):
        message_id = '1578083234-893239-2956-1311577-1'
        action = 'allowed'
        reason = ''
        reason_extra = ''
        delivered = 'delivered'
        delivery_detail = 'mail.protonmail.ch:25:250 2.0.0 OK: queued as \
                           01BF74010077'

        email = '*****@*****.**'
        r = Recipient(message_id=message_id,
                      action=action,
                      reason=reason,
                      reason_extra=reason_extra,
                      delivered=delivered,
                      delivery_detail=delivery_detail,
                      email=email)
        db.session.add(r)
        db.session.commit()
        db.session.refresh(r)
        r = Recipient.query.filter_by(id=r.id).first()
        self.assertTrue(r)
        r = Recipient.query.filter_by(id=-1).first()
        self.assertFalse(r)
Пример #9
0
 def test_register_recipient(self):
     r = Recipient(username='******')
     db.session.add(r)
     db.session.commit()
     self.assertEqual(Recipient.query.first(), r)
     self.assertEqual(UserDirectory.query.first().id, r.userdir_id)