Exemplo n.º 1
0
def header_footer(request):
    """ Generate header and footer bar contents.
    """
    #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'))
    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 stats link
    try:
        f = stats_link(request)
        if f:
            footer.append(f)
    except:
        pass

    # also add static pages
    for sp in get_static_pages():
        footer.append(sp.html_link())

    # qporposal
    if not Qproposal.disabled():
        footer.append(Qproposal.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}
Exemplo n.º 2
0
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}
Exemplo n.º 3
0
def setup_staff_groups():
    for g in get_games():
        for group in g.get_staff_and_permissions():
            group_obj = Group.objects.get_or_create(name=group['name'])[0]
            for p in group.get('permissions', []):
                perm_obj = Permission.objects.get(codename=p)
                group_obj.permissions.add(perm_obj)
Exemplo n.º 4
0
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}
Exemplo n.º 5
0
def setup_staff_groups():
    for g in get_games():
        for group in g.get_staff_and_permissions():
            group_obj = Group.objects.get_or_create(name=group['name'])[0]
            for p in group.get('permissions', []):
                perm_obj = Permission.objects.get(codename=p)
                group_obj.permissions.add(perm_obj)
Exemplo n.º 6
0
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 = []

    try:
        # Request blocks from games
        for game in get_games():
            w = game.get_sidebar_widget(request)
            if w:
                sidebar.append(w)

        # Request blocks from apps
        for app in (Top,):
            w = app.get_sidebar_widget(request)
            if w:
                sidebar.append(w)
    except Exception as e:
        logging.error(e)
        # This is a hack for fixing test. TODO: actually fix ./manage.py test

    return {'sidebar': sidebar}
Exemplo n.º 7
0
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 = []

    try:
        # Request blocks from games
        for game in get_games():
            w = game.get_sidebar_widget(request)
            if w:
                sidebar.append(w)

        # Request blocks from apps
        for app in (Top, ):
            w = app.get_sidebar_widget(request)
            if w:
                sidebar.append(w)
    except Exception as e:
        logging.error(e)
        # This is a hack for fixing test. TODO: actually fix ./manage.py test

    return {'sidebar': sidebar}
Exemplo n.º 8
0
 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
Exemplo n.º 9
0
 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
Exemplo n.º 10
0
 def header_generator():
     for game in get_games():
         h = game.get_header_link(request)
         if h:
             yield h, game.get_instance().verbose_name
     for game in [Message, Bazaar, Chat]:
         h = game.get_header_link(request)
         if h:
             yield h, game.__name__
Exemplo n.º 11
0
 def header_generator():
     for game in get_games():
         h = game.get_header_link(request)
         if h:
             yield h, game.get_instance().verbose_name
     for game in [Message, Bazaar, Chat]:
         h = game.get_header_link(request)
         if h:
             yield h, game.__name__
Exemplo n.º 12
0
def games(request):
    """ List of games """
    wgs = []
    for model in get_games():
        wgs.append({'link': model._meta.app_label,
                    'name': model._meta.verbose_name})

    return render_to_response('interface/games.html',
                              {'games': wgs},
                              context_instance=RequestContext(request))
Exemplo n.º 13
0
 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
Exemplo n.º 14
0
 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
Exemplo n.º 15
0
 def _user_points(user):
     """ :return: a list of (game, points) - distribution of points per source """
     points = {}
     for game in get_games() + [None]:
         pp = History.user_points_from_game(user=user, game=game, zeros=False)
         if pp:
             if game:
                 points[game.get_instance().verbose_name] = pp
             else:
                 points['wouso'] = pp
     return points
Exemplo n.º 16
0
Arquivo: god.py Projeto: LucianU/wouso
    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
              'steal',  # allow users to steal points, one from another
        ]
        for g in get_games():
            ms.extend(g.get_modifiers())

        return ms
