Skip to content

Commit

Permalink
Order cards with no controls for orders received yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
mariamrf committed May 3, 2017
1 parent 3505d39 commit cbf07fd
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 7 deletions.
13 changes: 13 additions & 0 deletions yadawia/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ def paragraph(text):
"""TEMPLATE FILTER: Replace newlines with <br /> in html."""
return text.replace('\n', '<br />')

@app.template_filter('order_total')
def order_total(order):
"""TEMPLATE FILTER: Get order total given the order object."""
total = {}
strings = []
for product in order.products.all():
if product.currency_id in total:
total[product.currency_id] += product.price * product.quantity
else:
total[product.currency_id] = product.price * product.quantity
for key, val in total.items():
strings.append(str(val) + ' ' + key)
return ' + '.join(strings)

app.jinja_env.globals['csrf_token'] = yadawia.helpers.generate_csrf_token
"""Whenever `{{ csrf_token() }}` is used in a Jinja2 template, it returns the result of the function `generate_csrf_token()` """
6 changes: 2 additions & 4 deletions yadawia/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,7 @@ class Product(db.Model):
cascade='save-update, merge, delete')
reviews = db.relationship('Review', backref='product', lazy='dynamic',
cascade='save-update, merge, delete')
orders = db.relationship('Order', secondary='order_product',
back_populates='products', lazy='dynamic')
order_products = db.relationship('OrderProduct', backref='details', lazy='dynamic')
available = db.Column(db.Boolean, default=True, nullable=False)
force_unavailable = db.Column(db.Boolean, default=False, nullable=False)

Expand Down Expand Up @@ -437,8 +436,7 @@ class Order(db.Model):
status = db.Column(db.String, default='New')
address_id = db.Column(db.Integer, db.ForeignKey('addresses.id'))
payment_method_id = db.Column(db.Integer, db.ForeignKey('payment_methods.id'))
products = db.relationship('Product', secondary='order_product',
back_populates='orders', lazy='dynamic')
products = db.relationship('OrderProduct', backref='order', lazy='dynamic')
message_threads = db.relationship(
'MessageThread', backref='order', lazy='dynamic')

Expand Down
23 changes: 23 additions & 0 deletions yadawia/static/css/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,29 @@
- Text Grey: rgb(51,51,51);
*/

.order-card {
background-color: #eee;
padding: 1em;
box-shadow: 1px 3px 4px 1px rgba(51,51,3,0.3);
margin-bottom: 2em;
}

.order-card .order-status-disp {
background-color: rgb(237,216,52);
padding: 0.5em;
border-radius: 0.5em;
font-weight: bold;
float: right;
text-transform: uppercase;
}

.order-card p {
text-transform: uppercase;
font-size: 0.8em;
margin-top: 1em;
font-weight: bold;
}

.success {
color: rgba(39,174,96,1.0); /* SUCCESS GREEN */
font-size: 2em;
Expand Down
6 changes: 6 additions & 0 deletions yadawia/static/js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,12 @@ $(function(){

$('#logout', '.menu').parent().attr('href', Flask.url_for('logout', { next: window.location.href }));

$('.date-to-now').each(function(){
var md = momentDate($(this).text());
$(this).attr('title', md.formatted);
$(this).text(md.fromNow);
});

// CHECK AVAILABILITY (FOR EMAIL AND USERNAME FIELDS)
$('.feedback-elem').bind('blur', function(){
var field = this;
Expand Down
14 changes: 14 additions & 0 deletions yadawia/templates/macros.html
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,18 @@ <h5>{{ product.name }}</h5>
<input type="submit" class="btn btn-default submit" value="Search">
</div>
</form>
{% endmacro %}

{% macro order_card(order) %}
<li class="order-card">
<h4>Order #{{ order.id }} <small>Last updated: <span class="date-to-now">{{ order.update_date }}</span><span class="order-status-disp">{{ order.status }}</span></small></h4>
<ul>
{% for product in order.products.all() %}
<li><b>{{ product.details.name }} ({{ product.variety.name }})</b> X {{ product.quantity }} = {{ product.quantity * product.price }} {{ product.currency_id }}</li>
{% endfor %}
</ul>
<p>Total: {{ order | order_total }}</p>
<p>Address: {{ order.address.name }}</p>
<p>Order created: <span class="date-to-now">{{ order.create_date }}</span></p>
</li>
{% endmacro %}
20 changes: 19 additions & 1 deletion yadawia/templates/order_history.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends 'layout.html' %}
{% from 'macros.html' import settings_nav with context %}
{% from 'macros.html' import settings_nav, order_card with context %}

{% block extend_title %}
| Orders
Expand All @@ -19,9 +19,27 @@ <h2><i class="fa fa-history"></i> Order History</h2>
</div>
<div id="orders-by-you" class="col-xs-12 col-md-8 settings-section-wrapper">
<h2>By You <small>{{ by_you | length }}</small></h2>
{% if by_you | length > 0 %}
<ul class="list-unstyled">
{% for order in by_you %}
{{ order_card(order) }}
{% endfor %}
</ul>
{% else %}
<h3><small>You haven't placed any orders yet.</small></h3>
{% endif %}
</div>

<div id="orders-for-you" class="col-xs-12 col-md-8 settings-section-wrapper" style="display:none;">
<h2>For You <small>{{ for_you | length }}</small></h2>
{% if for_you | length > 0 %}
<ul class="list-unstyled">
{% for order in for_you %}
{{ order_card(order) }}
{% endfor %}
</ul>
{% else %}
<h3><small>You haven't received any orders yet.</small></h3>
{% endif %}
</div>
{% endblock %}
5 changes: 3 additions & 2 deletions yadawia/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ def checkout():
@authenticate
def order_history():
"""Get someone's order history. Orders by them, and orders for them."""
for_you = Order.query.join(OrderProduct).join(Product).filter_by(seller_id=session['userId']).all()
by_you = Order.query.filter_by(user_id=session['userId']).all()
for_you = Order.query.join(OrderProduct).join(Product).\
filter_by(seller_id=session['userId']).order_by(Order.create_date.desc()).all()
by_you = Order.query.filter_by(user_id=session['userId']).order_by(Order.update_date.desc()).all()
return render_template('order_history.html', for_you=for_you, by_you=by_you)

0 comments on commit cbf07fd

Please sign in to comment.