Skip to content

Commit

Permalink
only show items with pictures on purchase page
Browse files Browse the repository at this point in the history
now this adds a problem if the user has no recently purchased items with
pictures, as the heading will still be there with it empty. because this
was implemented as a generator i don't know how to fix it.
  • Loading branch information
bradjc committed Sep 4, 2016
1 parent b78cf31 commit ba470c0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions chezbetty/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,20 +270,25 @@ def get_user_count_cumulative(cls):
.all()
return utility.timeseries_cumulative(rows)

def iterate_recent_items(self, limit=None, allow_duplicates=False):
def iterate_recent_items(self, limit=None, allow_duplicates=False, pictures_only=True):
cap_search = 20
items = set()
count = 0
for e in self.events:
if e.type == 'purchase':
for transaction in e.transactions:
if transaction.type == 'purchase':
for line_item in transaction.subtransactions:
cap_search -= 1
if cap_search == 0:
return
if (line_item.item not in items) or allow_duplicates:
count += 1
if limit is not None and count > limit:
return
yield line_item.item
items.add(line_item.item)
if (line_item.item.img) or not pictures_only:
count += 1
if limit is not None and count > limit:
return
yield line_item.item
items.add(line_item.item)

def __make_salt(self):
return binascii.b2a_base64(open("/dev/urandom", "rb").read(32))[:-3].decode("ascii")
Expand Down
2 changes: 1 addition & 1 deletion chezbetty/templates/terminal/terminal.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@

{# Recently purchased items #}
<hr />
<h4>Quick-Select Most Recently Purchased Items</h4>
<h4>Quick-Select Some Recently Purchased Items</h4>
<div id="recently-purchased" class="row">
<div class="col-md-1"></div>
{% for item in user.iterate_recent_items(limit=5) %}
Expand Down

0 comments on commit ba470c0

Please sign in to comment.