def url_for_school(endpoint, school=None, user_school=False, **values):
	""" Similar to typical url for, except this will rewrite the base to the specified school """
	url = url_for(endpoint, **values)
	csn = g.school.name # current school name
	fsn = school.name if hasattr(school,'name') else school # future school name
	if fsn is None and user_school:
		u = current_user._get_current_object()
		c = get_school_context(u)
		if c:
			fsn = c.name
	# The name of the default school never appears in the path: it is always the base url
	if school == g.default_school:
		fsn = None
	# Requesting the default/ global school
	if fsn is None:
		if g.is_default_school:
			return url
		else:
			return url.replace('/'+csn, '', 1)
	# Requesting a particular school
	else:
		if csn==fsn:
			return url
		elif g.is_default_school:
			return url.replace('/', '/'+fsn+'/', 1)
		else:
			return url.replace('/'+csn, '/'+fsn, 1)
def url_for_school(endpoint, school=None, user_school=False, **values):
    """ Similar to typical url for, except this will rewrite the base to the specified school """
    url = url_for(endpoint, **values)
    csn = g.school.name  # current school name
    fsn = school.name if hasattr(school,
                                 'name') else school  # future school name
    if fsn is None and user_school:
        u = current_user._get_current_object()
        c = get_school_context(u)
        if c:
            fsn = c.name
    # The name of the default school never appears in the path: it is always the base url
    if school == g.default_school:
        fsn = None
    # Requesting the default/ global school
    if fsn is None:
        if g.is_default_school:
            return url
        else:
            return url.replace('/' + csn, '', 1)
    # Requesting a particular school
    else:
        if csn == fsn:
            return url
        elif g.is_default_school:
            return url.replace('/', '/' + fsn + '/', 1)
        else:
            return url.replace('/' + csn, '/' + fsn, 1)
Beispiel #3
0
def detail(id):
    """ Show a single userproposal, redirecting to the appropriate school if necessary """
    u = User.objects.get_or_404(id=id)
    c = get_school_context(u)
    if not g.school == c:
        flash(_("You've been redirected to the school the user is following."))
        return redirect(url_for_school('users.detail', school=c, id=u.id),
                        code=301)
    return render_template('user/detail.html', title=u.display_name, user=u)
def detail(id):
	""" Show a single userproposal, redirecting to the appropriate school if necessary """
	u = User.objects.get_or_404(id=id)
	c = get_school_context(u)
	if not g.school==c:
		flash(_("You've been redirected to the school the user is following."))
		return redirect(url_for_school('users.detail', school=c, id=u.id), code=301)
	return render_template('user/detail.html',
		title = u.display_name,
		user = u)
Beispiel #5
0
def detail(id):
	""" Show a detail of an event """
	e = Event.objects.get_or_404(id=id)
	c = get_school_context(e)
	if not g.school==c:
		flash(_("You've been redirected to the school where the class is happening."))
		return redirect(url_for_school('events.detail', school=c, id=e.id), code=301)
	# Passing some permissions related functions on to Jinja
	current_app.jinja_env.globals['can_edit'] = can_edit
	return render_template('event/detail.html',
		title = e.title,
		event = e,
		other_events = []) #other_events(e))
def detail(id):
	""" Show a single discussion, redirecting to the appropriate school if necessary """
	d = Discussion.objects.get_or_404(id=id)
	context = get_school_context(d)
	if not g.school==context:
		flash(_("You've been redirected to where the discussion was created."))
		return redirect(url_for_school('discussions.detail', school=context, id=d.id), code=301)
	other_schools = [school for school in d.schools if not school==context]
	comments = Comment.objects.filter(discussion=d).order_by('-created')
	# Passing some permissions related functions on to Jinja
	#current_app.jinja_env.globals['can_edit_proposal'] = can_edit_proposal
	return render_template('discussion/detail.html',
		title = d.title,
		discussion = d,
		comments = comments,
		other_schools = other_schools)
Beispiel #7
0
def detail(id):
	""" Show a single proposal, redirecting to the appropriate school if necessary """
	p = Proposal.objects.get_or_404(id=id)
	c = get_school_context(p)
	if not g.school==c:
		flash(_("You've been redirected to where the proposal was made."))
		return redirect(url_for_school('proposals.detail', school=c, id=p.id), code=301)
	other_schools = [school for school in p.schools if not school==c]
	# Passing some permissions related functions on to Jinja
	current_app.jinja_env.globals['can_edit_proposal'] = can_edit_proposal
	current_app.jinja_env.globals['can_organize_proposal'] = can_organize_proposal
	return render_template('proposal/detail.html',
		title = p.title,
		proposal = p,
		other_schools = other_schools,
		events = p.events,
		discussions = p.discussions)
Beispiel #8
0
def detail(id):
	""" Show a single collection, redirecting to the appropriate school if necessary """
	c = Collection.objects.get_or_404(id=id)
	context = get_school_context(c)
	if not g.school==context:
		flash(_("You've been redirected to where the proposal was made."))
		return redirect(url_for_school('collections.detail', school=context, id=c.id), code=301)
	other_schools = [school for school in c.schools if not school==context]
	# Passing some permissions related functions on to Jinja
	#current_app.jinja_env.globals['can_edit_proposal'] = can_edit_proposal
	#current_app.jinja_env.globals['can_organize_proposal'] = can_organize_proposal
	return render_template('collection/detail.html',
		title = c.title,
		collection = c,
		proposals = c.all_proposals(),
		events = c.all_events(),
		other_schools = other_schools)
Beispiel #9
0
def detail(id):
    """ Show a single discussion, redirecting to the appropriate school if necessary """
    d = Discussion.objects.get_or_404(id=id)
    context = get_school_context(d)
    if not g.school == context:
        flash(_("You've been redirected to where the discussion was created."))
        return redirect(url_for_school('discussions.detail',
                                       school=context,
                                       id=d.id),
                        code=301)
    other_schools = [school for school in d.schools if not school == context]
    comments = Comment.objects.filter(discussion=d).order_by('-created')
    # Passing some permissions related functions on to Jinja
    #current_app.jinja_env.globals['can_edit_proposal'] = can_edit_proposal
    return render_template('discussion/detail.html',
                           title=d.title,
                           discussion=d,
                           comments=comments,
                           other_schools=other_schools)