def generate_fakes():
	Author.generate_fake()
	BookDetails.generate_fake()
	BookInventory.generate_fake()
	Client.generate_fake()
	Person.generate_fake()
	Volunteer.generate_fake()
	Donor.generate_fake()
def donation(request):
    context_dict = {}
    if request.POST:
        try:

            if Donation.objects.filter():
                donation = Donation.objects.filter()[0]
            else:
                donation = Donation()
                donation.name = "Corona virus fundraising"
                donation.save()

            donor = Donor()
            donor.full_name = request.POST['firstname'] + " " + request.POST[
                'lastname']
            donor.amount = request.POST['amount']
            donor.email = request.POST['email']
            donor.phone_number = request.POST['phonenumber']
            donor.save()

            donorDonation = DonorDonation()
            donorDonation.donation = donation
            donorDonation.donor = donor

            return redirect('/')
        except:
            render(request, 'app/donate.html', context_dict)
    else:
        return render(request, 'app/donate.html', context_dict)
Exemple #3
0
def oauth_callback(provider, user_type=1):
    if not current_user.is_anonymous():
        return redirect(url_for('index'))
    oauth = OAuthSignIn.get_provider(provider)
    email, first_name, last_name = oauth.callback()
    if email is None:
        flash(
            'Facebook authentication failed. Try again or register via email.')
        return redirect(url_for('home.register'))
    user = User.query.filter_by(email=email).first()
    if not user:
        user = User(first_name=first_name,
                    last_name=last_name,
                    email=email,
                    password='',
                    user_type=1)
        db.session.add(user)
        if user_type == 1:
            student = Student(user_id=User.query.filter_by(
                email=email).first().id)
            db.session.add(student)
        if user_type == 2:
            donor = Donor(user_id=User.query.filter_by(email=email).first().id)
            db.session.add(donor)
        db.session.commit()
    login_user(user, remember=False)
    return redirect(url_for('home.index'))
Exemple #4
0
def donate(scholarship_id=None):

    scholarship = Scholarship.get_scholarship(scholarship_id)
    if not scholarship:
        flash(
            'Error finding donation page. Please make sure the scholarship ID is correct.'
        )
        return redirect(url_for('donor.browse'))

    form = DonationForm(request.form, obj=donor)
    if form.validate_on_submit():
        amount = form.amount.data or form.other_amount.data
        donation = Donation(
            donor_id=Donor.get_donor(user_id=current_user.id).donor_id,
            scholarship_id=scholarship_id,
            message=form.message.data,
            amount=amount,
            cleared=False)
        db.session.add(donation)
        db.session.commit()
        form.populate_obj(donor)
        return render_template(
            'donor/donate.html',
            scholarship=scholarship,
            donation=donation,
            key=current_app.config['STRIPE_CREDENTIALS']['publishable_key'],
            form=form)

    return render_template('donor/donate.html',
                           form=form,
                           scholarship=scholarship)
Exemple #5
0
def test_donor_with_complete_fields():
    test_donor = Donor(donor_name='Tesla', email='*****@*****.**', want_receipt=True,
                       telephone_number='604-123-5678', mobile_number='604-123-5678',
                       address_line='Mars street', city='Tokyo',
                       province='Japan', postal_code='123123', verified=True)
    test_donor.save()

    response = Donor.objects.get(donor_name='Tesla')
    assert response.donor_name == 'Tesla'
    assert response.email == '*****@*****.**'
    assert response.want_receipt == True
    assert response.telephone_number == '604-123-5678'
    assert response.mobile_number == '604-123-5678'
    assert response.address_line == 'Mars street'
    assert response.city == 'Tokyo'
    assert response.province == 'Japan'
    assert response.postal_code == '123123'
    assert response.verified == True
Exemple #6
0
def profile(user_id=None, donor_id=None):
    if donor_id:
        donor = Donor.get_donor(donor_id=donor_id)
        if donor:
            return render_template('donor/profile.html', donor=donor)
        flash("The donor profile you selected is unavailable. \
            We've redirected you to your own profile.".format(donor_id))
    donor = Donor.query.filter_by(user_id=current_user.id).first() or None
    return render_template('donor/profile.html', donor=donor)
