Пример #1
0
 def post(self, slug):
     payload = None
     if challenge_exists(slug):
         app.logger.debug('The challenge already exists')
         abort(409, message='This challenge already exists.')
     if not re.match("^[\w\d_-]+$", slug):
         app.logger.debug(
             'The challenge slug should contain only a-z, A-Z, 0-9, _, -')
         abort(400,
               message=
               'The challenge slug should contain only a-z, A-Z, 0-9, _, -')
     try:
         payload = json.loads(request.data)
     except Exception as e:
         app.logger.debug('POST request does not have a JSON payload')
         app.logger.debug(request.data)
         abort(400, message=e)
     if 'title' not in payload:
         app.logger.debug('A new challenge must have title')
         abort(400, message="A new challenge must have title")
     c = Challenge(slug, payload.get('title'))
     c.title = payload.get('title')
     c.geometry = payload.get('geometry')
     c.description = payload.get('description')
     c.blurb = payload.get('blurb')
     c.help = payload.get('help')
     c.instruction = payload.get('instruction')
     c.active = payload.get('active')
     c.difficulty = payload.get('difficulty')
     c.options = payload.get('options')
     db.session.add(c)
     try:
         db.session.commit()
     except Exception as e:
         if type(e) == IntegrityError:
             app.logger.warn(e)
             db.session.rollback()
             abort(
                 409,
                 message=
                 'The session and the database did not agree for challenge {slug}: {message}'
                 .format(slug=c.slug, message=e))
         else:
             app.logger.warn(e)
             abort(500, message=message_internal_server_error)
     return {}, 201
Пример #2
0
 def post(self, slug):
     if challenge_exists(slug):
         abort(409, 'This challenge already exists')
     if not re.match("^[\w\d_-]+$", slug):
         abort(400, 'slug should contain only a-z, A-Z, 0-9, _, -')
     try:
         payload = json.loads(request.data)
     except Exception:
         abort(400, "JSON bad")
     if 'title' not in payload:
         abort(400, "new challenge must have title")
     c = Challenge(slug, payload.get('title'))
     if 'title' in payload:
         c.title = payload.get('title')
     if 'geometry' in payload:
         c.geometry = payload.get('geometry')
     if 'description' in payload:
         c.description = payload.get('description')
     if 'blurb' in payload:
         c.blurb = payload.get('blurb')
     if 'help' in payload:
         c.help = payload.get('help')
     if 'instruction' in payload:
         c.instruction = payload.get('instruction')
     if 'active' in payload:
         c.active = payload.get('active')
     if 'difficulty' in payload:
         c.difficulty = payload.get('difficulty')
     db.session.add(c)
     try:
         db.session.commit()
     except Exception as e:
         if type(e) == IntegrityError:
             app.logger.warn(e.message)
             db.session.rollback()
             abort(
                 409,
                 'the session and the database did not agree: {}'.format(
                     e.message))
         else:
             app.logger.warn(e.message)
             abort(500, 'something unexpected happened')
     return {}, 201
Пример #3
0
 def post(self, slug):
     if challenge_exists(slug):
         abort(409, 'This challenge already exists')
     if not re.match("^[\w\d_-]+$", slug):
         abort(400, 'slug should contain only a-z, A-Z, 0-9, _, -')
     try:
         payload = json.loads(request.data)
     except Exception:
         abort(400, "JSON bad")
     if 'title' not in payload:
         abort(400, "new challenge must have title")
     c = Challenge(slug, payload.get('title'))
     if 'title' in payload:
         c.title = payload.get('title')
     if 'geometry' in payload:
         c.geometry = payload.get('geometry')
     if 'description' in payload:
         c.description = payload.get('description')
     if 'blurb' in payload:
         c.blurb = payload.get('blurb')
     if 'help' in payload:
         c.help = payload.get('help')
     if 'instruction' in payload:
         c.instruction = payload.get('instruction')
     if 'active' in payload:
         c.active = payload.get('active')
     if 'difficulty' in payload:
         c.difficulty = payload.get('difficulty')
     db.session.add(c)
     try:
         db.session.commit()
     except Exception as e:
         if type(e) == IntegrityError:
             app.logger.warn(e.message)
             db.session.rollback()
             abort(409, 'the session and the database did not agree: {}'.format(e.message))
         else:
             app.logger.warn(e.message)
             abort(500, 'something unexpected happened')
     return {}, 201
