Skip to content

Commit

Permalink
Only streaming some pages
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbyt3r committed Oct 17, 2024
1 parent d41eb2e commit d14c59d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
21 changes: 20 additions & 1 deletion uber/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,8 @@ def renderable_data(data=None):


# render using the first template that actually exists in template_name_list
def render(template_name_list, data=None, encoding='utf-8'):
# Returns a generator that streams the template result to the client
def render_stream(template_name_list, data=None, encoding='utf-8'):
data = renderable_data(data)
env = JinjaEnv.env()
template = env.get_or_select_template(template_name_list)
Expand All @@ -585,6 +586,17 @@ def render(template_name_list, data=None, encoding='utf-8'):
return rendered


# render using the first template that actually exists in template_name_list
def render(template_name_list, data=None, encoding='utf-8'):
data = renderable_data(data)
env = JinjaEnv.env()
template = env.get_or_select_template(template_name_list)
rendered = template.render(data)
if encoding:
return rendered.encode(encoding)
return rendered


def render_empty(template_name_list):
env = JinjaEnv.env()
template = env.get_or_select_template(template_name_list)
Expand Down Expand Up @@ -653,12 +665,19 @@ def with_rendering(*args, **kwargs):
if c.UBER_SHUT_DOWN and not cherrypy.request.path_info.startswith('/schedule'):
return render('closed.html')
elif isinstance(result, dict):
cp_config = getattr(func, "_cp_config", {})
if cp_config.get("response.stream", False):
return render_stream(_get_template_filename(func), result)
return render(_get_template_filename(func), result)
else:
return result

return with_rendering

def streamable(func):
func._cp_config = getattr(func, "_cp_config", {})
func._cp_config['response.stream'] = True
return func

def public(func):
func.public = True
Expand Down
4 changes: 2 additions & 2 deletions uber/site_sections/reg_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from sqlalchemy.orm import subqueryload

from uber.config import c
from uber.decorators import all_renderable, log_pageview
from uber.decorators import all_renderable, log_pageview, streamable
from uber.models import Attendee, Group, PromoCode, ReceiptTransaction, ModelReceipt


Expand Down Expand Up @@ -38,6 +38,7 @@ def found_how(self, session):
key=lambda s: s.lower())}

@log_pageview
@streamable
def attendee_receipt_discrepancies(self, session, include_pending=False, page=1):
filters = [Attendee.default_cost_cents != ModelReceipt.item_total]
if include_pending:
Expand All @@ -60,7 +61,6 @@ def attendee_receipt_discrepancies(self, session, include_pending=False, page=1)
'attendees': receipt_query.limit(50).offset(offset),
'include_pending': include_pending,
}
attendee_receipt_discrepancies._cp_config = {'response.stream': True}

@log_pageview
def attendees_nonzero_balance(self, session, include_no_receipts=False):
Expand Down

0 comments on commit d14c59d

Please sign in to comment.