Exemple #7
0
def createdonor():
    """
    @api {post} /donor Add a new donor
    @apiVersion 1.0.0
    @apiName createdonor
    @apiGroup Donor

    @apiParam {String}      first_name      The first name of the Donor.
    @apiParam {String}      last_name       the last name of the Donor.
    @apiParam {String}      email           email of Donor.
    @apiParam {String}      phone_no        phone number of Donor.
    @apiParam {String}      password        password of Donor.
    @apiParam {String}      organisation    organisation of Donor.
    @apiParam {String}      city            city name(part of address)
    @apiParam {String}      street          street number(part of address)
    @apiParam {String}      landmark        landmark description(part of address)
    @apiParam {String}      country         country name(part of address)

    @apiSuccess {String}    message         donor added to database

    @apiError               message         Donor with that email already exists!
    @apiError               message[2]         address street not provided
    @apiError               message[3]         not json
    """
    donor = request.json
    if not donor:
        return jsonify({"message": "not json"}), 400
    if not donor.get("street"):
        return jsonify({"message": "address street not provided"}), 400
    print(donor)
    check_donor = Donor.query.filter_by(email=donor.get('email')).first()
    if check_donor:
        return jsonify({'message': 'Donor with that email already exists!'})
    password_hash = bcrypt.generate_password_hash(
        donor.get('password')).decode('utf-8')
    username = donor.get('email').split('@')[0]
    check_username = username_in_database_donor(username)
    if check_username:
        while check_username:
            username = username + '1'
            check_username = username_in_database_donor(username)
    u = Donor(first_name=donor.get('first_name'),
              last_name=donor.get('last_name'),
              email=donor.get('email'),
              phone_no=donor.get('phone_no'),
              username=username,
              password_hash=password_hash,
              organisation=donor.get('organisation'))
    address = Address(donor=u,
                      city=donor.get('city'),
                      street=donor.get('street'),
                      country=donor.get('country'),
                      landmark=donor.get('landmark'))
    db.session.add(address)
    db.session.add(u)
    db.session.commit()
    return jsonify({'message': 'Donor added to database'}), 200
Exemple #8
0
def insert_donor():
    form = InsertForm()
    # If form is valid, post it and return the updated table
    # on account page
    if form.validate_on_submit():
        # add donor to database
        donor = Donor(name=form.name.data,
                      contact_email=form.contact_email.data,
                      donation_amount=form.donation_amount.data,
                      donate_event=form.donate_event.data,
                      admin=current_user)
        db.session.add(donor)
        db.session.commit()
        flash(' A new person data was added', 'success')
        return redirect(url_for('users.account'))
    return render_template('insert_donor.html',
                           form=form,
                           title=' Add Donor',
                           legend='Add Donor')
Exemple #9
0
def create():
    form = CreateScholarshipForm(request.form)
    if form.validate_on_submit():
        new_scholarship = Scholarship(
            name=form.name.data,
            category=form.category.data,
            affiliation=form.affiliation.data,
            slug=form.slug.data,
            grade_9=form.grade_9.data,
            grade_10=form.grade_9.data,
            grade_11=form.grade_9.data,
            grade_12=form.grade_9.data,
            amount_target=form.amount_target.data,
            description=form.description.data,
            creator_id=Donor.get_donor(user_id=current_user.id).donor_id)
        db.session.add(new_scholarship)
        db.session.commit()
        flash('Your scholarship was successfully created!')
        return redirect(url_for('home.index'))
    return render_template('donor/create.html', form=form)
Exemple #10
0
def register():
    # if already signed in take to homepage
    if current_user.is_authenticated():
        return redirect(url_for('home.index'))

    form = RegisterForm(request.form)
    if form.validate_on_submit():
        if form.user_type.data == 1:
            user = User(first_name=form.first_name.data,
                        last_name=form.last_name.data,
                        email=form.email.data,
                        password=generate_password_hash(form.password.data),
                        user_type=1)
        elif form.user_type.data == 2:
            user = User(first_name=form.first_name.data,
                        last_name=form.last_name.data,
                        email=form.email.data,
                        password=generate_password_hash(form.password.data),
                        user_type=2)

        try:
            db.session.add(user)
            db.session.commit()
        except IntegrityError:
            flash('An account with this email already exists.')
        else:
            if form.user_type.data == 1:
                student = Student(user_id=User.query.filter_by(
                    email=form.email.data).first().id)
                db.session.add(student)
            elif form.user_type.data == 2:
                donor = Donor(user_id=User.query.filter_by(
                    email=form.email.data).first().id)
                db.session.add(donor)
            db.session.commit()
            login_user(user, remember=False)  # TODO: add remember me
            flash('Thanks for registering')
            return redirect(url_for('home.index'))

    return render_template("home/register.html", form=form)
Exemple #11
0
def createdonor(module):
    donor_pure = request.json
    donor = donor_pure.get('form')
    if not donor:
        return jsonify({"message": "not json"}), 400
    if not donor.get("street"):
        return jsonify({"message": "address street not provided"}), 400
    print(donor)
    check_donor = Donor.query.filter_by(email=donor.get('email')).first()
    if check_donor:
        return jsonify({'message': 'Donor with that email already exists!'})
    # modules = Modules.query.all()
    # # if module not in modules:           # TODO: check if this works
    #     return jsonify({'message': 'This module does not exist'})
    password_hash = bcrypt.generate_password_hash(
        donor.get('password')).decode('utf-8')
    username = donor.get('email').split('@')[0]
    check_username = username_in_database_donor(username)
    if check_username:
        while check_username:
            username = username + '1'
            check_username = username_in_database_donor(username)
    u = Donor(first_name=donor.get('first_name'),
              last_name=donor.get('last_name'),
              email=donor.get('email'),
              phone_no=donor.get('phone_no'),
              username=username,
              password_hash=password_hash,
              module=donor_pure.get('module'),
              organisation=donor.get('organisation'))
    address = Address(donor=u,
                      city=donor.get('city'),
                      street=donor.get('street'),
                      country=donor.get('country'),
                      landmark=donor.get('landmark'))
    db.session.add(address)
    db.session.add(u)
    db.session.commit()
    return jsonify({'message': 'Donor added to database'}), 200
