diff --git a/server.py b/server.py index 397d61b..f62a09c 100755 --- a/server.py +++ b/server.py @@ -192,69 +192,40 @@ def tasks(): user = get_user() userCount = db['users'].count() + isAdmin = user['isAdmin'] categories = db['categories'] catCount = categories.count() flags = db['flags'] - tasks = db.query("SELECT * FROM tasks ORDER BY category, score"); - - tasks = list(tasks) + tasks = db['tasks'] grid = [] - rowCount = 0 - currentCat = 0 - currentCatCount = 0 - - if len(tasks) == 0: - row = [None] * catCount - grid.append(row) - - for task in tasks: - cat = task["category"] - 1 - - while currentCatCount + 1 >= rowCount: - row = [None] * catCount - grid.append(row) - rowCount += 1 - - if currentCat != cat: - if user['isAdmin']: - endTask = { "end": True, "category": currentCat } - grid[currentCatCount][currentCat] = endTask - currentCat = cat - currentCatCount = 0 - - - percentComplete = (float(flags.count(task_id=task['id'])) / userCount) * 100 - - #hax for bad css (if 100, nothing will show) - if percentComplete == 100: - percentComplete = 99.99 + for cat in categories: + cTasks = [x for x in tasks if x['category'] == cat['id']] + gTasks = [] - task['percentComplete'] = percentComplete + gTasks.append(cat) + for task in cTasks: + percentComplete = (float(flags.count(task_id=task['id'])) / userCount) * 100 - isComplete = bool(flags.count(task_id=task['id'], user_id=user['id'])) + #hax for bad css (if 100, nothing will show) + if percentComplete == 100: + percentComplete = 99.99 - task['isComplete'] = isComplete + task['percentComplete'] = percentComplete - grid[currentCatCount][cat] = task - currentCatCount += 1 + isComplete = bool(flags.count(task_id=task['id'], user_id=user['id'])) - #add the final endTask element - if user['isAdmin']: - if len(tasks) > 0: - endTask = { "end": True, "category": currentCat } - grid[currentCatCount][currentCat] = endTask + task['isComplete'] = isComplete + gTasks.append(task) - #if any None in first row, add end task - for i, t in enumerate(grid[0]): - if t is None: - endTask = { "end": True, "category": i } - grid[0][i] = endTask + if isAdmin: + gTasks.append({'add': True, 'category': cat['id']}) + grid.append(gTasks) # Render template render = render_template('frame.html', lang=lang, page='tasks.html', @@ -283,9 +254,7 @@ def addcatsubmit(): @app.route('/addtask//', methods=['GET']) @admin_required def addtask(cat): - category = db.query('SELECT * FROM categories LIMIT 1 OFFSET :cat', cat=cat) - category = list(category) - category = category[0] + category = db['categories'].find_one(id=cat) user = get_user() diff --git a/static/css/ctf.css b/static/css/ctf.css index 321647a..8bad279 100755 --- a/static/css/ctf.css +++ b/static/css/ctf.css @@ -98,6 +98,15 @@ background-size: cover; * Tasks page */ +.category-column > a{ + float: left; + clear: left; +} + +.category-column{ + float: left; +} + .chall-box-score { z-index:100; diff --git a/templates/tasks.html b/templates/tasks.html index e1ba1a2..f83b88d 100755 --- a/templates/tasks.html +++ b/templates/tasks.html @@ -1,44 +1,38 @@
- {% for category in categories %} -
- {{ category.name }} -
- {% endfor %} - {% if user.isAdmin %} - -
- + -
-
- {% endif %} - -
- - {% for row in grid %} -
+ {% for row in grid %} +
{% for task in row %} - {% if task.id %} + + {% if task.score %}
{{ task.score }}
- {% elif task.end %} + {% elif task.add %}
+
{% else %} -
-   +
+ {{ task.name }}
{% endif %} {% endfor %} +
+ {% endfor %} + {% if user.isAdmin %} + +
+ + +
+
+ {% endif %}
- {% endfor %}