def view_sites(): form = SiteForm() if form.validate_on_submit(): Site.create(owner=current_user, **form.data) flash("Added site") return redirect(url_for(".view_sites")) query = Site.query.filter(Site.user_id == current_user.id) data = query_to_list(query) results = [] try: # The header row should not be linked results = [next(data)] for row in data: row = [_make_link(cell) if i == 0 else cell for i, cell in enumerate(row)] results.append(row) except StopIteration: # This happens when a user has no sites registered yet # Since it is expected, we ignore it and carry on. pass return render_template("analytics/sites.html", sites=results, form=form)
def view_site_visits(site_id=None): site = Site.get_or_404(site_id) if not site.user_id == current_user.id: abort(401) query = Visit.query.filter(Visit.site_id == site_id) data = query_to_list(query) return render_template("analytics/site.html", visits=data, site=site)