def permissionMessage(request, site, p): if request.user.is_authenticated: msg = """ <div class="system_message"> <h2> Restricted page</h2> <p>This page can only be viewed by participants of this project to view this page please make sure of the following:</p> <ul> <li>First, log in to {} by using the 'Sign in' button at the top right.</li> <li>Second, you need to join / register with the specific project you are interested in as a participant. The link to do this is provided by the project organizers on the project website.</li> </ul> <div> """.format( settings.MAIN_PROJECT_NAME ) title = p.title else: msg = ( "The page '" + p.title + "' can only be viewed by registered users. Please sign in to view this page." ) title = p.title return ErrorPage(challenge=site, title=title, html=msg)
def site(request, challenge_short_name): # TODO: Doing two calls to getSite here. (second one in site_get_standard_vars) # How to handle not found nicely? Throwing exception in site_get_standard_vars # seems like a nice start, but this function is called throughout the code # also outside views (in contextprocessor). Throwing Http404 there will # result in server error.. try: site = getSite(challenge_short_name) except Challenge.DoesNotExist: raise Http404("Project %s does not exist" % challenge_short_name) [site, pages, metafooterpages] = site_get_standard_vars( challenge_short_name ) if len(pages) == 0: page = ErrorPage( challenge=site, title="no_pages_found", html="No pages found for this site. Please log in and use the admin button to add pages.", ) currentpage = page else: currentpage = pages[0] currentpage = getRenderedPageIfAllowed(currentpage, request, site) return render( request, 'page.html', {'site': site, 'currentpage': currentpage, "pages": pages}, )
def get_object(self, queryset=None): page = self.request.challenge.page_set.first() if page is None: page = ErrorPage( challenge=self.request.challenge, title="No Pages Found", html="No pages found for this site. Please log in and add some pages.", ) return page
def challenge_homepage(request): challenge = request.challenge pages = challenge.page_set.all() if len(pages) == 0: currentpage = ErrorPage( challenge=challenge, title="no_pages_found", html="No pages found for this site. Please log in and add some pages.", ) else: currentpage = pages[0] currentpage = getRenderedPageIfAllowed(currentpage, request) return render( request, "page.html", {"challenge": challenge, "currentpage": currentpage, "pages": pages}, )
def site(request, challenge_short_name): try: site = getSite(challenge_short_name) except Challenge.DoesNotExist: raise Http404("Project %s does not exist" % challenge_short_name) pages = site.page_set.all() if len(pages) == 0: currentpage = ErrorPage( challenge=site, title="no_pages_found", html="No pages found for this site. Please log in and add some pages.", ) else: currentpage = pages[0] currentpage = getRenderedPageIfAllowed(currentpage, request, site) return render( request, "page.html", {"site": site, "currentpage": currentpage, "pages": pages}, )