def confirm_orders(request, slug=''):
	""" Confirms orders and expenses in Order Writing phase """
	game = get_object_or_404(Game, slug=slug)
	player = get_object_or_404(Player, game=game, user=request.user, done=False)
	if request.method == 'POST':
		msg = u"Confirming orders for player %s (%s, %s) in game %s (%s):\n" % (player.id,
			player.static_name,
			player.user.username,
			game.id,
			game.slug) 
		sent_orders = player.order_set.all()
		for order in sent_orders:
			msg += u"%s => " % order.format()
			if order.is_possible():
				order.confirm()
				msg += u"OK\n"
			else:
				msg += u"Invalid\n"
		## confirm expenses
		player.expense_set.all().update(confirmed=True)
		if logging:
			logging.info(msg)
		player.end_phase()
		messages.success(request, _("You have successfully confirmed your actions."))
	return redirect(game)		
def log_event(event_class, game, **kwargs):
	""" Creates a new BaseEvent and its child event. """
	try:
		event = event_class(game=game, year=game.year, season=game.season, phase=game.phase, **kwargs)
		event.save()
	except:
		if logging:
			logging.info("Error in log_event")
 def handle_noargs(self, **options):
     to_heal = models.CondottieriProfile.objects.filter(karma__lt=settings.KARMA_TO_JOIN)
     for profile in to_heal:
         profile.karma += 2
         profile.save()
         if profile.karma >= settings.KARMA_TO_JOIN:
             if notification:
                 notification.send([profile.user], "karma_healed", {}, True)
     msg = "Healed karma to %s users" % len(to_heal)
     if len(to_heal) > 0:
         logging.info(msg)
Beispiel #4
0
    def get_view(request, *arg, **kw):
        logging.info("Get " + name)
        if 'filter' in request.GET:
            selfs = cls.objects.filter(**django.utils.simplejson.loads(request.GET['filter']))
        else:
            selfs = cls.objects.all()
        if 'order_by' in request.GET:
            selfs = selfs.order_by(*django.utils.simplejson.loads(request.GET['order_by']))

        res = {name: selfs}
        res.update(expand_foreign_keys(selfs, follow_foreign_keys))
        return res
	def handle_noargs(self, **options):
		## check first if the ranking is outdated
		server = Server.objects.get()
		if not server.ranking_outdated:
			return

		profile_list = profiles.CondottieriProfile.objects.filter(total_score__gt=0)
		last_game = machiavelli.Game.objects.order_by('-finished')[0]
		now = last_game.finished
		msg = "Recalculating weighted scores\n"
		msg += "Reference date: %s\n" % now
		msg += "Found %s profiles\n" % profile_list.count()
		c = 0
		for p in profile_list:
			scores = machiavelli.Score.objects.filter(user=p.user)
			weighted = 0
			for s in scores:
				age = now - s.created_at
				if age <= threshold:
					months = age.days / 30
				else:
					months = threshold.days / 30
				factor = 1.0 - ( months * deval )
				w = s.points * factor
				weighted += w
			p.weighted_score = int(round(weighted))
			p.save()
			c += 1
		msg += "Processed %s profiles\n" % c

		server.ranking_last_update = datetime.now()
		server.ranking_outdated = False
		server.save()
		msg += "Server updated\n"

		if logging:
			logging.info(msg)
		else:
			print msg
Beispiel #6
0
            raise AttributeError(name)

    def __setattr__(self, name, value):
        self[name] = value

    def __delattr__(self, name):
        del self[name]


# To consistently use the fastest serializer possible, use:
#   from signalqueue.utils import json
# ... so if you need to swap a library, do it here.
try:
    import ujson as json
except ImportError:
    logg.info("--- Loading czjson in leu of ujson")
    try:
        import czjson as json
    except ImportError:
        logg.info("--- Loading yajl in leu of czjson")
        try:
            import yajl as json
            assert hasattr(json, 'loads')
            assert hasattr(json, 'dumps')
        except (ImportError, AssertionError):
            logg.info("--- Loading simplejson in leu of yajl")
            try:
                import simplejson as json
            except ImportError:
                logg.info(
                    "--- Loading stdlib json module in leu of simplejson")
            raise AttributeError(name)

    def __setattr__(self, name, value):
        self[name] = value

    def __delattr__(self, name):
        del self[name]


# To consistently use the fastest serializer possible, use:
#   from signalqueue.utils import json
# ... so if you need to swap a library, do it here.
try:
    import ujson as json
except ImportError:
    logg.info("--- Loading czjson in leu of ujson")
    try:
        import czjson as json
    except ImportError:
        logg.info("--- Loading yajl in leu of czjson")
        try:
            import yajl as json

            assert hasattr(json, "loads")
            assert hasattr(json, "dumps")
        except (ImportError, AssertionError):
            logg.info("--- Loading simplejson in leu of yajl")
            try:
                import simplejson as json
            except ImportError:
                logg.info("--- Loading stdlib json module in leu of simplejson")