Exemple #12
0
def test_donor_bad_phonenumber():
    # DOES NOT THROW ANYTHING.
    test_donor = Donor(donor_name='Zavala',
                       telephone_number='111122223333123', want_receipt=False)
    test_donor.save()
def init_persons():
	Person.generate_fake(100)
	Donor.generate_fake()
	Volunteer.generate_fake()
Exemple #14
0
def test_donor_null_for_want_receipt():
    with pytest.raises(IntegrityError):
        test_donor = Donor(donor_name='Tohru', telephone_number='123-333-3333')
        test_donor.save()
Exemple #15
0
def signup(request):
    context_dict = {}

    # If the user is logged in redirect to the app dashboard
    if request.user.is_authenticated:
        return redirect("app:app")

    # Check if the request is Post, new user is being registered
    if request.method == 'POST':
        qd = dict(request.POST)

        # Check if it is Donor or Hospital
        if 'username' in qd:
            for k, v in qd.items():
                qd[k] = v[0]

            new_donor = Donor()

            # Create a new donor instance
            r = new_donor.new_donor(data=qd)
            # Handle any errors which may occur
            if r['error'] is None:
                return JsonResponse({
                    'success':
                    True,
                    'message':
                    "Account was successfully created. You can now log in!"
                })
            else:
                return JsonResponse({'success': False, 'message': r['error']})

        elif 'hospital_name' in qd:
            for k, v in qd.items():
                qd[k] = v[0]

            # Create a new hospital instance
            new_hosp = Hospital()
            # Handle any errors which may occur
            r = new_hosp.new_hospital(data=qd)
            if r['error'] is None:
                return JsonResponse({
                    'success':
                    True,
                    'message':
                    "Account was successfully created. You can now log in!"
                })
            else:
                return JsonResponse({'success': False, 'message': r['error']})

    # Use this to have a link choosing the Hospital form directly
    if request.method == 'GET':
        # Check if GET parameter has been used in the url to show hospital sign up form directly
        hospital = request.GET.get('hospital', '')
        if hospital == "true":
            context_dict['hospital'] = "true"
            response = render(request, 'app/signup.html', context=context_dict)

    else:
        return render(request, 'app/signup.html')

    response = render(request, 'app/signup.html', context=context_dict)

    # Return a rendered response to send to the client.
    return response
Exemple #16
0
def app(request):
    context_dict = {}

    # Check if the logged in user is Donor or Hospital
    if request.user.is_donor:
        # Get the logged in donor
        donor = Donor.objects.get(pk=request.user.id)
        context_dict["donor"] = donor

        # Get all hospitals
        hospitals = Hospital.objects.all()
        context_dict["hospitals"] = hospitals

        # Get the hospitals which need the donor's blood type
        if donor.notification:
            context_dict["notifications"] = Hospital.objects.filter(
                notified_types=donor.blood_type)

        # Get 4 most liked stories
        stories = Story.objects.order_by('-likes')[:4]
        context_dict["stories"] = stories

        # get list of stories this donor liked
        context_dict["liked"] = donor.likedStories

        # Get if the donor can donate blood again
        donate = Donor.donate_again(request.user.id)
        if donate:
            context_dict["donate"] = {"donate": "yes"}

        # Get all reviews of by the donor
        reviews = Review.objects.order_by('pk').filter(donor=donor)
        if len(reviews) > 0:
            context_dict["reviews"] = reviews

        # Get bookings of this donor
        bookings = Booking.objects.order_by('appointment').filter(donor=donor)
        if len(bookings) > 0:
            context_dict["bookings"] = bookings

    else:
        # Get the logged in hospital
        hospital = Hospital.objects.get(pk=request.user.id)
        context_dict["hospital"] = hospital
        # Get bookings at this hospital
        bookings = Booking.objects.order_by('appointment').filter(
            hospital=hospital)
        if len(bookings) > 0:
            context_dict["bookings"] = bookings
        # Get stories written by this hospital
        stories = Story.objects.order_by('-pk').filter(hospital=hospital)
        if len(stories) > 0:
            context_dict["stories"] = stories
        # Get all reviews about this hospital
        reviews = Review.objects.filter(hospital=hospital)
        if len(reviews) > 0:
            context_dict["reviews"] = reviews

    response = render(request, 'app/app.html', context=context_dict)
    # Return a rendered response to send to the client.
    return response
Exemple #17
0
def test_invalid_postal_code():
    test_donor = Donor(donor_name='Kobayashi',
                       postal_code='12345678123afasdf', want_receipt=False)
    test_donor.save()
    response = Donor.objects.get(donor_name='Kobayashi')
    assert len(response.postal_code) == 7