def get(self, title): serie = Serie.get_by_id(title) if not serie: helpers.make_not_found_exception('Serie %s not found' % title) issues = Issue.query(Issue.serie == serie.key).fetch() return helpers.make_response(issues, model.Issue.FIELDS)
def welcome(): user_db = auth.current_user_db() today = datetime.date.today() week_start = today - timedelta(days=today.weekday()) week_end = week_start + timedelta(days=6) # list_keys = list_query.fetch(keys_only=True) # maybe put a limit here. # # list_keys = random.sample(list_keys, 20) # issue_dbs = [list_key.get() for list_key in list_keys] user_issues = [] if user_db is not None: if user_db.series_list: for serie in user_db.series_list: serie_6_issues = Issue.query(Issue.serie == serie).order(-Issue.date).fetch(limit=6) user_issues += serie_6_issues # if user_db.buy_list: # current_week += Issue.query(Issue.key.IN(user_db.buy_list)) # # next_weeks = Issue.query( # ndb.AND(Issue.serie.IN(user_db.series_list), # Issue.date > week_end # ) # ).order(Issue.date).fetch() # for issue in user_issues: # print(issue.title.encode()) return flask.render_template('welcome.html', html_class='welcome', user_db=user_db, user_issues=user_issues, )
def issue_page(title): title = urllib.unquote_plus(title) issues = Issue.query(Issue.title == title).fetch() for issue in issues: if len(issue.summary) == 0: parser = Parser() parser.parse_issue_summary(issue) return flask.render_template('issue_page.html', issues=issues)
def cart_page(): user_db = auth.current_user_db() cart = [] if user_db.cart: cart = Issue.query(Issue.key.IN( user_db.cart)).order(-Issue.date).fetch() else: flask.abort(404) return flask.render_template('cart_page.html', cart=cart, user_db=user_db)
def purchased_page(): user_db = auth.current_user_db() purchased = [] if user_db.purchased_list: purchased = Issue.query(Issue.key.IN( user_db.purchased_list)).order(-Issue.date).fetch() else: flask.abort(404) return flask.render_template('purchased_page.html', purchased=purchased, user_db=user_db)
def purchased_list_del(): title = request.form['issue_title'] issue = Issue.query(Issue.title == title).get(keys_only=True) user_db = auth.current_user_db() if (issue is not None) & (issue in user_db.purchased_list): user_db.purchased_list.remove(issue) user_db.put() app.logger.debug("issue removed from purchased list: %s" % title) else: app.logger.error("issue %s not found" % title) return flask.redirect(flask.url_for('purchased_page'))
def serie_page(title): user_db = auth.current_user_db() serie = [] if title: serie = Issue.query( Issue.serie == ndb.Key(Serie, title)).order(-Issue.date).fetch() if not serie: abort(404) return flask.render_template('serie_page.html', title=title, serie=serie, user_db=user_db)
def cart_add(): title = request.form['issue_title'] issue = Issue.query(Issue.title == title).get(keys_only=True) app.logger.debug("%s" % issue) user_db = auth.current_user_db() if (issue is not None) & (issue not in user_db.cart): user_db.cart.append(issue) user_db.put() app.logger.debug("issue added to cart: %s" % title) else: app.logger.error("user: %s \tissue %s not found" % (user_db.name, title)) return flask.redirect(flask.url_for('welcome'))
def all_series(): user_db = auth.current_user_db() issues = [] series = Serie.query().fetch(keys_only=True) if not series: abort(404) for serie in series: serie_6_issues = Issue.query( Issue.serie == serie).order(-Issue.date).fetch(limit=6) issues += serie_6_issues return flask.render_template('all_series_page.html', series=series, user_db=user_db, issues=issues)