Exemplo n.º 17
0
def user_profile(request, id, page=u'1'):
    try:
        profile = Player.objects.get(id=id)
    except Player.DoesNotExist:
        raise Http404

    # TODO: parca exista o functie in core pentru gravatar
    avatar = "http://www.gravatar.com/avatar/%s.jpg?d=monsterid"\
        % md5(profile.user.email).hexdigest()
    activity_list = Activity.get_player_activity(profile)

    top_user = profile.get_extension(TopUser)
    #top_user.topgroups = list(profile.groups.all())
    #for g in top_user.topgroups:
    #    g.week_evolution = top_user.week_evolution(relative_to=g)
    #    g.position = TopHistory.get_user_position(top_user, relative_to=g)
    history = History.user_points(profile)
    paginator = Paginator(activity_list, 10)

    try:
        activity = paginator.page(page)
    except (EmptyPage, InvalidPage):
        activity = paginator.page(paginator.num_pages)

    profile_actions = ''
    profile_superuser_actions = ''
    for g in get_games():
        profile_actions += g.get_profile_actions(request, profile)
        profile_superuser_actions += g.get_profile_superuser_actions(request, profile)

        # some hackish introspection
        if hasattr(g, 'user_model'):
            model = getattr(g, 'user_model')
            setattr(profile, model.__name__.lower(), profile.get_extension(model))
    #Fix to show succes message from report user form
    if 'report_msg' in request.session:
        message = request.session['report_msg']
        del request.session['report_msg']
    else:
        message=''

    return render_to_response('profile/profile.html',
                              {'profile': profile,
                               'avatar': avatar,
                               'activity': activity,
                               'top': top_user,
                               'scoring': history,
                               'profile_actions': profile_actions,
                               'profile_superuser_actions': profile_superuser_actions,
                               'message': message, },
                              context_instance=RequestContext(request))
Exemplo n.º 18
0
def get_cpanel_games():
    """
     Returns a dict of games having a cpanel page:
        gs({'games/specialquest':'Special Quest'})
    """
    gs = {}
    for game in get_games():
        game = game.__name__.replace('Game', '')
        if has_cpanel_url(game.lower()):
            url = 'games/' + game.lower()
            # Add space before capital letters (e.g. Special Quest)
            gs[url] = re.sub(r"(\w)([A-Z])", r"\1 \2", game)

    return gs
Exemplo n.º 19
0
    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
            'steal',  # allow users to steal points, one from another
        ]
        for g in get_games():
            ms.extend(g.get_modifiers())

        return ms
Exemplo n.º 20
0
def get_cpanel_games():
    """
     Returns a dict of games having a cpanel page:
        gs({'games/specialquest':'Special Quest'})
    """
    gs = {}
    for game in get_games():
        game = game.__name__.replace('Game', '')
        if has_cpanel_url(game.lower()):
            url = 'games/' + game.lower()
            # Add space before capital letters (e.g. Special Quest)
            gs[url] = re.sub(r"(\w)([A-Z])", r"\1 \2", game)

    return gs
Exemplo n.º 21
0
    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
Exemplo n.º 22
0
    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
Exemplo n.º 23
0
def user_profile(request, id, page=u'1'):
    try:
        profile = Player.objects.get(id=id)
    except Player.DoesNotExist:
        raise Http404

    avatar = "http://www.gravatar.com/avatar/%s.jpg?d=monsterid"\
        % md5(profile.user.email).hexdigest()
    activity_list = Activity.objects.\
        filter(Q(user_to=id) | Q(user_from=id)).order_by('-timestamp')

    top_user = profile.get_extension(TopUser)
    top_user.topgroups = list(profile.groups.all().order_by('-gclass'))
    for g in top_user.topgroups:
        g.week_evolution = top_user.week_evolution(relative_to=g)
        g.position = TopHistory.get_user_position(top_user, relative_to=g)
    history = History.user_points(profile)
    paginator = Paginator(activity_list, 10)

    try:
        activity = paginator.page(page)
    except (EmptyPage, InvalidPage):
        activity = paginator.page(paginator.num_pages)

    profile_actions = ''
    profile_superuser_actions = ''
    for g in get_games():
        profile_actions += g.get_profile_actions(request, profile)
        profile_superuser_actions += g.get_profile_superuser_actions(
            request, profile)

        # some hackish introspection
        if hasattr(g, 'user_model'):
            model = getattr(g, 'user_model')
            setattr(profile, model.__name__.lower(),
                    profile.get_extension(model))

    return render_to_response(
        'profile/profile.html', {
            'profile': profile,
            'avatar': avatar,
            'activity': activity,
            'top': top_user,
            'scoring': history,
            'profile_actions': profile_actions,
            'profile_superuser_actions': profile_superuser_actions,
        },
        context_instance=RequestContext(request))
