Skip to content

Commit

Permalink
Use current_access on index views, for JSON support (#446)
Browse files Browse the repository at this point in the history
  • Loading branch information
jace authored Jun 16, 2019
1 parent f02663e commit 3e90323
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
3 changes: 3 additions & 0 deletions funnel/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ class Project(UuidMixin, BaseScopedNameMixin, db.Model):
'_state', 'website', 'bg_image', 'bg_color', 'explore_url', 'tagline', 'absolute_url',
'location', 'calendar_weeks'
},
'call': {
'url_for',
}
}
}

Expand Down
10 changes: 7 additions & 3 deletions funnel/views/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ def home(self):
if featured_project in upcoming_projects:
upcoming_projects.remove(featured_project)
open_cfp_projects = projects.filter(Project.cfp_state.OPEN).order_by(Project.date.asc()).all()
return {'projects': projects.all(), 'all_projects': all_projects,
'upcoming_projects': upcoming_projects, 'open_cfp_projects': open_cfp_projects,
'featured_project': featured_project}

return {
'all_projects': [p.current_access() for p in all_projects],
'upcoming_projects': [p.current_access() for p in upcoming_projects],
'open_cfp_projects': [p.current_access() for p in open_cfp_projects],
'featured_project': featured_project.current_access() if featured_project else None
}


@route('/')
Expand Down
15 changes: 10 additions & 5 deletions funnel/views/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ProfileView(ProfileViewMixin, UrlForView, ModelView):
__decorators__ = [legacy_redirect]

@route('')
@render_with('index.html.jinja2')
@render_with('index.html.jinja2', json=True)
@requires_permission('view')
def view(self):
# `order_by(None)` clears any existing order defined in relationship.
Expand All @@ -82,10 +82,15 @@ def view(self):
upcoming_projects.remove(featured_project)
open_cfp_projects = projects.filter(Project.cfp_state.OPEN).order_by(Project.date.asc()).all()
draft_projects = [proj for proj in self.obj.draft_projects if proj.current_roles.admin]
return {'profile': self.obj, 'projects': projects, 'past_projects': past_projects,
'all_projects': all_projects, 'upcoming_projects': upcoming_projects,
'open_cfp_projects': open_cfp_projects, 'draft_projects': draft_projects,
'featured_project': featured_project}
return {
'profile': self.obj.current_access(),
'past_projects': [p.current_access() for p in past_projects],
'all_projects': [p.current_access() for p in all_projects],
'upcoming_projects': [p.current_access() for p in upcoming_projects],
'open_cfp_projects': [p.current_access() for p in open_cfp_projects],
'draft_projects': [p.current_access() for p in draft_projects],
'featured_project': featured_project.current_access()
}

@route('json')
@render_with(json=True)
Expand Down
1 change: 0 additions & 1 deletion funnel/views/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ def updates(self):
next.end = localize_date(next.end, to_tz=self.obj.venue.project.timezone)
nextdiff = next.start.date() - now.date()
nextdiff = nextdiff.total_seconds() / 86400
print current, next
return dict(room=self.obj, current=current, next=next, nextdiff=nextdiff)


Expand Down

0 comments on commit 3e90323

Please sign in to comment.