예제 #1
0
    def post(self):
        # Ensuer the user can add an outing
        if not hu.userIsAuthorized(self, uau.poster):
            return

        # Get the data
        outingName, description, departureTime, returnTime, meetLocation, outingLocation, showcase = hu.getQueryValues(
            self,
            [ 'i_outing_name',
              'ta_description',
              'i_departure_time',
              'i_return_time',
              'i_meet_location',
              'i_outing_location',
              'i_showcase' ])

        departureTime = du.tryHtmlDatetimeToPythonDatetime(departureTime)
        returnTime = du.tryHtmlDatetimeToPythonDatetime(returnTime)
        showcase = True if showcase == 'True' else False

        valid, errorMessage = ou.outingParametersAreValid(outingName, description, departureTime, returnTime, meetLocation, outingLocation, showcase)

        # If all parameters are valid, then create and store the outing
        if valid:
            creatorId = ''
            try:
                uau.getLoggedInUser(self).key().id()
            except:
                logging.info('Warning: could not determine logged in user when creating outing.')

            newOuting = ou.createOuting(outingName, description, departureTime, returnTime, meetLocation, outingLocation, showcase, creatorId)
            newOuting.put()

            time.sleep(0.25)
            self.redirect('/outings')
            return

        # Otherwise, tell the user what the errors are
        else:    
            departureTime = du.tryPythonDatetimeToHtmlDatetime(departureTime)
            returnTime = du.tryPythonDatetimeToHtmlDatetime(returnTime)

            contentTemplateValues = {
                'outings_buttons_top': ou.getOutingButtonsTop(self),
                'outing_name': outingName,
                'description': description,
                'departure_time': departureTime,
                'error_message': jtr.getRenderedErrorMessage(errorMessage),
                'meet_location': meetLocation,
                'outing_location': outingLocation,
                'return_time': returnTime,
                'showcase': showcase
            }

            # Render the page
            jtr.renderContentAndPage(self, pathToContent, contentFilename, contentTemplateValues, pageTemplateValues)
예제 #2
0
def getOutingButtonsTop(handler):
    """
    Renders and returns the buttons for the top of an outings page.

    handler: the current page handler

    returns: string
    """
    # Determine if the user can add an outing
    loggedInUser = uau.getLoggedInUser(handler)
    canAddOuting = False
    if loggedInUser != None and uau.doesUserHavePermission(loggedInUser.accountLevel, uau.poster):
        canAddOuting = True

    # Get the rendered buttons
    return jtr.getRenderedTemplate(pathToOutingTemplates, buttonsTopTemplateName, { 'can_add_outing': canAddOuting })
예제 #3
0
def userIsAuthorized(handler, requiredAccountLevel):
    """    
    Determines whether the current user's account level meets the required account level.
    If the user does not, sets the redirect flags to the unauthroized page. Usually, if this
    method returns false the caller will want to immediately return.

    handler: the current page handler
    requiredAccountLevel: the required level

    returns: bool
    """
    currentUser = uau.getLoggedInUser(handler)
    userAccountLevel = uau.loggedOut    
    if currentUser != None:
        userAccountLevel = currentUser.accountLevel

    if not uau.doesUserHavePermission(userAccountLevel, requiredAccountLevel):
        handler.redirect('/unauthorized')
        return False

    return True
def getRenderedPage(handler, templateValues):
    """
    Renders and returns page_base.html after inserting the template values. The templateValues
    dictionary should contain 'page_title', 'content_title', 'content', optionally
    'login_redirect_link', 'scripts' and 'stylesheets', and no other values. Any additional templating
    to be done to 'content' should be done before calling this method.

    handler: the current page handler
    templateValues: a dictionary of values for the template

    returns: string
    """
    # Get an environment for the html blocks
    jinjaEnv = getJinjaEnv(os.path.join(rh.rootDir, 'html/templates'))

    # Get the current user
    currentUser = uau.getLoggedInUser(handler)

    # Render the buttons_top
    tempVals = {
        'user': '******',
        'logged_in': False
    }

    if 'login_redirect_link' in templateValues.keys():
        # Get the login redirect link if possible
        tempVals['login_redirect_link'] = templateValues['login_redirect_link']
        
    if currentUser != None:
        # Get the user information if possible
        tempVals['user'] = '******' % (currentUser.firstName, currentUser.lastName)
        tempVals['logged_in'] = True
    
    templateValues['buttons_top'] = getRenderedTemplateWithEnvironment(jinjaEnv, 'buttons_top.html', tempVals)
        
    # Render the buttons_side
    templateValues['buttons_side'] = getRenderedTemplateWithEnvironment(jinjaEnv, 'buttons_side.html')

    # Render page_base.html
    return getRenderedTemplateWithEnvironment(jinjaEnv, 'page_base.html', templateValues)