Exemplo n.º 24
0
 def user_points(user):
     """ :return: a list of (game, points) - distribution of points per source """
     points = {}
     coins = History.user_coins(user)
     for game in get_games():
         pp = {}
         hs = History.objects.filter(user=user, game=game.get_instance())
         for h in hs:
             if h.coin in pp.keys():
                 pp[h.coin] += h.amount
             else:
                 pp[h.coin] = h.amount
         if pp.keys():
             points[game.get_instance().verbose_name] = pp
     # TODO: also get points without a game origin
     return points
Exemplo n.º 25
0
 def user_points(user):
     """ :return: a list of (game, points) - distribution of points per source """
     points = {}
     coins = History.user_coins(user)
     for game in get_games():
         pp = {}
         hs = History.objects.filter(user=user, game=game.get_instance())
         for h in hs:
             if h.coin in pp.keys():
                 pp[h.coin] += h.amount
             else:
                 pp[h.coin] = h.amount
         if pp.keys():
             points[game.get_instance().verbose_name] = pp
     # TODO: also get points without a game origin
     return points
Exemplo n.º 26
0
def user_profile(request, id, page=u'1'):
    if int(id) == request.user.get_profile().id:
        profile = request.user.get_profile()
    else:
        profile = get_object_or_404(Player, id=id)

    activity_list = Activity.get_player_activity(profile)

    top_user = profile.get_extension(TopUser)
    #top_user.topgroups = list(profile.groups.all())
    #for g in top_user.topgroups:
    #    g.week_evolution = top_user.week_evolution(relative_to=g)
    #    g.position = TopHistory.get_user_position(top_user, relative_to=g)
    history = History.user_points(profile)
    paginator = Paginator(activity_list, 10)

    try:
        activity = paginator.page(page)
    except (EmptyPage, InvalidPage):
        activity = paginator.page(paginator.num_pages)

    profile_actions = ''
    profile_superuser_actions = ''
    for g in get_games():
        profile_actions += g.get_profile_actions(request, profile)
        profile_superuser_actions += g.get_profile_superuser_actions(request, profile)

        # some hackish introspection
        if hasattr(g, 'user_model'):
            model = getattr(g, 'user_model')
            setattr(profile, model.__name__.lower(), profile.get_extension(model))
    #Fix to show succes message from report user form
    if 'report_msg' in request.session:
        message = request.session['report_msg']
        del request.session['report_msg']
    else:
        message=''

    return render_to_response('profile/profile.html',
                              {'profile': profile,
                               'activity': activity,
                               'top': top_user,
                               'scoring': history,
                               'profile_actions': profile_actions,
                               'profile_superuser_actions': profile_superuser_actions,
                               'message': message, },
                              context_instance=RequestContext(request))
Exemplo n.º 27
0
    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
Exemplo n.º 28
0
    def user_points(user):
        """ :return: a list of (game, points) - distribution of points per source """
        points = {}
        for game in get_games() + [None]:
            pp = {}
            hs = History.objects.filter(user=user, game=game.get_instance() if game else game)
            for h in hs:
                if h.coin in pp.keys():
                    pp[h.coin] += h.amount
                else:
                    pp[h.coin] = h.amount
            if pp:
                if game:
                    points[game.get_instance().verbose_name] = pp
                else:
                    points["wouso"] = pp

        return points
