def get(self, cid, n=1): cid = int(cid) qs = Reply.where('cid = %s', cid) total = qs.count() page, limit, offset = page_limit_offset( '/reply_list/%s-%%s'%cid, total, n, PAGE_LIMIT, ) li = qs.order_by('id desc')[offset: offset + limit] txt_bind(li) #print cid == CID_USER if cid == CID_USER: Wall.mc_bind(li, 'wall', 'rid') wall_list = [i.wall for i in li] Zsite.mc_bind(wall_list, 'from_user', 'from_id') Zsite.mc_bind(wall_list, 'to_user', 'to_id') else: Po.mc_bind(li, 'po', 'rid') Zsite.mc_bind(li, 'user', 'user_id') self.render( reply_list=li, page=page, )
def start(self): delta = round(self.width / (WALLS_COUNT - 1)) up_walls = [ Wall(Vector(i * delta, UPPER_WALL_Y), Vector((i + 1) * delta, UPPER_WALL_Y + 100), 3, 3, AMPLITUDE) for i in range(WALLS_COUNT) ] down_walls = [ Wall(Vector(i * delta, LOWER_WALL_Y), Vector((i + 1) * delta, LOWER_WALL_Y + 100), 3, 3, AMPLITUDE) for i in range(WALLS_COUNT) ] self.walls_num = WALLS_COUNT * 2 self.heap = Heap(Dot(Vector(400, 500), 30), Vector(0, 0), 0) for wall in up_walls: wall.step(random() * 10) self.append(wall) for wall in down_walls: wall.step(random() * 10) self.append(wall) dots = [self.gen_rnd_dot() for i in range(5)] for dot in dots: self.append(dot) self.append(self.heap)
def spammer_reset(user_id): from model.po import Po, po_rm, reply_rm_if_can from zsite_tag import zsite_tag_rm_by_po for i in Po.where(user_id=user_id): po_rm(user_id, i.id) zsite_tag_rm_by_po(i) from model.reply import Reply for i in Reply.where(user_id=user_id): reply_rm_if_can(user_id, i.id) from model.wall import Wall from model.zsite import Zsite z = Zsite.mc_get(user_id) total = z.reply_count if total: reply_list = z.reply_list_reversed(total, 0) for reply in reply_list: wall = Wall.mc_get(reply.rid) if wall: wall.reply_rm(reply) spammer_new(user_id)
def get(self, id, n=1): zsite = self.zsite zsite_id = zsite.id zsite_url = zsite.link current_user_id = self.current_user_id wall = Wall.mc_get(id) if not wall: return self.redirect('/') zsite_id_list = wall.zsite_id_list() if zsite_id not in zsite_id_list: return self.redirect('/') else: other = wall.zsite_other(zsite_id) if other.cid == CID_SITE or zsite_id == current_user_id: return self.redirect('%s/wall/%s' % (other.link, id)) total = wall.reply_count page, limit, offset = page_limit_offset( '%s/wall/%s-%%s' % (zsite_url, id), total, n, PAGE_LIMIT) if type(n) == str and offset >= total: return self.redirect(zsite_url) reply_list = wall.reply_list_reversed(limit, offset) self.render(wall=wall, zsite_id_list=zsite_id_list, reply_list=reply_list, page=page)
def collide(self, wall: Wall, dt): points = wall.get_dots() glob_moment = 0 glob_force = Vector(0, 0) for point in points: if abs(point - self.get_cords()) > self.r: continue for dot in self.dots: dot_coords = dot.get_cords() dot_force = Vector(0, 0) l_2 = (point.x - dot_coords.x)**2 + ( point.y - dot_coords.y)**2 + 0.01 #because of division by zero if l_2 < dot.get_r()**2: dot_force += FORCE_CONSTANT * (dot.get_r() - math.sqrt( l_2)) / abs(dot_coords - point) * (dot_coords - point) dot_moment = (dot_coords - self.get_cords()).cross(dot_force) glob_force += dot_force glob_moment += dot_moment beta = glob_moment / self.get_I() a = glob_force / self.m self.v += a * dt self.w += beta * dt
def post(self, id): current_user_id = self.current_user_id r = Reply.mc_get(id) can_admin = r.can_admin(current_user_id) wall = Wall.mc_get(r.rid) if r: zsite_id_list = wall.zsite_id_list() if wall: if can_admin is False and (current_user_id in zsite_id_list): can_admin = True if can_admin: wall.reply_rm(r) self.finish({'success':can_admin})
def post(self, id): current_user_id = self.current_user_id r = Reply.mc_get(id) can_admin = r.can_admin(current_user_id) wall = Wall.mc_get(r.rid) if r: zsite_id_list = wall.zsite_id_list() if wall: if can_admin is False and (current_user_id in zsite_id_list): can_admin = True if can_admin: wall.reply_rm(r) self.finish({'success': can_admin})
def get(self, id, n=1): zsite = self.zsite zsite_id = zsite.id zsite_url = zsite.link current_user_id = self.current_user_id wall = Wall.mc_get(id) if not wall: return self.redirect('/') zsite_id_list = wall.zsite_id_list() if zsite_id not in zsite_id_list: return self.redirect('/') else: other = wall.zsite_other(zsite_id) if other.cid == CID_SITE or zsite_id == current_user_id: return self.redirect('%s/wall/%s'%(other.link, id)) total = wall.reply_count page, limit, offset = page_limit_offset( '%s/wall/%s-%%s' % (zsite_url, id), total, n, PAGE_LIMIT ) if type(n) == str and offset >= total: return self.redirect(zsite_url) reply_list = wall.reply_list_reversed(limit, offset) self.render( wall=wall, zsite_id_list=zsite_id_list, reply_list=reply_list, page=page )
def __init__(self): pg.init() screen = pg.display.set_mode((WIDTH, HEIGHT)) self.clock = pg.time.Clock() self.onclick = Event() self.onkey = Event() self.view = View(screen) self.dots = [ Dot(400, 600, 10), Dot(450, 450, 20), Dot(550, 450, 30), Dot(500, 550, 25) ] self.player = Heap(self.dots, 500, 500, 1000, 0.5, 100) self.wall = Wall([Dot(200, 600, 0), Dot(300, 500, 0)]) self.gameObjects = [*self.dots, self.player, self.wall] self.running = True
def spammer_reset(user_id): from model.po import Po, po_rm, reply_rm_if_can from zsite_tag import zsite_tag_rm_by_po for i in Po.where(user_id=user_id): po_rm(user_id, i.id) zsite_tag_rm_by_po(i) from model.reply import Reply for i in Reply.where(user_id=user_id): reply_rm_if_can(user_id, i.id) from model.wall import Wall from model.zsite import Zsite z = Zsite.mc_get(user_id) total = z.reply_count if total: reply_list = z.reply_list_reversed(total, 0) for reply in reply_list: wall = Wall.mc_get(reply.rid) if wall: wall.reply_rm(reply) spammer_new(user_id)
def wall_action(self, wall: Wall, dt): heap = self.heap heap_x_l = heap.get_cords().x - heap.get_r() heap_x_r = heap.get_cords().x + heap.get_r() wall_x_l = wall.get_cords().x wall_x_r = wall.get_cords().x + wall.width if (heap_x_l - wall_x_l) * (heap_x_l - wall_x_r) < 0 or ( heap_x_r - wall_x_l) * ( heap_x_r - wall_x_r ) < 0 or heap_x_l - wall_x_l < 0 and heap_x_r - wall_x_r > 0: heap.collide(wall, dt) if wall_x_r - self.view_point.x < 0: delta = round(self.width / (WALLS_COUNT - 1)) self.remove(wall) wall = Wall( Vector(self.walls_num // 2 * delta, wall.get_cords().y), Vector((self.walls_num // 2 + 1) * delta, wall.get_cords().y), 3, 3, AMPLITUDE) self.append(wall) wall.step(random()) self.walls_num += 1
def post(self, id): wall = Wall.mc_get(id) post_reply(self, wall.reply_new) self.redirect('/wall/%s' % id)
def post(self, id): wall = Wall.mc_get(id) post_reply(self, wall.reply_new) self.redirect('/wall/%s' % id)
def collide(self, wall: Wall): points = wall.get_dots() for point in points: if abs(point - self.get_cords()) < self.r: return True return False