def gallery(): series_collection = crud.get_series_collection(crud.new_transaction(), 700, args=request.args) non_series_artwork_collection = crud.get_non_series_artwork_collection( crud.new_transaction(), 700, args=request.args) return render_template( 'gallery.html', series_collection=series_collection, non_series_artwork_collection=non_series_artwork_collection)
def facebook_shopping_feed(): artworks = crud.get_artwork_collection(crud.new_transaction(), 700, args=request.args) feed = render_template('facebook_feed.xml', artworks=artworks) response = make_response(feed) response.headers['mimetype'] = 'application/xml' response.headers["Content-Type"] = "text/xml; charset=utf-8" return response
def sitemap_series(): series_collection = crud.get_series_collection(crud.new_transaction(), 240, args=None) for series in series_collection: yield 'series', { 'slug': slugify_title(series['title']), 'id': series['id'] }
def sitemap_artwork(): artworks = crud.get_artwork_collection(crud.new_transaction(), 400, args=None) for artwork in artworks: yield 'artwork', { 'slug': slugify_title(artwork['title']), 'id': artwork['id'] }
def artwork_buy(id): artwork = crud.get_artwork(crud.new_transaction(), id, 240) artwork_url = url_for('artwork', slug=slugify_title(artwork["title"]), id=id, _external=True) if artwork is None: abort(404) enquiry_email_template = crud.get_artwork_buy_email_template() enquirer_email_address = request.form.get('email') enquirer_name = request.form.get('name') enquirer_address = f"{request.form.get('city')}, {request.form.get('country')}" enquirer_address_type = request.form.get('address_type') enquirer_message = request.form.get('message') email_subject = f"Psyclonic Studios artwork enquiry: {artwork['title']}" email_body = Environment( loader=BaseLoader()).from_string(enquiry_email_template).render( name=enquirer_name, address=enquirer_address, address_type=enquirer_address_type, artwork=artwork, message=enquirer_message, artwork_url=artwork_url) email = gmail.compose_email_from_me(enquirer_email_address, email_subject, email_body, alias='Customer') email_response = gmail.send_email(email) trello_title = f'Buyer - {enquirer_name}' trello_description = render_template( 'trello_shipping_enquiry_description.md', gmail_link=gmail.get_email_link(email_response['id']), enquirer_name=enquirer_name, enquirer_email_address=enquirer_email_address, enquirer_address=enquirer_address, artwork=artwork, artwork_url=artwork_url, enquirer_message=enquirer_message) trello_due = datetime.today() + timedelta(3) trello_helper.create_customer_card( trello_helper.AWAITING_RESPONSE_LIST_ID, trello_title, desc=trello_description, due=str(trello_due), labels=[trello_helper.ARTWORK_ENQUIRY_LABEL], position='top') return render_template('enquiry_success.html', thankyou_text=crud.get_enquire_thankyou(), enquiry_type='artwork_shipping')
def cart(): cart = session.get('cart', {}) transaction = crud.new_transaction() cart_items = [{ 'artwork': crud.get_artwork(transaction, id, 240), 'quantity': cart[id] } for id in cart] cart_subtotal = sum(item['artwork']['price'] * item['quantity'] for item in cart_items) return render_template('cart.html', cart_items=cart_items, cart_subtotal=cart_subtotal, hide_cart=True)
def series(slug, id): series = crud.get_series(crud.new_transaction(), id, 700) if series is None: abort(404) number_of_tiles = len(series['artworks']) + len(series['series_images']) canonical_url = url_for('series', slug=slugify_title(series["title"]), id=id, _external=True) return render_template('series.html', series=series, number_of_tiles=number_of_tiles, canonical_url=canonical_url)
def artwork(slug, id): artwork = crud.get_artwork(crud.new_transaction(), id, 700) if artwork is None: abort(404) number_of_images = len(artwork['images']) canonical_url = url_for('artwork', slug=slugify_title(artwork["title"]), id=id, _external=True) in_cart = id in session.get('cart', []) return render_template('artwork.html', artwork=artwork, number_of_tiles=number_of_images, canonical_url=canonical_url, in_cart=in_cart)
def checkout(): cart = session.get('cart', {}) transaction = crud.new_transaction() cart_items = [{ 'artwork': crud.get_artwork(transaction, id, 240), 'quantity': cart[id] } for id in cart] cart_subtotal = sum(item['artwork']['price'] * item['quantity'] for item in cart_items) shipping_country = request.form.get('country') shipping_cost = 0 if not shipping_country.lower() == 'australia': insurance_cost = math.ceil(cart_subtotal / 100.0 - 1) * 2 international_shipping_cost = sum(item['quantity'] for item in cart_items) * 20 shipping_cost += round(insurance_cost + international_shipping_cost, 2) total_cost = cart_subtotal + shipping_cost stripe_amount = int(total_cost * 100) if 'payment_intent' in session and session['payment_intent']: intent = stripe.PaymentIntent.modify( session['payment_intent'], amount=stripe_amount, description=describe_cart(cart_items)) else: idempotency_key = str(uuid.uuid4()) intent = stripe.PaymentIntent.create( amount=stripe_amount, currency='aud', description=describe_cart(cart_items), metadata={'channel': 'website'}, idempotency_key=idempotency_key) session['payment_intent'] = intent.id crud.update_order(intent.id, cart, cart_subtotal, shipping_cost, total_cost, False) return render_template('checkout.html', country=shipping_country, cart_items=cart_items, cart_subtotal=cart_subtotal, shipping_cost=shipping_cost, grand_total=total_cost, client_secret=intent.client_secret, hide_cart=True)
def home(): return render_template('home.html', home_images=crud.get_home_images( crud.new_transaction()), home_text=crud.get_home_text())