Exemplo n.º 29
0
def user_profile(request, id, page=u'1'):
    try:
        profile = Player.objects.get(id=id)
    except Player.DoesNotExist:
        raise Http404

    avatar = "http://www.gravatar.com/avatar/%s.jpg?d=monsterid"\
        % md5(profile.user.email).hexdigest()
    activity_list = Activity.objects.\
        filter(Q(user_to=id) | Q(user_from=id)).order_by('-timestamp')

    top_user = profile.get_extension(TopUser)
    top_user.topgroups = list(profile.groups.all().order_by('-gclass'))
    for g in top_user.topgroups:
        g.week_evolution = top_user.week_evolution(relative_to=g)
        g.position = TopHistory.get_user_position(top_user, relative_to=g)
    history = History.user_points(profile)
    paginator = Paginator(activity_list, 10)

    try:
        activity = paginator.page(page)
    except (EmptyPage, InvalidPage):
        activity = paginator.page(paginator.num_pages)

    profile_actions = ''
    profile_superuser_actions = ''
    for g in get_games():
        profile_actions += g.get_profile_actions(request, profile)
        profile_superuser_actions += g.get_profile_superuser_actions(request, profile)

        # some hackish introspection
        if hasattr(g, 'user_model'):
            model = getattr(g, 'user_model')
            setattr(profile, model.__name__.lower(), profile.get_extension(model))

    return render_to_response('profile/profile.html',
                              {'profile': profile,
                               'avatar': avatar,
                               'activity': activity,
                               'top': top_user,
                               'scoring': history,
                               'profile_actions': profile_actions,
                               'profile_superuser_actions': profile_superuser_actions,},
                              context_instance=RequestContext(request))
Exemplo n.º 30
0
    def user_points(user):
        """ :return: a list of (game, points) - distribution of points per source """
        points = {}
        for game in get_games() + [None]:
            pp = {}
            hs = History.objects.filter(
                user=user, game=game.get_instance() if game else game)
            for h in hs:
                if h.coin in pp.keys():
                    pp[h.coin] += h.amount
                else:
                    pp[h.coin] = h.amount
            if pp:
                if game:
                    points[game.get_instance().verbose_name] = pp
                else:
                    points['wouso'] = pp

        return points
Exemplo n.º 31
0
Arquivo: sm.py Projeto: LucianU/wouso
def setup():
    """ Prepare database for Scoring """
    for cc in CORE_POINTS:
        if not Coin.get(cc):
            Coin.add(cc, name=cc)
    # special case, gold is integer
    gold = Coin.get('gold')
    gold.integer = True
    gold.save()

    # iterate through games and register formulas
    for game in get_games():
        for formula in game.get_formulas():
            if not Formula.get(formula.id):
                Formula.add(formula)
    # add wouso formulas
    for formula in God.get_system_formulas():
        if not Formula.get(formula.id):
            Formula.add(formula)
Exemplo n.º 32
0
def user_profile(request, id, page=u'1'):
    profile = get_object_or_404(Player, id=id)

    activity_list = Activity.get_player_activity(profile)

    top_user = profile.get_extension(TopUser)
    history = History.user_points(profile.user)
    paginator = Paginator(activity_list, 10)

    try:
        activity = paginator.page(page)
    except (EmptyPage, InvalidPage):
        activity = paginator.page(paginator.num_pages)

    profile_actions = ''
    profile_superuser_actions = ''
    for g in get_games():
        profile_actions += g.get_profile_actions(request, profile)
        profile_superuser_actions += g.get_profile_superuser_actions(
            request, profile)

        # some hackish introspection
        if hasattr(g, 'user_model'):
            model = getattr(g, 'user_model')
            setattr(profile, model.__name__.lower(),
                    profile.get_extension(model))
    #Fix to show succes message from report user form
    if 'report_msg' in request.session:
        message = request.session['report_msg']
        del request.session['report_msg']
    else:
        message = ''

    return render_to_response('profile/profile.html', {
        'profile': profile,
        'activity': activity,
        'top': top_user,
        'scoring': history,
        'profile_actions': profile_actions,
        'profile_superuser_actions': profile_superuser_actions,
        'message': message,
    },
                              context_instance=RequestContext(request))
Exemplo n.º 33
0
def setup():
    """ Prepare database for Scoring """
    for cc in CORE_POINTS:
        if not Coin.get(cc):
            Coin.add(cc, name=cc)
    # special case, gold is integer
    gold = Coin.get('gold')
    gold.integer = True
    gold.save()

    # iterate through games and register formulas
    for game in get_games():
        for formula in game.get_formulas():
            if not Formula.get(formula.id):
                Formula.add(formula)
    # add wouso formulas
    for formula in God.get_system_formulas():
        if not Formula.get(formula.id):
            Formula.add(formula)
