Exemple #1
0
def on_event_request():
    ''' Receives GET requests from the user to setup subscriptions. '''

    # Does the user want a linked outpage to make it easier to link to?
    htmlPage = bool(request.query.html)
    event = None

    tag = request.query.tag
    lat, lon, radius = subscriptionWorker.checkGeos(request.query.lat,
                                                    request.query.lon,
                                                    request.query.radius)

    if tag and len(tag) > 0:
        event = {'object': 'tag', 'tag': tag.lower()}

    elif lat and lon and radius:

        # Convert the incoming metres radius to degrees
        latRad, lonRad = crowdedWorker.radialToLinearUnits(float(lat))
        scale = (latRad + lonRad) / 2.0
        radius = float(radius) / scale

        event = {
            'object': 'geography',
            'lat': float(lat),
            'lon': float(lon),
            'radius': float(radius)
        }

    else:
        print 'Must specify a lat/lon/radius or tag.'
        redirect("/help")
        return

    if not event:
        response = {'success': False}
    # Get the response form updating the backend records
    else:
        response = subscriptionWorker.buildSubscription(event)

        # Now get something populated in that so that its not blank
        subInfo = [{
            "object": response['object'],
            "object_id": response['objectId']
        }]
        crowdedWorker.main(p, json.dumps(subInfo))

    # A user linked page for getting to the event splash page
    if response.has_key('url') and response['success'] == True:
        if htmlPage == True:
            output = template("goToEventPage",
                              objectId=response['objectId'],
                              eventPage=response['url'],
                              helpPage=p.helpUrl)
        else:
            output = json.dumps(response)
    else:
        redirect("/help")

    return output
Exemple #2
0
def on_event_request():
    ''' Receives GET requests from the user to setup subscriptions. '''

    # Does the user want a linked outpage to make it easier to link to?
    htmlPage = bool(request.query.html)
    event = None
    
    tag    = request.query.tag
    lat, lon, radius = subscriptionWorker.checkGeos(request.query.lat, request.query.lon, request.query.radius)
    
    if tag and len(tag) > 0:
        event = {'object' : 'tag',
                 'tag'    :  tag.lower()}
    
    elif lat and lon and radius:
        
        # Convert the incoming metres radius to degrees
        latRad, lonRad = crowdedWorker.radialToLinearUnits(float(lat))
        scale = (latRad+lonRad)/2.0
        radius = float(radius)/scale
        
        event = {'object' : 'geography',
                 'lat'    : float(lat),
                 'lon'    : float(lon),
                 'radius' : float(radius)}    
    
    else:
        print 'Must specify a lat/lon/radius or tag.'
        redirect("/help")
        return
    
    if not event:
        response = {'success': False}
    # Get the response form updating the backend records
    else:
        response = subscriptionWorker.buildSubscription(event)
        
        # Now get something populated in that so that its not blank
        subInfo = [{"object" : response['object'], "object_id" : response['objectId']}]
        crowdedWorker.main(p, json.dumps(subInfo))
    
    # A user linked page for getting to the event splash page
    if response.has_key('url') and response['success']==True:
        if htmlPage == True:
            output = template("goToEventPage",
                              objectId=response['objectId'],
                              eventPage=response['url'],
                              helpPage=p.helpUrl)
        else:
            output = json.dumps(response)
    else:
        redirect("/help")
        
    return output
Exemple #3
0
def on_event_callback():
    ''' The function that does both the subscription authorisation - a response to their server
        and receives the POST payload to get the update messages for building endpoint fetches'''

    # Challenge to be responded to - this allows subscriptions to be setup
    challenge = request.GET.get("hub.challenge")
    if challenge:
        return challenge

    # If its a POST, get the payload
    try:
        raw_response = request.body.read()
    except:
        on_error(message='Failed on body read request.')

    # Make sure that the payload exists
    if raw_response == None:
        on_error(message='Failed on body read request.')
    else:
        crowdedWorker.main(p, raw_response)
Exemple #4
0
def on_event_callback():
    ''' The function that does both the subscription authorisation - a response to their server
        and receives the POST payload to get the update messages for building endpoint fetches'''
    
    # Challenge to be responded to - this allows subscriptions to be setup
    challenge = request.GET.get("hub.challenge")
    if challenge: 
        return challenge

    # If its a POST, get the payload
    try:
        raw_response = request.body.read()
    except:
        on_error(message='Failed on body read request.')
    
    # Make sure that the payload exists
    if raw_response == None:
        on_error(message='Failed on body read request.')
    else:
        crowdedWorker.main(p, raw_response)