Пример #4
0
 def post(self, slug):
     payload = None
     if challenge_exists(slug):
         app.logger.debug('The challenge already exists')
         abort(409, message='This challenge already exists.')
     if not re.match("^[\w\d_-]+$", slug):
         app.logger.debug('The challenge slug should contain only a-z, A-Z, 0-9, _, -')
         abort(400, message='The challenge slug should contain only a-z, A-Z, 0-9, _, -')
     try:
         payload = json.loads(request.data)
     except Exception as e:
         app.logger.debug('POST request does not have a JSON payload')
         app.logger.debug(request.data)
         abort(400, message=e)
     if 'title' not in payload:
         app.logger.debug('A new challenge must have title')
         abort(400, message="A new challenge must have title")
     c = Challenge(slug, payload.get('title'))
     c.title = payload.get('title')
     c.geometry = payload.get('geometry')
     c.description = payload.get('description')
     c.blurb = payload.get('blurb')
     c.help = payload.get('help')
     c.instruction = payload.get('instruction')
     c.active = payload.get('active')
     c.difficulty = payload.get('difficulty')
     c.options = payload.get('options')
     db.session.add(c)
     try:
         db.session.commit()
     except Exception as e:
         if type(e) == IntegrityError:
             app.logger.warn(e)
             db.session.rollback()
             abort(409, message='The session and the database did not agree for challenge {slug}: {message}'.format(slug=c.slug, message=e))
         else:
             app.logger.warn(e)
             abort(500, message=message_internal_server_error)
     return {}, 201
Пример #5
0
def load_sampledata(path):

    identifier = 0
    tasks = []
    actions = []
    c = Challenge('test')
    c.title = 'Just a test challenge'

    with open(path, 'rb') as filehandle:
        q = json.load(filehandle)

        for feature in q['features']:
            identifier += 1
            coordinates = feature['geometry']['coordinates']
            shape = Point(coordinates[0], coordinates[1])
            properties = feature['properties']
            t = Task('test',identifier)
            t.location = dumps(shape)
            t.run = 1
            a = Action(t.id, "created")
            tasks.append(t)
            
    print tasks
    
    feedengine = create_engine('postgresql://*****:*****@localhost/maproulette')

    Session = sessionmaker(bind=feedengine)

    session = Session()

    session.add(c)
    session.commit()
    for t in tasks:
        session.add(t)
    for a in actions:
        session.add(a)

    c.active = True
    session.commit()
Пример #6
0
# delete old tasks and challenges
db.session.query(TaskGeometry).delete()
db.session.query(Action).delete()
db.session.query(Task).delete()
db.session.query(Challenge).delete()
db.session.commit()

for i in range(NUM_CHALLENGES):
    print "Generating Test Challenge #", i
    minx = -120
    maxx = -40
    miny = 20
    maxy = 50
    challengepoly = None
    challenge = Challenge('test%i' % (i + 1))
    challenge.title = 'Test Challenge %i' % (i + 1)
    challenge.difficulty = random.choice([1, 2, 3])
    challenge.active = True
    challenge.blurb = 'This is test challenge number %i' % (i + 1, )
    challenge.description = 'This describes test challenge number %i in more detail' % (i + 1, )
    challenge.help = words
    challenge.instruction = words2
    # have bounding boxes for all but the first two challenges.
    if i > 1:
        minx = random.randrange(-120, -40)
        miny = random.randrange(20, 50)
        maxx = minx + 1
        maxy = miny + 1
        challengepoly = box(minx, miny, maxx, maxy)
        print "\tChallenge has a bounding box of ", challengepoly
        challenge.polygon = challengepoly