Exemplo n.º 34
0
    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)
Exemplo n.º 35
0
def homepage(request, page=u"1"):
    """ First page shown """
    if request.user.is_anonymous():
        return anonymous_homepage(request)

    profile = request.user.get_profile()
    # gather users online in the last ten minutes
    oldest = datetime.datetime.now() - datetime.timedelta(minutes=10)
    online_last10 = Player.objects.filter(last_seen__gte=oldest).order_by("-last_seen")
    activity = get_wall(page)

    topuser = profile.get_extension(TopUser)
    topgroups = [profile.group] if profile.group else []
    for g in topgroups:
        g.position = TopHistory.get_user_position(topuser, relative_to=g)

    if detect_mobile(request):
        template = "mobile_index.html"
    else:
        template = "site_index.html"

    news = NewsItem.objects.all().order_by("-date_pub", "-id")
    more = False
    if len(news) > 10:
        more = True
    news = news[:10]

    return render_to_response(
        template,
        {
            "last10": online_last10,
            "activity": activity,
            "is_homepage": True,
            "top": topuser,
            "topgroups": topgroups,
            "games": get_games(),
            "news": news,
            "more": more,
        },
        context_instance=RequestContext(request),
    )
Exemplo n.º 36
0
    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)
Exemplo n.º 37
0
def homepage(request, page=u'1'):
    """ First page shown """
    if request.user.is_anonymous():
        return anonymous_homepage(request)

    profile = request.user.get_profile()
    # gather users online in the last ten minutes
    oldest = datetime.datetime.now() - datetime.timedelta(minutes=10)
    online_last10 = Player.objects.filter(
        last_seen__gte=oldest).order_by('-last_seen')
    activity = get_wall(page)

    topuser = profile.get_extension(TopUser)
    topgroups = [profile.group] if profile.group else []
    for g in topgroups:
        g.position = TopHistory.get_user_position(topuser, relative_to=g)

    if detect_mobile(request) and BoolSetting.get(
            'setting-mobile-version').get_value():
        template = 'mobile_index.html'
    else:
        template = 'site_index.html'

    news = NewsItem.objects.all().order_by('-date_pub', '-id')
    more = False
    if len(news) > 10:
        more = True
    news = news[:10]

    return render_to_response(template, {
        'last10': online_last10,
        'activity': activity,
        'is_homepage': True,
        'top': topuser,
        'topgroups': topgroups,
        'games': get_games(),
        'news': news,
        'more': more,
    },
                              context_instance=RequestContext(request))
Exemplo n.º 38
0
def homepage(request, page=u'1'):
    """ First page shown """
    if request.user.is_anonymous():
        return anonymous_homepage(request)

    profile = request.user.get_profile()
    # gather users online in the last ten minutes
    oldest = datetime.datetime.now() - datetime.timedelta(minutes = 10)
    online_last10 = Player.objects.filter(last_seen__gte=oldest).order_by('-last_seen')
    activity = get_wall(page)

    topuser = profile.get_extension(TopUser)
    topgroups = [profile.group] if profile.group else []
    for g in topgroups:
        g.position = TopHistory.get_user_position(topuser, relative_to=g)

    if detect_mobile(request):
        template = 'mobile_index.html'
    else:
        template = 'site_index.html'

    news = NewsItem.objects.all().order_by('-date_pub', '-id')
    more = False
    if len(news) > 10:
        more = True
    news = news[:10]

    return render_to_response(template,
                              {'last10': online_last10, 'activity': activity,
                              'is_homepage': True,
                              'top': topuser,
                              'topgroups': topgroups,
                              'games': get_games(),
                              'news': news,
                              'more': more,
                              },
                              context_instance=RequestContext(request))
Exemplo n.º 39
0
    def props(self):
        p = []
        for g in get_games():
            p.append(BoolSetting.get('disable-%s' % g.__name__))

        return p
