Ejemplo n.º 1
0
 def get(self):
     # TODO: refactor, this is messy
     categories = {}
     for cat in models.Category.query.all():
         challenges = []
         for q in cat.challenges:
             attachments = []
             for a in q.attachments:
                 attachments.append({
                     'aid': a.aid,
                     'filename': a.filename,
                     'content_type': a.content_type,
                 })
             challenges.append({
                 'cid': q.cid,
                 'category': cat.slug,
                 'name': q.name,
                 'description': q.description,
                 'points': q.points,
                 'answer_hash': q.answer_hash,
                 'attachments': attachments,
                 'prerequisite': q.prerequisite,
                 'weight': q.weight,
             })
         categories[cat.slug] = {
             'name': cat.name,
             'description': cat.description,
             'challenges': challenges,
             'slug': cat.slug,
         }
     return (
         {'categories': categories},
         200,
         {'Content-Disposition': 'attachment; filename=challenges.json'})
Ejemplo n.º 2
0
 def get(self):
     # TODO: refactor, this is messy
     categories = {}
     for cat in models.Category.query.all():
         challenges = []
         for q in cat.challenges:
             attachments = []
             for a in q.attachments:
                 attachments.append({
                     'aid': a.aid,
                     'filename': a.filename,
                     'content_type': a.content_type,
                 })
             challenges.append({
                 'cid': q.cid,
                 'category': cat.slug,
                 'name': q.name,
                 'description': q.description,
                 'points': q.points,
                 'answer_hash': q.answer_hash,
                 'attachments': attachments,
                 'prerequisite': q.prerequisite,
                 'weight': q.weight,
             })
         categories[cat.slug] = {
             'name': cat.name,
             'description': cat.description,
             'challenges': challenges,
             'slug': cat.slug,
         }
     return (
         {'categories': categories},
         200,
         {'Content-Disposition': 'attachment; filename=challenges.json'})