def set_custom_theme(player, theme): from wouso.utils import get_themes from wouso.core.config.models import Setting if theme in get_themes(): Setting.get('theme_user_%d' % player.id).set_value(theme) return True return False
def chat_scripts(): """ Dump the chat scris :return: """ if settings.CHAT_ENABLED and not Setting.get('disable-Chat').get_value(): return render_to_string('chat/setup.html', {'chat_host': Setting.get('chat_host').get_value(), 'chat_port': Setting.get('chat_port').get_value(), 'basepath': settings.FORCE_SCRIPT_NAME, }) return ''
def chat_scripts(): """ Dump the chat scris :return: """ if settings.CHAT_ENABLED and not Setting.get('disable-Chat').get_value(): return render_to_string( 'chat/setup.html', { 'chat_host': Setting.get('chat_host').get_value(), 'chat_port': Setting.get('chat_port').get_value(), 'basepath': settings.FORCE_SCRIPT_NAME, }) return ''
def coin_top_settings(cls): """ Return a list of coin names for which we calculate the top Example: ['gold', 'karma'] """ return [c for c in Setting.get('top-coins').get_value().split(',') if c] or []
def read(self, request): api = { 'api_version': API_VERSION, 'title': Setting.get('title').get_value(), 'authenticated': request.user.is_authenticated() } return api
def coin_top_settings(cls): """ Return a list of coin names for which we calculate the top Example: ['gold', 'karma'] """ return [ c for c in Setting.get('top-coins').get_value().split(',') if c ] or []
def render_zone(context, zone, glue): """ :return: HTML for the sidebar """ s = get_library(zone) order = [k for k in Setting.get('%s-order' % zone).get_value().split(',') if k] if not order: order = s.get_blocks() return glue.join([s.get_block(block, context) for block in order])
def handle(self, *args, **options): self.stdout.write('Starting at: %s\n' % datetime.now()) # Now handle other apps from wouso.interface import get_apps apps = get_apps() for a in apps: 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)
def get_theme(): """ Return the current theme """ global _theme if _theme is None: from wouso.core.config.models import Setting return Setting.get('theme').value return _theme
def get_context_data(self, **kwargs): from wouso.games.quest.models import Quest, QuestGame from django import get_version from wouso.settings import WOUSO_VERSION, DATABASES from wouso.core.config.models import Setting database = DATABASES['default'].copy() database_engine = database['ENGINE'].split('.')[-1] database_name = database['NAME'] future_questions = Schedule.objects.filter( day__gte=datetime.datetime.now()) nr_future_questions = len(future_questions) questions = Question.objects.all() nr_questions = len(questions) active_quest = QuestGame().get_current() total_quests = Quest.objects.all().count() # artifacts artifact_groups = ArtifactGroup.objects.all() # admins staff_group, new = auth.Group.objects.get_or_create(name='Staff') # wousocron last_run last_run = Setting.get('wousocron_lastrun').get_value() if last_run == "": last_run = "wousocron was never run" # online members oldest = datetime.datetime.now() - datetime.timedelta(minutes=10) online_last10 = Player.objects.filter( last_seen__gte=oldest).order_by('-last_seen') # number of players which can play cp_number = Player.objects.filter(race__can_play=True).count() context = super(DashboardView, self).get_context_data(**kwargs) context.update({ 'nr_future_questions': nr_future_questions, 'nr_questions': nr_questions, 'active_quest': active_quest, 'total_quests': total_quests, 'artifact_groups': artifact_groups, 'django_version': get_version(), 'wouso_version': WOUSO_VERSION, 'database_engine': database_engine, 'database_name': database_name, 'staff': staff_group, 'last_run': last_run, 'online_users': online_last10, 'cp_number': cp_number }) return context
def render_zone(context, zone, glue): """ :return: HTML for the sidebar """ s = get_library(zone) order = [ k for k in Setting.get('%s-order' % zone).get_value().split(',') if k ] if not order: order = s.get_blocks() return glue.join([s.get_block(block, context) for block in order])
def setup_user_groups(): # Assistants group, 'Staff' staff = Group.objects.get_or_create(name='Staff')[0] cpanel_perm = Permission.objects.get(codename='change_setting') staff.permissions.add(cpanel_perm) # Default entry race, 'Others' others = Race.objects.get_or_create(name='Others')[0] others.can_play = False others.save() default_race = Setting.get('default_race') default_race.set_value(str(others.pk))
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)
def setup_user_groups(): # Assistants group, 'Staff' staff = Group.objects.get_or_create(name='Staff')[0] cpanel_perm = Permission.objects.get(codename='change_setting') staff.permissions.add(cpanel_perm) # Default entry race, 'Unaffiliated' unaffiliated = Race.objects.get_or_create(name='Unaffiliated')[0] unaffiliated.can_play = False unaffiliated.save() default_race = Setting.get('default_race') default_race.set_value(str(unaffiliated.pk))
def get_context_data(self, **kwargs): from wouso.games.quest.models import Quest, QuestGame from django import get_version from wouso.settings import WOUSO_VERSION, DATABASES from wouso.core.config.models import Setting database = DATABASES['default'].copy() database_engine = database['ENGINE'].split('.')[-1] database_name = database['NAME'] future_questions = Schedule.objects.filter( day__gte=datetime.datetime.now()) nr_future_questions = len(future_questions) questions = Question.objects.all() nr_questions = len(questions) active_quest = QuestGame().get_current() total_quests = Quest.objects.all().count() # artifacts artifact_groups = ArtifactGroup.objects.all() # admins staff_group, new = auth.Group.objects.get_or_create(name='Staff') # wousocron last_run last_run = Setting.get('wousocron_lastrun').get_value() if last_run == "": last_run = "wousocron was never run" # online members oldest = datetime.datetime.now() - datetime.timedelta(minutes=10) online_last10 = Player.objects.filter(last_seen__gte=oldest).order_by( '-last_seen') # number of players which can play cp_number = Player.objects.filter(race__can_play=True).count() context = super(StatusView, self).get_context_data(**kwargs) context.update({'nr_future_questions': nr_future_questions, 'nr_questions': nr_questions, 'active_quest': active_quest, 'total_quests': total_quests, 'artifact_groups': artifact_groups, 'django_version': get_version(), 'wouso_version': WOUSO_VERSION, 'database_engine': database_engine, 'database_name': database_name, 'staff': staff_group, 'last_run': last_run, 'online_users': online_last10, 'cp_number': cp_number}) return context
def dashboard(request): from wouso.games.quest.models import Quest, QuestGame from django import get_version from wouso.settings import WOUSO_VERSION from wouso.core.config.models import Setting future_questions = Schedule.objects.filter( day__gte=datetime.datetime.now()) nr_future_questions = len(future_questions) questions = Question.objects.all() nr_questions = len(questions) active_quest = QuestGame().get_current() total_quests = Quest.objects.all().count() # artifacts artifact_groups = ArtifactGroup.objects.all() # admins staff_group, new = auth.Group.objects.get_or_create(name='Staff') # wousocron last_run last_run = Setting.get('wousocron_lastrun').get_value() if last_run == "": last_run = "wousocron was never run" # online members oldest = datetime.datetime.now() - datetime.timedelta(minutes=10) online_last10 = Player.objects.filter( last_seen__gte=oldest).order_by('-last_seen') # number of players which can play cp_number = Player.objects.filter(race__can_play=True).count() return render_to_response('cpanel/index.html', { 'nr_future_questions': nr_future_questions, 'nr_questions': nr_questions, 'active_quest': active_quest, 'total_quests': total_quests, 'module': 'home', 'artifact_groups': artifact_groups, 'django_version': get_version(), 'wouso_version': WOUSO_VERSION, 'staff': staff_group, 'last_run': last_run, 'online_users': online_last10, 'cp_number': cp_number, }, context_instance=RequestContext(request))
def render_header(context): s = get_library('header') order = [k for k in Setting.get('header-order').get_value().split(',') if k] if not order: order = s.get_blocks() content = '' for block in order: data = s.get_block(block, context) if not data: continue content += '<span id="head-%s"><a href="%s">%s' % (block, data.get('link', ''), data.get('text', '')) if data.get('count', 0): content += '<sup class="unread-count">%s</sup>' % data.get('count') content += '</a></span> ' return content
def dashboard(request): from wouso.games.quest.models import Quest, QuestGame from django import get_version from wouso.settings import WOUSO_VERSION from wouso.core.config.models import Setting future_questions = Schedule.objects.filter(day__gte=datetime.datetime.now()) nr_future_questions = len(future_questions) questions = Question.objects.all() nr_questions = len(questions) active_quest = QuestGame().get_current() total_quests = Quest.objects.all().count() # artifacts artifact_groups = ArtifactGroup.objects.all() # admins staff_group, new = auth.Group.objects.get_or_create(name='Staff') # wousocron last_run last_run = Setting.get('wousocron_lastrun').get_value() if last_run == "": last_run="wousocron was never run" # online members oldest = datetime.datetime.now() - datetime.timedelta(minutes = 10) online_last10 = Player.objects.filter(last_seen__gte=oldest).order_by('-last_seen') # number of players which can play cp_number = Player.objects.filter(race__can_play=True).count() return render_to_response('cpanel/index.html', {'nr_future_questions' : nr_future_questions, 'nr_questions' : nr_questions, 'active_quest': active_quest, 'total_quests': total_quests, 'module': 'home', 'artifact_groups': artifact_groups, 'django_version': get_version(), 'wouso_version': WOUSO_VERSION, 'staff': staff_group, 'last_run': last_run, 'online_users': online_last10, 'cp_number': cp_number, }, context_instance=RequestContext(request))
def render_zone(context, zone, glue): """ :return: HTML for the sidebar """ s = get_library(zone) order = [k for k in Setting.get('%s-order' % zone).get_value().split(',') if k] if not order: order = s.get_blocks() # Do not print blocks with empty contents. non_empty_block_contents = [] for block in order: content = s.get_block(block, context) if content and not content.isspace(): non_empty_block_contents.append(content) return glue.join(non_empty_block_contents)
def render_header(context): s = get_library('header') order = [ k for k in Setting.get('header-order').get_value().split(',') if k ] if not order: order = s.get_blocks() content = '' for block in order: data = s.get_block(block, context) if not data: continue content += '<span id="head-%s"><a href="%s">%s' % ( block, data.get('link', ''), data.get('text', '')) if data.get('count', 0): content += '<sup class="unread-count">%s</sup>' % data.get('count') content += '</a></span> ' return content
def render_zone(context, zone, glue): """ :return: HTML for the sidebar """ s = get_library(zone) order = [ k for k in Setting.get('%s-order' % zone).get_value().split(',') if k ] if not order: order = s.get_blocks() # Do not print blocks with empty contents. non_empty_block_contents = [] for block in order: content = s.get_block(block, context) if content and not content.isspace(): non_empty_block_contents.append(content) return glue.join(non_empty_block_contents)
def dashboard(request): from wouso.games.quest.models import Quest, QuestGame from django import get_version from wouso.settings import WOUSO_VERSION from wouso.core.config.models import Setting future_questions = Schedule.objects.filter(day__gte=datetime.datetime.now()) nr_future_questions = len(future_questions) questions = Question.objects.all() nr_questions = len(questions) active_quest = QuestGame().get_current() total_quests = Quest.objects.all().count() # artifacts artifact_groups = ArtifactGroup.objects.all() # admins staff_group, new = auth.Group.objects.get_or_create(name='Staff') # wousocron last_run last_run = Setting.get('wousocron_lastrun').get_value() return render_to_response('cpanel/index.html', {'nr_future_questions' : nr_future_questions, 'nr_questions' : nr_questions, 'active_quest': active_quest, 'total_quests': total_quests, 'module': 'home', 'artifact_groups': artifact_groups, 'django_version': get_version(), 'wouso_version': WOUSO_VERSION, 'staff': staff_group, 'last_run': last_run, }, context_instance=RequestContext(request))
def post(self, request): data = request.POST['display'] blocks = ','.join([b.strip() for b in data.split(',') if b.strip()]) Setting.get('sidebar-order').set_value(blocks) return redirect('cpanel_display')
def get_context_data(self, **kwargs): s = get_sidebar() sidebar_order = Setting.get('sidebar-order').get_value() or ','.join( s.get_blocks()) return {'display': sidebar_order}
def get_theme_dir(self): """ Note (AE): I'm unhappy with this approach, since a Setting.get call is done for every request. THIS must be cached somehow """ theme = Setting.get('theme').value return os.path.join(settings.THEMES_ROOT, theme, 'templates')
def get_custom_theme(player): from wouso.core.config.models import Setting return Setting.get('theme_user_%d' % player.id).get_value()