Changeset View
Changeset View
Standalone View
Standalone View
server/server/controllers/controller.py
| Context not available. | |||||
| return homepage() | return homepage() | ||||
| @app.route("/gooseberry/") | |||||
| def gooseberry_home(): | |||||
| return abort(404) | |||||
| """Emergency caching response. Add a {user} check in layout.html if this | |||||
| this gets enabled, otherwise the template will look for a non existing user | |||||
| supporters_count = supporters_count_data() | |||||
| response = make_response(render_template('gooseberry.html', | |||||
| supporters_count=supporters_count, | |||||
| user=None, | |||||
| currency_selector=True, | |||||
| subscription=False)) | |||||
| response.set_cookie('currency', 'USD') | |||||
| return response | |||||
| """ | |||||
| supporters_count = supporters_count_data() | |||||
| if current_user.is_anonymous(): | |||||
| response = make_response(render_template('gooseberry_pilot.html', | |||||
| supporters_count=supporters_count, | |||||
| user=current_user, | |||||
| currency_selector=True, | |||||
| subscription=False)) | |||||
| response.set_cookie('currency', default_country_currency()) | |||||
| return response | |||||
| else: | |||||
| if current_user.cloud_subscription: | |||||
| has_subscription = True | |||||
| else: | |||||
| has_subscription = False | |||||
| # Make a response object in order to set cookies for currency | |||||
| response = make_response(render_template('gooseberry_pilot.html', | |||||
| supporters_count=supporters_count, | |||||
| user=current_user, | |||||
| currency_selector=True, | |||||
| subscription=has_subscription)) | |||||
| response.set_cookie('currency', default_country_currency()) | |||||
| return response | |||||
| @app.route("/gooseberry/<action>", methods=['GET', 'POST']) | |||||
| def gooseberry(action): | |||||
| if request.method == 'POST': | |||||
| if action == 'pledge': | |||||
| currency = request.cookies.get('currency') | |||||
| pledge_amount = request.form["pledge_amount"] | |||||
| pledge_amount = float(pledge_amount) / currency_code_multiplier(currency) | |||||
| if current_user.is_anonymous(): | |||||
| return render_template('settings/pledge/add_billing_address.html', | |||||
| user=current_user, | |||||
| pledge_amount=pledge_amount, | |||||
| step=2) | |||||
| else: | |||||
| billing_address = Address.query.\ | |||||
| filter(Address.user_id == current_user.id).\ | |||||
| filter(Address.address_type == 'billing').\ | |||||
| first() | |||||
| if billing_address: | |||||
| return render_template('settings/pledge/make_pledge.html', | |||||
| user=current_user, | |||||
| address=billing_address, | |||||
| pledge_amount=pledge_amount, | |||||
| step=3) | |||||
| else: | |||||
| return render_template('settings/pledge/add_billing_address.html', | |||||
| user=current_user, | |||||
| pledge_amount=pledge_amount, | |||||
| step=2) | |||||
| # Temporary hack to get URLs to look nice | |||||
| elif action == 'make-pledge': | |||||
| if current_user.is_anonymous(): | |||||
| password = encrypt_password(request.form["password"]) | |||||
| user = user_datastore.get_user(request.form["email"]) | |||||
| pledge_amount = request.form["pledge_amount"] | |||||
| if user: | |||||
| user = user_datastore.get_user(request.form["email"]) | |||||
| flash('You already have an account! Please login first.') | |||||
| return render_template('settings/subscribe/add_billing_address.html', | |||||
| user=current_user, | |||||
| subscription_type=action, | |||||
| pledge_amount=pledge_amount, | |||||
| step=2) | |||||
| else: | |||||
| try: | |||||
| user = user_datastore.create_user( | |||||
| email=request.form["email"], | |||||
| password=password) | |||||
| db.session.commit() | |||||
| except IntegrityError: | |||||
| flash('Whoops! Something went wrong!') | |||||
| return render_template('settings/pledge/add_billing_address.html', | |||||
| user=current_user, | |||||
| subscription_type=action, | |||||
| pledge_amount=pledge_amount, | |||||
| step=2) | |||||
| login_user(user) | |||||
| send_email_welcome(current_user.email) | |||||
| return add_billing_address() | |||||
| else: | |||||
| return add_billing_address() | |||||
| # Temporary hack to handle currency conversion after adding an address | |||||
| elif action == 'pledge-after-address': | |||||
| pledge_amount = request.form["pledge_amount"] | |||||
| billing_address = Address.query.\ | |||||
| filter(Address.user_id == current_user.id).\ | |||||
| filter(Address.address_type == 'billing').\ | |||||
| first() | |||||
| if billing_address: | |||||
| return render_template('settings/pledge/make_pledge.html', | |||||
| user=current_user, | |||||
| address=billing_address, | |||||
| pledge_amount=pledge_amount, | |||||
| step=3) | |||||
| else: | |||||
| return render_template('settings/pledge/add_billing_address.html', | |||||
| user=current_user, | |||||
| pledge_amount=pledge_amount, | |||||
| step=2) | |||||
| else: | |||||
| if action == 'pledge': | |||||
| currency = request.cookies.get('currency') | |||||
| if currency: | |||||
| return render_template('settings/pledge/select_pledge_amount.html', | |||||
| user=current_user, | |||||
| currency_selector=True, | |||||
| step=1) | |||||
| else: | |||||
| response = make_response(render_template('settings/pledge/select_pledge_amount.html', | |||||
| user=current_user, | |||||
| currency_selector=True, | |||||
| step=1)) | |||||
| response.set_cookie('currency', default_country_currency()) | |||||
| return response | |||||
| else: | |||||
| pass | |||||
| @app.route("/backers/", defaults={'page': 0}) | |||||
| @app.route("/backers/<int:page>") | |||||
| @cache.memoize(timeout=60) | |||||
| def users_list(page): | |||||
| pagesize = 20 | |||||
| startbacker = page*pagesize | |||||
| endbacker = startbacker+pagesize | |||||
| backers = db.session.query( | |||||
| GooseberryPledge.user_id.label('user_id'), | |||||
| GooseberryPledge.pledge_date.label('pay_date'), | |||||
| GooseberryPledge.pledge_amount.label('amount'), | |||||
| GooseberryPledge.original_currency.label('original_currency'), | |||||
| literal('pledge').label('type') | |||||
| ).union_all( | |||||
| db.session.query( | |||||
| CloudSubscription.user_id.label('user_id'), | |||||
| CloudSubscription.start_date.label('pay_date'), | |||||
| CloudSubscription.prepaid_balance.label('amount'), | |||||
| CloudSubscription.original_currency.label('original_currency'), | |||||
| literal('cloud').label('type') | |||||
| ) | |||||
| ).\ | |||||
| order_by(desc('pay_date')).\ | |||||
| slice(startbacker,endbacker) | |||||
| events_list = [] | |||||
| for backer in backers: | |||||
| user = User.query.get(backer.user_id) | |||||
| amount = backer.amount | |||||
| if backer.original_currency == 'USD': | |||||
| amount = amount * 1.28 | |||||
| amount = round(amount, 2) | |||||
| if user.get_setting('show_avatar'): | |||||
| displayname = user.first_name+' '+user.last_name | |||||
| else: | |||||
| displayname = 'Anonymous' | |||||
| if backer.type == 'pledge': | |||||
| displaytype = 'Pledge' | |||||
| else: | |||||
| displaytype = 'Cloud Subscription' | |||||
| try: | |||||
| events_list.append([ | |||||
| pretty_date(backer.pay_date), | |||||
| displayname, | |||||
| str(amount) + ' ' + backer.original_currency, | |||||
| user.address[0].country_code_alpha2, | |||||
| user.gravatar(80), | |||||
| displaytype | |||||
| ]) | |||||
| except IndexError: | |||||
| pass | |||||
| return jsonify(event_list=events_list) | |||||
| @app.errorhandler(404) | @app.errorhandler(404) | ||||
| def not_found(error): | def not_found(error): | ||||
| return render_template('404.html'), 404 | return render_template('404.html'), 404 | ||||
| Context not available. | |||||