def presentBlockchangesByArea (nick): c = logblock.cursor() c.execute('''select count(*) as count,world,round(x,-2) as x_,round(z,-2) as z_ from (''' + ' union all '.join(['''select '%s' as world, x, z from `lb-%s` join `lb-players` using (playerid) where date >= %%s and date < date_add(%%s, interval 1 day) and playername = %%s and type != replaced''' % (world, world) for world in worldnames.keys()]) + ''') as foo group by world,x_,z_ order by world,count desc''', (day, day, nick) * len(worldnames)) rows = [( normalizeId('area', nick, x, z), count, world, x, z) for (count, world, x, z) in c.fetchall()] return [tags.tr (id = rowId) [ tags.td [ tags.a (href = '#' + rowId) [ '#' ] ], tags.td [ 'block changes' ], tags.td [ count ], tags.td [ '~ ', tags.a (href = 'http://mc.dev-urandom.eu/map/#/%s/64/%s/-2/%s/0' % (x, z, renders[world])) [ '%s/%s/*/%s' % (worldnames[world], x, z) ] ] ] for (rowId, count, world, x, z) in rows]
def renderApiKeys(self, keys): content = ( T.h2['API Keys'], T.p[ T.a(href=self.getUrl('profile/newKey'))[ T.button(class_='btn btn-primary')['Add key'] ], ], T.div(class_='panel panel-default')[ T.div(class_='panel-heading')['Added keys'], T.table(class_='table')[ T.thead[ T.tr[ T.th['Key ID'], T.th['Expires'], T.th['Characters'], T.th() ] ], T.tbody[ forEach(keys, lambda keyId, expires, characters: ( T.tr[ T.td[keyId], T.td[expires], T.td[ [ T.div[char] for char in characters ] ], T.td[ T.a(class_='glyphicon glyphicon-info-sign withTooltip', title='Detailed info', href='#', **{'data-placement': 'top', 'data-toggle': 'tooltip'}), ' ', T.a(class_='glyphicon glyphicon-trash withTooltip text-danger', title='Delete key', href='#', **{'data-placement': 'top', 'data-toggle': 'tooltip'}), ] ] )), ] ] ] ) html = HtmlLayout() html.setContent(content) return html
def doGet(self, request): layout = IGBLayout() layout.setContent([ Panel(heading=['How to use scanning tool'], content=[ T.p[""" This tool alows you to remember all scanned signatures in given solar system. It will try to automatically detect that you changed system, and always show you signatures from system you are currently in """], T.p[""" Basic idea for this tool is that, you should copy-and-paste all data from scanning overview to rectangular gray textarea in this tool (and submit) as often as posible. It will automatically detect changes, update existing signatures with more info, delete old signatures, and add new. """], T.p[""" This tool has two modes: personal and corporation. All they differ is who sees your submitted data. It might be only you, or all people from your corporation. """], T.p[""" To copy-paste signatures from scanning overview, select any signature in your "Probe scanner" window. Then press ctrl+a (select all), then ctrl+c (copy). Then click in IGB window, inside rectangular gray area, and press ctrl+v (paste). """], T.div[ T.img(src='/static/images/help_overview.jpg'), T.img(src='/static/images/help_igb_paste.jpg') ], T.p[""" """], T.hr(), T.p[ 'Back to: ', T.a(href=self.getUrl('scanning/personal'))['personal scanner'], ' or ', T.a(href=self.getUrl('scanning/corporation'))['corporation scanner'], ] ]) ]) return layout
def test_nested_macros(): """test nested macros""" url_data = [ {'url': 'http://www.google.com', 'label': 'Google'}, {'url': 'http://www.yahoo.com', 'label': 'Yahoo!'}, {'url': 'http://www.amazon.com', 'label': 'Amazon'} ] template = ( macro('list_macro', lambda url, label: ( macro('link_macro', lambda _u, _l: T.a(href=_u)[_l] ), T.li[link_macro(url, label)] # @UndefinedVariable )), T.html[ T.head[T.title[my_name()]], T.body[ T.ul[ [list_macro(**_item) # @UndefinedVariable for _item in url_data] ] ] ] ) output = flatten(template) assert output == ('<html><head><title>test_nested_macros</title></head>' '<body><ul><li><a href="http://www.google.com">Google</a></li>' '<li><a href="http://www.yahoo.com">Yahoo!</a></li>' '<li><a href="http://www.amazon.com">Amazon</a></li></ul></body></html>')
def listExecutedCommands (nick): c = logblock.cursor() c.execute('''select date,message from `lb-chat` join `lb-players` using (playerid) where date >= %s and date < date_add(%s, interval 1 day) and message like '/%%' and message not like '/tell%%' and playername = %s order by date''', ( day, day, nick )) rows = [ (normalizeId('command', nick, date), isBoring(command), date, command) for (date, command) in c.fetchall() ] return [(date, tags.tr (id = commandId, class_ = boring) [ [tags.td [s] for s in [ tags.a ( href = '#' + commandId ) [ '#' ], date, 'command']], [ tags.td (colspan = '4') [ command ] ] ]) for (commandId, boring, date, command) in rows]
def test_tag_multiplication_with_macro(): """tag multiplication including macro""" url_data = [ {'url': 'http://www.google.com', 'label': 'Google', 'class': 'link'}, {'url': 'http://www.yahoo.com', 'label': 'Yahoo!', 'class': 'link'}, {'url': 'http://www.amazon.com', 'label': 'Amazon', 'class': 'link'} ] template = ( macro('test_macro', lambda url: T.a(href=url)["$label"] ), T.html[ T.head[T.title[my_name()]], T.body[ T.ul[ T.li(class_="$class")[test_macro("$url")] * url_data # @UndefinedVariable ] ] ] ) output = flatten(template) assert output == ('<html><head><title>test_tag_multiplication_with_macro</title></head>' '<body><ul><li class="link"><a href="http://www.google.com">Google</a></li>' '<li class="link"><a href="http://www.yahoo.com">Yahoo!</a></li>' '<li class="link"><a href="http://www.amazon.com">Amazon</a></li></ul>' '</body></html>')
def renderRegisterForm(self, form): html = HtmlLayout(isLogged=False) formView = FormRenderer() formView.addButton('Create account') formView.setRenderPanel() content = ( T.div(class_="row")[ T.div(class_="col-sm-4")[ T.h2['Register form'], ], T.div(class_="col-sm-4 text-right")[ T.h2[T.a(href=self.getUrl('index'))['Back']] ] ], T.div(class_="row")[ T.div(class_="col-sm-8")[ formView.render(form) ] ] ) html.setContent(content) return html
def renderLoginForm(self, form, count): formView = FormRenderer() formView.addButton('Login') formView.setRenderPanel() content = [ T.div(class_="row")[ T.div(class_="col-sm-4")[ T.h2['Login form '], ], T.div(class_="col-sm-4 text-right")[ T.h2[T.a(href=self.getUrl('register'))['Register account']] ] ], T.div(class_="row")[ T.div(class_="col-sm-8")[ formView.render(form) ] ], ] layout = HtmlLayout(isLogged=False) layout.setContent(content) return layout
def getKnownSignaturesTable(self, signatures): result = [ T.table(class_='table table-bordered')[ T.thead[ T.tr[ T.th['Key'], T.th['Group'], T.th['Type'], T.th['Name'], T.th[''], ] ], T.tbody[ forEach(signatures, lambda key, group, sigType, name: [ T.tr[ T.td[key], T.td[group], T.td[sigType], T.td[name], T.td[ C.when(sigType in ['Data Site', 'Relic Site'])[ T.a(href='#', class_='lootModalToggle', **{'data-key': key})[ 'Loot' ] ] ] ] ]) ] ] ] return result
def _renderHeader(self, helper): return [ 'Hello ', T.strong[helper.charName], T.div(class_='pull-right')[ T.a(href=self.getUrl('scanning/corporation'))['Go to corp'] ] ]
def renderRequestTrust(self): result = [ Panel(heading='Untrusted', content=[ T.p(id='untrusted')[ T.a(href='#', onclick='return IGBManager.requestTrust()')['Please trust me!'] ], T.p()[ T.a(href='#', onclick='return IGBManager.reload()')['Reload page'], ' when you accepted trust request' ] ]) ] return result
def listBlockChanges (nick): c = logblock.cursor() query = '''select date_add(date(date), interval hour(date) hour),sum(created),sum(destroyed) from (''' + ' union all '.join(['''(select date,type != 0 as created,replaced != 0 as destroyed from `lb-%s` join `lb-players` using (playerid) where date >= %%s and date < date_add(%%s, interval 1 day) and playername = %%s and type != replaced )''' % world for world in worldnames.keys()]) + ''') as blockchanges group by hour(date)''' c.execute(query, (day, day, nick) * len(worldnames)) rows = [( normalizeId('blocks', nick, date), date, created, destroyed) for (date, created, destroyed) in c.fetchall()] return [(date, tags.tr (id = rowId) [ tags.td [ tags.a (href = '#' + rowId) [ '#' ] ], tags.td [ date ], tags.td [ 'blocks/hour' ], tags.td (colspan = '4') [ 'Placed: %s, ' % created if created else '', 'Destroyed: %s' % destroyed if destroyed else '' ] ]) for (rowId, date, created, destroyed) in rows]
def presentBlockchangesByMaterial (nick): c = logblock.cursor() query = '''select sum(count) as net, type from (''' + ' union all '.join([('''(select -count(*) as count,replaced as type from `lb-%s` join `lb-players` using (playerid) where date >= %%s and date < date_add(%%s, interval 1 day) and playername = %%s group by replaced) union all (select count(*) as count,type from `lb-%s` join `lb-players` using (playerid) where date >= %%s and date < date_add(%%s, interval 1 day) and playername = %%s group by type)''' ) % (world, world) for world in worldnames.keys()]) + ''') as accumulatedchanges where type != 0 group by type order by net''' c.execute(query, (day, day, nick) * len(worldnames) * 2) rows = [(normalizeId('blocks.hour', nick, materials[btype], day), net, materials[btype]) for (net, btype) in c.fetchall() if net] return [tags.tr (id = rowId) [ tags.td [ tags.a (href = '#' + rowId) [ '#' ] ], tags.td [ 'placed' if net > 0 else 'destroyed' ], tags.td [ abs(net) ], tags.td [ material ] ] for (rowId, net, material) in rows]
def renderSignatureLoot(self, signatureKey): result = Modal( id='lootModal', content=[ T.div(id='containers')[ T.div(class_='buttons')[ T.button(type='button', class_='btn btn-success', **{'data-level': 'trivial'})['+ Debris'], T.button(type='button', class_='btn btn-success', **{'data-level': 'easy'})['+ Rubble'], T.button(type='button', class_='btn btn-warning', **{'data-level': 'medium'})['+ Remains'], T.button(type='button', class_='btn btn-danger', **{'data-level': 'hard'})['+ Ruins'], ], T.div(id='contentPaste')[ Panel( heading='Paste content of container below', content=[ T.div(class_='row')[ T.div(class_='col-xs-9')[ T.textarea(class_="form-control", rows="2"), ], T.div(class_='col-xs-3')[ T.button(class_='btn btn-default')['Submit'], T.div(class_='ajaxLoader', style='white-space: nowrap')[ T.img(src='/static/images/ajax-loader.gif'), ' Processing' ], ], ], ] ), ], T.div(class_='row container-list')[ T.div(class_='col-xs-3 blueprint')[ T.div(class_='thumbnail')[ T.img(src='#'), T.div(class_='caption')[ T.strong()['Lorem ipsum'], T.div(class_='totalWorth')['Lorem ipsum'], ], T.a(href='#', title='Delete', **{'data-toggle': 'tooltip', 'data-placement': 'top'})[ T.span(class_='glyphicon glyphicon-remove-circle') ] ] ] ], ] ], heading=['Loot for signature ', T.strong[signatureKey]], ) return result
def _renderHeader(self, helper): """ :type helper: pyeve.www.igb.IGBRequest """ return [ 'Hello ', T.strong[helper.charName], ', from ', T.strong[helper.corpName], T.div(class_='pull-right')[ T.a(href=self.getUrl('scanning/personal'))['Go to personal'] ] ]
def test_toc_macro ( self ): '''test table-of-contents macro''' template = ( assign ( 'TOC', [ ] ), macro ( 'TableOfContents', lambda matchtags, tag: ( macro ( 'toc_search', lambda tag, is_tag: tag.name in matchtags and ( TOC.append ( T.a ( href='#toc-%s' % tag.children [ 0 ] ) [ tag.children [ 0 ] ] ), tag.attrs.update ( { 'class': 'chapter-%s' % tag.name } ), tag.children.insert ( 0, T.a ( name='toc-%s' % tag.children [ 0 ] ) [ tag.name ] ) ) or True ), tag.walk ( toc_search, True ) ) ), T.html [ T.head [ T.title [ my_name ( ) ] ], T.body [ T.div ( id='TableOfContents' ) [ 'Table of Contents', lambda: T.ul [ [ T.li [ _t ] for _t in TOC ] ] ], TableOfContents ( ( 'h1', 'h2', 'h3' ), T.div [ T.h1 [ 'Chapter 1' ], T.div [ 'chapter 1 content' ], T.h1 [ 'Chapter 2' ], T.div [ 'chapter 2 content', T.h2 [ 'Chapter 2 subsection' ], T.div [ 'chapter 2 subsection content' ] ] ] ) ] ] ) actual = flatten ( template )
def render(self, request, url): """ :type url: werkzeug.routing.MapAdapter :type request: werkzeug.wrappers.Request """ # ifLogged = lambda fun: fun if self.isLogged else '' isTrusted = IGBRequest(request).isTrusted layout = ( T.html(lang='en')[ T.head[ T.meta(charset='utf-8'), T.meta(content='IE=Edge', **{'http-equiv': "X-UA-Compatible"}), T.meta(name='viewport', content='width=device-width, initial-scale=1'), T.title['PyEve IGB'], T.link(href='/static/css/bootstrap-black.min.css', rel='stylesheet'), T.link(href='/static/css/igb.css', rel='stylesheet'), T.script(src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'), T.script(src='/static/js/bootstrap.js'), T.script(src='/static/js/igbCore.js'), self.getAdditionalJs() ], T.body[ # 'HOWDY', # request.headers.get('EVE_TRUSTED', 'alo'), T.div(class_='container-fluid')[ C.switch(isTrusted)[ C.case(True)[self.content], C.case(False)[self.renderRequestTrust()] ], T.div(class_='text-center')[ T.small[ 'PyEVE. Created by ', T.a(href="#", onclick="CCPEVE.showInfo(1377, 93747896); return false")[ 'Rudykocur Maxwell' ] ] ] ], ] ] ) return Response(flatten(layout), mimetype='text/html')
def _add_root_menu(tag): nodepath = node.path.split('.') nodedepth = len(nodepath) label = node.label t = T.li()[T.a(href=self.urlfactory(node))[label]] tag[t] if request_path == nodepath: add_class(t, 'selected') if self.item_id == 'name': t.attrs['id'] = 'nav-%s'%node.name
def collectActivity (nick): activity = aggregate( listExecutedCommands(nick), listChestAccesses(nick), listBlockChanges(nick), listProtectionChanges(nick), ) materials = presentBlockchangesByMaterial(nick) hotspots = presentBlockchangesByArea(nick) return [ tags.h2 ( id = nick ) [ nick , ' ', tags.a ( class_ = 'hashlink', href = '#'+nick ) [ '#' ] ], tags.h3 [ 'activity by time' ] if activity else '', tags.table (class_ = 'bytime') [ activity ] if activity else '', tags.h3 [ 'materials used (net)' ] if materials else '', tags.table (class_ = 'bymaterial') [ materials ] if materials else '', tags.h3 [ 'activity by area' ] if hotspots else '', tags.table (class_ = 'byarea') [ hotspots ] if hotspots else '', ] if activity or materials or hotspots else []
def build_tree(facet, root_url, category_path): ul_by_path = {} root = T.ul() ul_by_path[''] = root cats = list(facet['category']) cats.sort(lambda x, y: cmp(len(x['path'].split('.')), len(y['path'].split('.')))) for c in cats: u = T.ul() ul_by_path[c['path']] = u if c['path'] == category_path: class_ = 'selected' else: class_ = '' link = T.a(href=root_url.child(c['path']))[c['data']['label']] link.attrs['class'] = class_ li_link = T.li()[link] parent = get_parent(c['path']) ul_by_path[ parent ][ li_link, u ] return flatten(root)
def build_tree(facet, root_url, category_path): ul_by_path = {} root = T.ul() ul_by_path[''] = root cats = list(facet['category']) cats.sort( lambda x, y: cmp(len(x['path'].split('.')), len(y['path'].split('.')))) for c in cats: u = T.ul() ul_by_path[c['path']] = u if c['path'] == category_path: class_ = 'selected' else: class_ = '' link = T.a(href=root_url.child(c['path']))[c['data']['label']] link.attrs['class'] = class_ li_link = T.li()[link] parent = get_parent(c['path']) ul_by_path[parent][li_link, u] return flatten(root)
def test_tag_multiplication(): """tag multiplication""" url_data = [ dict(url='http://www.google.com', label='Google'), dict(url='http://www.yahoo.com', label='Yahoo!'), dict(url='http://www.amazon.com', label='Amazon') ] template = T.html[ T.head[T.title[my_name()]], T.body[ T.ul[ T.li[T.a(href="$url")["$label"]] * url_data ] ] ] output = flatten(template) assert output == ('<html><head><title>test_tag_multiplication</title></head>' '<body><ul><li><a href="http://www.google.com">Google</a></li>' '<li><a href="http://www.yahoo.com">Yahoo!</a></li>' '<li><a href="http://www.amazon.com">Amazon</a></li></ul></body></html>')
def renderModuleNav(self, tag, data): """ :type data: (werkzeug.routing.MapAdapter, None) """ (url, unused) = data currentEndpoint = url.match()[0] currentModule = [x for x in self.modules if currentEndpoint in x.endpoints][0] html = ( T.ul(class_='nav nav-pills nav-stacked')[ [ T.li(class_='active' if currentEndpoint == page.endpoint else None)[ T.a(href=page.url)[page.name] ] for page in currentModule.publicPages ] ] ) return tag[html]
def _add_child_menus(tag, node, urlpath): nodepath = node.path.split('.') nodedepth = len(nodepath) label = node.label # If we're not showing submenus (apart from the selected item) # then loop through our urlpath and check that the node matches each segment. # If it doesn't then return our result so far if not self.openall: for n, segment in enumerate(urlpath[:self.openallbelow]): if n+1>=nodedepth or segment != nodepath[n+1]: return t = T.li()[T.a(href=self.urlfactory(node))[label]] tag[t] # Mark selected item if request_path == nodepath: add_class(t, 'selected') elif request_path[:nodedepth] == nodepath[:nodedepth]: add_class(t, 'selectedpath') if self.item_id == 'name': t.attrs['id'] = 'nav-%s'%node.name # only show up to a set depth if self.maxdepth is not None and nodedepth > self.maxdepth: return # If we have more children and we're showing them all or we're considered to be in the right location - then add them if node.children and (self.openall or force_url_path[:nodedepth] == nodepath[:nodedepth]): s = T.ul() t[s] _add_children(s, node, urlpath,is_root=False)
def listChestAccesses (nick): accesses = list(chain(*[[ row + (world,) for row in queryChestAccesses(world, nick) ] for world in worldnames.keys()])) rows = [ (normalizeId('access', nick, date), date, iamount, ( materials[itype] or 'unknown (%s)' % itype ) + (' (%s)' % idata if idata else '' ), getProtectionOwner(ctype,world,x,y,z) or getPastProtectionOwner(x, y, z) , '%s/%s/%s' % (x,y,z), renders[world], worldnames[world] ) for (date,iamount,itype,idata,ctype,x,y,z,world) in accesses] return [(date, tags.tr (id = rowId) [ [tags.td[s] for s in [ tags.a ( href = '#' + rowId ) [ '#' ], date, 'chest', amount, material, tags.a (href = 'http://mc.dev-urandom.eu/map/#/%s/-2/%s/0' % (pos, render)) [ worldname, '/', pos ], owner ] ] ]) for (rowId, date, amount, material, owner, pos, render, worldname) in rows]
def renderNavbar(self, tag, data): """ :type data: (werkzeug.routing.MapAdapter, None) """ (url, unused) = data currentEndpoint = url.match()[0] burgerToggle = lambda targetId: ( T.button(class_='navbar-toggle', **{'data-toggle': 'collapse', 'data-target': '#%s' % targetId})[ T.span(class_='sr-only')['Toggle navigation'], T.span(class_='icon-bar'), T.span(class_='icon-bar'), T.span(class_='icon-bar'), ] ) mainNavigation = lambda: ( forEach(self.modules, lambda mod: ( T.li(class_='active' if currentEndpoint in mod.endpoints else None)[ T.a(href=url.build(mod.pages[0].endpoint))[mod.name] ] )) ) html = ( T.nav(class_='navbar navbar-default', role='navigation')[ T.div(class_='container-fluid')[ T.div(class_='navbar-header')[ burgerToggle('mainNavCollapse'), T.span(class_='navbar-brand')['Rudykocur Maxwell'] ], T.div(class_='collapse navbar-collapse', id='mainNavCollapse')[ T.ul(class_="nav navbar-nav")[ mainNavigation() ], T.ul(class_="nav navbar-nav navbar-right")[ T.li(class_='dropdown')[ T.a(href='#', class_='dropdown-toggle', **{'data-toggle': 'dropdown'})[ 'Characters', ' ', T.span(class_='caret') ], T.ul(class_='dropdown-menu', role='menu')[ T.li(role='presentation', class_='dropdown-header')['Account: Rudykocur'], T.li[T.a(href='#')['Rudykocur Maxwell']], T.li[T.a(href='#')['Imaginary Profile']], T.li(role='presentation', class_='divider'), T.li(role='presentation', class_='dropdown-header')['Account: Generic'], T.li[T.a(href='#')['All Skills V']], ], ], T.li[ T.a(href=url.build('logout'))['Logout'] ] ] ] ] ] ) return tag[html]
def renderResponse(self, helper, signatures): layout = IGBLayout() layout.addJs('common.js') layout.addJs('scanning.js') layout.addJs('loot.js') if helper.isTrusted: content = [ Panel( heading=[ self._renderHeader(helper), ], content=[ T.div(class_='row')[ T.div(class_='col-xs-8')[ T.textarea(class_="form-control", id="signaturesInput", rows="2", style="overflow: hidden; resize: none", placeholder="Paste scanning content here") ], T.div(class_='col-xs-4')[ T.button(class_='btn btn-default', id='processButton')['Submit'], T.img(id='ajaxLoader', src='/static/images/ajax-loader.gif'), ], ] ] ), Panel(heading=['Known signatures in ', T.strong[helper.systemName], T.div(class_='pull-right')[ T.a(href=self.getUrl('scanning/help'))['How to use this tool'] ]], content=[ T.div(id='bookmarkContainer')[ self.getKnownSignaturesTable(signatures) ], ]), T.script[ """ $(document).ready(function() { BookmarkManager.init({ container: document.getElementById('bookmarkContainer'), processButton: document.getElementById('processButton'), signaturesInput: document.getElementById('signaturesInput'), ajaxLoader: document.getElementById('ajaxLoader'), systemName: '%(system)s' }); LootInterface.init(); }); """ % dict(system=helper.systemName) ] ] layout.setContent(content) return layout