def import_demo(): if request.method == 'POST': for demo_name in request.form: success, msg = Demo.create_from_name(demo_name) if success: flash(msg, category='success') db.session.commit() else: flash(msg, category='error') demos_raw = glob(os.path.join(app.config.get('DEMO_STORAGE_DIR', '.'), "*.dem")) demos = [] for demo in demos_raw: if not Demo.demo_exists(os.path.basename(demo)): demos.append((os.path.basename(demo), Demo.check_demo_filename(os.path.basename(demo)))) return render_template('import_demo.html', demos=demos)
def demopage(page=1): try: page = int(page) except ValueError: return redirect(url_for('index')) if page == 1: return redirect(url_for('index')) return render_template('demos.html', demos=Demo.get_page(page, app.config['DEMO_PER_PAGE']))
def upload_log(demo=None): if demo is None: return json.dumps({'success': False, 'msg': "Demo ID required. How did you get here again?", 'cat': "error"}) demo_obj = Demo.get_from_id(demo) if demo_obj is None: return json.dumps({'success': False, 'msg': "Demo %s was not found! How did you get here again?" % demo, 'cat': "error"}) log_file = request.files['log_file'] success, title, msg, cat = _do_upload_log_file(log_file, demo_obj) return json.dumps({"success": success, "msg": msg, "cat": cat})
def view_demo(demo=None): # This renders the permalink if demo is None: return redirect(url_for('index')) demo = Demo.get_from_id(demo) if demo is None: flash('Sorry I couldn\'t find that demo...', category='warning') return redirect(url_for('index')) # TODO: Do SQL magic to get this down to 1 query, too late tonight... return render_template('view_demo.html', demo=demo, next=demo.next_by_date(), prev=demo.previous_by_date())
def edit_demo_field(demo=None): demo = Demo.get_from_id(demo) if request.method == 'POST': name = request.form.get("name", '') value = request.form.get("value", '') if name == "delete": # special case, we need to redirect flash('Success! Demo %s was deleted!' % demo.title, category='success') return redirect(url_for('index')) if name == "summary": value = value.replace("\n", "<br />") setattr(demo, name, value) db.session.commit() return "Yep." return "Nope."
def _do_upload_demo_file(the_file): """ Returns: Demo Object/False, Message, Message Type (to be passed to flash) """ if not the_file: return False, "You must select a demo to upload!", "error" if not allowed_file(the_file.filename): return False, "DOH! Only .dem files are allowed!", "error" demo = None filename = secure_filename(the_file.filename) file_exists, title, total_path, category = _is_file_on_disk(filename) if file_exists: # NOTE: total_path here will be the message! return False, total_path, category success, msg = Demo.create_from_name(filename) if success: category = 'success' the_file.save(total_path) db.session.commit() demo = Demo.get_from_filename(filename) else: category = 'error' return demo, title, msg, category
def _is_file_on_disk(filename): total_path = os.path.join(app.config['DEMO_STORAGE_DIR'], filename) demo = Demo.get_from_filename(filename) file_exists = False category = "success" msg = total_path title = "Error" if demo: file_exists = True title = "Whoops!" msg = "<a href='%s'>That Demo already exists</a>!" % \ (url_for('view_demo', demo=demo.id)) category = 'warning' elif os.path.exists(total_path): file_exists = True title = "That Demo already exists!" msg = "That Demo <strong>file</strong> already exists, but hasn't been added to the repository. " \ "Perhaps you'd like to <a href='%s'>import it</a>?" % (url_for("import_demo")) category = 'warning' return file_exists, title, msg, category
def index(): print get_map_name("cp_dustbowl") print get_map_name("pl_goldrush") return render_template('demos.html', demos=Demo.get_page(1, app.config['DEMO_PER_PAGE']))
def delete_demo(): if request.method == 'POST': demoid = request.form.get("demoid", None) Demo.delete(int(demoid)) return "Yay."