Exemplo n.º 40
0
    url(r'^messages/archive/(?P<id>\d+)/$', Resource(handler=MessagesArchive, **ad)),
    url(r'^messages/unarchive/(?P<id>\d+)/$', Resource(handler=MessagesUnarchive, **ad)),

    url(r'^top/race/$', Resource(handler=TopRaces, **ad)),
    url(r'^top/group/$', Resource(handler=TopGroups, **ad)),
    url(r'^top/race/(?P<race_id>\d+)/group/$', Resource(handler=TopGroups, **ad)),
    url(r'^top/player/$', Resource(handler=TopPlayers, **ad)),
    url(r'^top/race/(?P<race_id>\d+)/player/$', Resource(handler=TopPlayers, **ad)),
    url(r'^top/group/(?P<group_id>\d+)/player/$', Resource(handler=TopPlayers, **ad)),

    url(r'^group/$', Resource(handler=GroupsHandler, **ad)),
    url(r'^group/(?P<group_id>\d+)/$', Resource(handler=GroupHandler, **ad)),
    url(r'^group/(?P<group_id>\d+)/(?P<type>activity)/$', Resource(handler=GroupHandler, **ad)),
    url(r'^group/(?P<group_id>\d+)/(?P<type>evolution)/$', Resource(handler=GroupHandler, **ad)),
    url(r'^group/(?P<group_id>\d+)/members/$', Resource(handler=GroupMembersHandler, **ad)),

    url(r'^race/$', Resource(handler=RacesHandler, **ad)),
    url(r'^race/(?P<race_id>\d+)/members/$', Resource(handler=RaceMembersHandler, **ad)),
    url(r'^race/(?P<race_id>\d+)/groups/$', Resource(handler=GroupsHandler, **ad)),

    url(r'^category/(?P<category>\w+)/tags$', Resource(handler=CategoryTagsHandler)),
    url(r'^lesson_category/(?P<category>\w+)/lesson_tags$', Resource(handler=LessonCategoryTagsHandler)),
)

for g in get_games():
    api = g.get_api()
    if api:
        for k, v in api.iteritems():
            resource = Resource(handler=v, **ad)
            urlpatterns += patterns('', url(k, resource))
Exemplo n.º 41
0
    def props(self):
        p = []
        for g in get_games():
            p.append(BoolSetting.get('setting-%s' % g.__name__.lower()))

        return p
Exemplo n.º 42
0
    def props(self):
        p = []
        for g in get_games():
            p.append(BoolSetting.get('disable-%s' % g.__name__))

        return p
Exemplo n.º 43
0
                                                        **ad)),
    url(r'^top/player/$', Resource(handler=TopPlayers, **ad)),
    url(r'^top/race/(?P<race_id>\d+)/player/$',
        Resource(handler=TopPlayers, **ad)),
    url(r'^top/group/(?P<group_id>\d+)/player/$',
        Resource(handler=TopPlayers, **ad)),
    url(r'^group/$', Resource(handler=GroupsHandler, **ad)),
    url(r'^group/(?P<group_id>\d+)/$', Resource(handler=GroupHandler, **ad)),
    url(r'^group/(?P<group_id>\d+)/(?P<type>activity)/$',
        Resource(handler=GroupHandler, **ad)),
    url(r'^group/(?P<group_id>\d+)/(?P<type>evolution)/$',
        Resource(handler=GroupHandler, **ad)),
    url(r'^group/(?P<group_id>\d+)/members/$',
        Resource(handler=GroupMembersHandler, **ad)),
    url(r'^race/$', Resource(handler=RacesHandler, **ad)),
    url(r'^race/(?P<race_id>\d+)/members/$',
        Resource(handler=RaceMembersHandler, **ad)),
    url(r'^race/(?P<race_id>\d+)/groups/$',
        Resource(handler=GroupsHandler, **ad)),
    url(r'^category/(?P<category>\w+)/tags$',
        Resource(handler=CategoryTagsHandler)),
    url(r'^lesson_category/(?P<category>\w+)/lesson_tags$',
        Resource(handler=LessonCategoryTagsHandler)),
)

for g in get_games():
    api = g.get_api()
    if api:
        for k, v in api.iteritems():
            resource = Resource(handler=v, **ad)
            urlpatterns += patterns('', url(k, resource))