示例#1
0
 def put(self, slug):
     exists = challenge_exists(slug)
     try:
         payload = json.loads(request.data)
     except Exception:
         abort(400, "JSON bad")
     if not exists and 'title' not in payload:
         abort(400, "No title")
         return {}
     if exists:
         app.logger.debug('challenge existed, retrieving')
         c = get_challenge_or_404(slug, abort_if_inactive=False)
         if 'title' in payload:
             c.title = payload.get('title')
     else:
         c = Challenge(slug, 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)
     db.session.commit()
     return {}
示例#2
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
示例#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):
     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
示例#5
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
示例#6
0
 def put(self, slug):
     if challenge_exists(slug):
         return {}
     try:
         payload = json.loads(request.data)
     except Exception:
         abort(400)
     if not 'title' in payload:
         abort(400)
     c = Challenge(
         slug,
         payload.get('title'),
         payload.get('geometry'),
         payload.get('description'),
         payload.get('blurb'),
         payload.get('help'),
         payload.get('instruction'),
         payload.get('active'),
         payload.get('difficulty'))
     db.session.add(c)
     db.session.commit()
     return {}
示例#7
0
 def put(self, slug):
     if challenge_exists(slug):
         app.logger.debug('challenge exists')
         abort(400)
     try:
         payload = json.loads(request.data)
     except Exception:
         app.logger.debug('payload invalid, no json')
         abort(400)
     if not 'title' in payload:
         app.logger.debug('payload invalid, no title')
         abort(400)
     c = Challenge(
         slug,
         payload.get('title'),
         payload.get('geometry'),
         payload.get('description'),
         payload.get('blurb'),
         payload.get('help'),
         payload.get('instruction'),
         payload.get('active'),
         payload.get('difficulty'))
     db.session.add(c)
     db.session.commit()