def sidebar(request): """ For each registered game, get a widget to be displayed in sidebar @remark This design needs to be analysed. @todo ordering, using config Returns a 'sidebar' list containing html boxes. """ sidebar = [] # Request blocks from games for game in get_games(): try: w = game.get_sidebar_widget(request) if w: sidebar.append(w) except Exception as e: logging.exception(e) # Request blocks from apps for app in get_apps(): try: w = app.get_sidebar_widget(request) if w: sidebar.append(w) except Exception as e: print e logging.exception(e) return {'sidebar': sidebar}
def header_footer(request): """ Generate header and footer bar contents. """ try: reverse('homepage') except NoReverseMatch: return {} #TODO ordering, using config header = [] try: for game in get_games(): h = game.get_header_link(request) if h: header.append((h, game.get_instance().name)) except Exception as e: logging.exception(e) # add also messages and magic link try: h = Message.get_header_link(request) if h: header.append((h, 'Message')) h = Bazaar.get_header_link(request) if h: header.append((h, 'Magic')) h = Chat.get_header_link(request) if h: header.append((h, 'Chat')) except Exception as e: logging.exception(e) footer = [] try: for game in get_games(): f = game.get_footer_link(request) if f: footer.append(f) except: pass # also add static pages footer.extend(get_static_pages()) for a in get_apps(): f = a.get_footer_link(request) if f: footer.append(a.get_footer_link(request)) # format header hids = lambda p: '<span id="head-%s"><a href="%s">%s</a>%s</span>' % (p[1].lower(), \ p[0]['link'], p[0]['text'], \ '<sup class="unread-count">%d</sup>' % p[0]['count'] if p[0].get('count', False) else '') header_html = " ".join(map(hids, header)) footer = " | ".join(footer) return {'header': header_html, 'heads': header, 'footer': footer}
def sidebar_generator(): for game in get_games() + list(get_apps()): try: w = game.get_sidebar_widget(request) except Exception as e: logging.exception(e) w = None if w: yield w
def footer_generator(): for game in get_games(): f = game.get_footer_link(request) if f: yield f for s in get_static_pages(): yield s for a in get_apps(): f = a.get_footer_link(request) if f: yield f
def read(self, request, type): notifs = {} for app in get_apps(): notifs[app.name()] = app.get_unread_count(request) for game in get_games(): notifs[game.name()] = game.get_unread_count(request) all = sum(notifs.values()) if type == 'all': return {'count': all, 'type': type, 'types': notifs.keys()} elif type in notifs.keys(): return {'count': notifs[type], 'type': type} else: return rc.BAD_REQUEST
def get_all_modifiers(self): """ Fetch modifiers from games and also add system specific ones """ ms = ['dispell', # cancel all spells 'cure', # delete all negative spells 'curse', # prevent cast of positive spells, or cure and dispell 'immunity', # prevent cast of any spells, or cure and dispell 'top-disguise', # allow showing another number of points in top ] for g in get_games(): ms.extend(g.get_modifiers()) from wouso.interface.apps import get_apps for a in get_apps(): ms.extend(a.get_modifiers()) return ms
def handle(self, *args, **options): self.stdout.write('Starting at: %s\n' % datetime.now()) # Now handle other apps from wouso.interface.apps import get_apps apps = get_apps() for a in apps: if a.management_task: self.stdout.write('%s ...\n' % a.name()) a.management_task(stdout=self.stdout) # Now handle games for g in get_games(): if g.management_task: self.stdout.write('%s ...\n' % g.name()) g.management_task(stdout=self.stdout) now = datetime.now() Setting.get('wousocron_lastrun').set_value('%s' % now) self.stdout.write('Finished at: %s\n' % now)