def populate_borders(self): minus_one = -1 for width in range(-1, self.map_width + 1): bottom_border_wall = Wall(Point(width, minus_one), self) upper_border_wall = Wall(Point(width, self.map_heigth), self) self.walls_positions[ bottom_border_wall.position] = bottom_border_wall self.walls_positions[ upper_border_wall.position] = upper_border_wall for height in range(self.map_heigth): left_border_wall = Wall(Point(minus_one, height), self) right_border_wall = Wall(Point(self.map_width, height), self) self.walls_positions[left_border_wall.position] = left_border_wall self.walls_positions[ right_border_wall.position] = right_border_wall
def get_arranged_data(): """Get the information needed for displaying a gallery. Response to an AJAX request. """ gallery_id = int(request.form.get('gallery_id')) # margin = request.form.get('margin') wkspc = ar.Workspace(gallery_id) algorithm_type = request.form.get('algorithm_type') if algorithm_type == 'linear': arr = ar.LinearArranger(wkspc) elif algorithm_type == 'column': arr = ar.ColumnArranger(wkspc) elif algorithm_type == 'grid': arr = ar.GridArranger(wkspc) else: # Default to column arrangement arr = ar.ColumnArranger(wkspc) arr.arrange() wall_id = Wall.init_from_workspace(wkspc) new_wall_data = {'id': wall_id} return jsonify(new_wall_data)
def load_walls(seed_file_path): """Add sample walls to database from text file. Data file is pipe seperated: wall_id | gallery_id | wall_width | wall_height | saved """ with open(seed_file_path) as seed_file: for line in seed_file: wall_id, gallery_id, wall_width, wall_height, saved = line.rstrip( ).split("|") # Currently gallery_id is discarded wall_id = int(wall_id) gallery_id = int(gallery_id) wall_width = int(wall_width) wall_height = int(wall_height) saved = saved.strip().lower() == 'saved' wall = Wall(wall_id=wall_id, gallery_id=gallery_id, wall_width=wall_width, wall_height=wall_height, saved=saved) db.session.add(wall) db.session.commit() # Reset counter result = db.session.query(func.max(Wall.wall_id)).one() max_id = int(result[0]) query = "ALTER SEQUENCE walls_wall_id_seq RESTART WITH :next_id" db.session.execute(query, {'next_id': max_id + 1}) db.session.commit()
def process_wall_info(project_id): """Process wall information and show artform page""" if 'email' in session: project_obj = Project.query.filter( Project.project_id == project_id).first() cur_project_id = project_obj.project_id wall_name = request.args.get("new_wall") wall_disc = request.args.get("wall_disc") wall_width = request.args.get("wall_width") width_fraction = request.args.get("wall_width_fraction") wall_height = request.args.get("wall_height") height_fraction = request.args.get("wall_height_fraction") center_line = request.args.get("center_line") center_fraction = request.args.get("center_line_fraction") offset_percent = request.args.get("offset_percent") wall_img = request.args.get("wall_img") session['wall_name'] = wall_name #format integers to pass to javascript adjusted_width = (int( (int(wall_width) + float(width_fraction)) * 1000)) adjusted_height = (int( (int(wall_height) + float(height_fraction)) * 1000)) adjusted_center = (int( (int(center_line) + float(center_fraction)) * 1000)) adjusted_offset = (int(float(offset_percent) * 1000)) print "adjusted_width", adjusted_width print "adjusted_height", adjusted_height print "adjusted_center", adjusted_center print "offset_percent", offset_percent cur_wall = Wall(wall_name=wall_name, wall_disc=wall_disc, wall_width=adjusted_width, wall_height=adjusted_height, center_line=adjusted_center, project_id=cur_project_id, offset_percent=adjusted_offset, wall_img=wall_img) db.session.add(cur_wall) db.session.commit() wall_id = cur_wall.wall_id wall_name = cur_wall.wall_name print "CURRENT PROJECT NAME FOR ART FORM: ", project_obj.project_name print "CURRENT WALL NAME FOR ART FORM: ", wall_name return render_template("new_art.html", project_id=project_id, wall_id=wall_id, wall_name=wall_name) else: flash("You must log in or register to create projects") redirect('/')
def admin_new_wall(): if request.method == 'GET': token = ''.join(random.choice(string.ascii_letters) for x in range(12)) return render_template('newwall.html', token=token) if request.method == 'POST': name = request.form['name'] alias = request.form['alias'] height = int(request.form['height']) width = int(request.form['width']) token = request.form['token'] w = Wall(name=name, alias=alias, height=height, width=width, token=token) wm = WalledModel() wm.create_wall(w) return redirect(url_for('admin_get_walls'))
def get_latest(n): return Wall.all().filter('name_set =', True).order('-created').fetch(n)
def fetch(unique_id): return Wall.gql('WHERE unique_id = :1', unique_id).get()
def create(name=''): w = Wall(name=name, name_set=len(name) > 0, item_count=0) w.put() w.unique_id = get_string_id(w.key().id(), ALPHABET); w.put() return w
def populate_walls(self): for row in range(self.map_heigth): for col in range(self.map_width): wall = Wall(row, col) self.walls_positions[Point(col, row)] = wall
import socket import threading from base64 import b64encode from hashlib import sha1 import struct import sys from functools import lru_cache from urllib.parse import parse_qs, urlparse from model import Wall import json from datetime import datetime wall = Wall() MAX_LEN = 64 * 1024 class ClientRequestHandler: def __init__(self, sock): self.socket = sock self.rfile = sock.makefile('rb') self.keepwork = 1 def handshake_fn(self): headers = {} while True: header = self.rfile.readline().decode().strip() if not header: break head, value = header.split(':', 1) headers[head.lower().strip()] = value.strip() self.headers = headers