Beispiel #1
0
def execute():
    try:
        change_game_instance_status(DEMO_NAME, new_status="terminated")
        delete_game_instance(DEMO_NAME)
    except UsageError as e:
        print("Exception swallowed:", e)
    create_game_instance(game_instance_id=DEMO_NAME,
                         creator_login="******")
Beispiel #2
0
def execute():
    try:
        change_game_instance_status(DEMO_NAME, new_status="terminated")
        delete_game_instance(DEMO_NAME)
    except UsageError, e:
        print "Exception swallowed:", e
def manage_instances(request):

    session_token_display = None
    game_creation_form = None
    require_email = False # superuser does what he wants

    try:
        if request.method == "POST":

            if request.POST.get("create_game_instance"):
                game_creation_form = GameInstanceCreationForm(require_email=require_email, data=request.POST)
                if game_creation_form.is_valid():
                    cleaned_data = game_creation_form.cleaned_data
                    game_instance_id = cleaned_data["game_instance_id"]
                    creator_login = cleaned_data["creator_login"]
                    creator_email = cleaned_data["creator_email"] or None
                    datamanager_administrator.create_game_instance(game_instance_id=game_instance_id,
                                                                     creator_login=creator_login,
                                                                     creator_email=creator_email,
                                                                     skip_randomizations=False)
                    messages.add_message(request, messages.INFO, _(u"Game instance '%(game_instance_id)s' successfully created for '%(creator_login)s/%(creator_email)s'") %
                                                                    SDICT(game_instance_id=game_instance_id, creator_login=creator_login, creator_email=creator_email))
                    game_creation_form = None
                else:
                    messages.add_message(request, messages.ERROR, _(u"Invalid game creation form submitted."))
            elif request.POST.get("lock_instance"):
                game_instance_id = request.POST["lock_instance"]
                maintenance_until = datetime.utcnow() + timedelta(minutes=GAME_INSTANCE_MAINTENANCE_LOCKING_DELAY_MN)
                datamanager_administrator.change_game_instance_status(game_instance_id=game_instance_id, maintenance_until=maintenance_until)
                messages.add_message(request, messages.INFO, _(u"Game instance '%(game_instance_id)s' successfully locked") % SDICT(game_instance_id=game_instance_id))
            elif request.POST.get("unlock_instance"):
                game_instance_id = request.POST["unlock_instance"]
                datamanager_administrator.change_game_instance_status(game_instance_id=game_instance_id, maintenance_until=None) # removes maintenance
                messages.add_message(request, messages.INFO, _(u"Game instance '%(game_instance_id)s' successfully unlocked") % SDICT(game_instance_id=game_instance_id))
            elif request.POST.get("change_instance_status"):
                game_instance_id = request.POST["change_instance_status"]
                new_status = request.POST["new_status"]
                datamanager_administrator.change_game_instance_status(game_instance_id=game_instance_id, new_status=new_status) # change status
                messages.add_message(request, messages.INFO, _(u"Game instance '%(game_instance_id)s' status changed to '%(new_status)s'") % SDICT(game_instance_id=game_instance_id, new_status=new_status))
            elif request.POST.get("delete_game_instance"):
                game_instance_id = request.POST["delete_game_instance"]
                datamanager_administrator.delete_game_instance(game_instance_id=game_instance_id)
                messages.add_message(request, messages.INFO, _(u"Game instance '%(game_instance_id)s' was deleted") % SDICT(game_instance_id=game_instance_id))
            elif request.POST.get("backup_game_instance"):
                game_instance_id = request.POST["backup_game_instance"]
                backup_comment = slugify(request.POST["backup_comment"].strip()) or None
                datamanager_administrator.backup_game_instance_data(game_instance_id=game_instance_id, comment=backup_comment)
                messages.add_message(request, messages.INFO, _(u"Game instance '%(game_instance_id)s' backup with comment '%(backup_comment)s' done") %
                                                               SDICT(game_instance_id=game_instance_id, backup_comment=(backup_comment or u"<empty>")))
            elif request.POST.get("compute_enforced_session_ticket"):
                game_instance_id = request.POST["game_instance_id"].strip() # manually entered
                login = request.POST["login"].strip()
                is_observer = bool(request.POST.get("is_observer"))
                authentication_token = authentication.compute_enforced_login_token(game_instance_id=game_instance_id, login=login, is_observer=is_observer)
                messages.add_message(request, messages.INFO, _(u"Auto-connection token for instance=%(game_instance_id)s, login=%(login)s and is_observer=%(is_observer)s is displayed below") %
                                                               SDICT(game_instance_id=game_instance_id, login=login, is_observer=is_observer))
                session_token_display = urlencode({authentication.ENFORCED_SESSION_TICKET_NAME: authentication_token})
            else:
                raise ValueError(_("Unknown admin action"))

    except Exception as e:
        messages.add_message(request, messages.ERROR, _(u"Unexpected error: %s") % e)

    instances_metadata = datamanager_administrator.get_all_instances_metadata()

    for _meta in instances_metadata:
        _activation_link = _build_activation_url(game_instance_id=_meta["instance_id"], creator_login=_meta["creator_login"], creator_email=_meta["creator_email"])
        _meta["activation_link"] = _activation_link

    return render(request,
                  "meta_administration/manage_instances.html",
                    {
                     'instances_metadata': instances_metadata, # enriched info
                     'utc_now': datetime.utcnow(),
                     'notifications': get_messages(request),
                     'possible_game_statuses': sorted(GAME_STATUSES),
                     'deletable_statuses': [GAME_STATUSES.terminated, GAME_STATUSES.aborted],
                     'game_creation_form': game_creation_form or GameInstanceCreationForm(require_email=require_email),
                     'session_token_display': session_token_display,
                    })
def manage_instances(request):
    session_token_display = None
    game_creation_form = None
    require_email = False  # superuser does what he wants

    try:
        if request.method == "POST":

            if request.POST.get("create_game_instance"):
                game_creation_form = GameInstanceCreationForm(
                    require_email=require_email, data=request.POST)
                if game_creation_form.is_valid():
                    cleaned_data = game_creation_form.cleaned_data
                    game_instance_id = cleaned_data["game_instance_id"]
                    creator_login = cleaned_data["creator_login"]
                    creator_email = cleaned_data["creator_email"] or None
                    datamanager_administrator.create_game_instance(
                        game_instance_id=game_instance_id,
                        creator_login=creator_login,
                        creator_email=creator_email,
                        skip_randomizations=False)
                    messages.add_message(
                        request, messages.INFO,
                        _("Game instance '%(game_instance_id)s' successfully created for '%(creator_login)s/%(creator_email)s'"
                          ) % SDICT(game_instance_id=game_instance_id,
                                    creator_login=creator_login,
                                    creator_email=creator_email))
                    game_creation_form = None
                else:
                    messages.add_message(
                        request, messages.ERROR,
                        _("Invalid game creation form submitted."))
            elif request.POST.get("lock_instance"):
                game_instance_id = request.POST["lock_instance"]
                maintenance_until = datetime.utcnow() + timedelta(
                    minutes=GAME_INSTANCE_MAINTENANCE_LOCKING_DELAY_MN)
                datamanager_administrator.change_game_instance_status(
                    game_instance_id=game_instance_id,
                    maintenance_until=maintenance_until)
                messages.add_message(
                    request, messages.INFO,
                    _("Game instance '%(game_instance_id)s' successfully locked"
                      ) % SDICT(game_instance_id=game_instance_id))
            elif request.POST.get("unlock_instance"):
                game_instance_id = request.POST["unlock_instance"]
                datamanager_administrator.change_game_instance_status(
                    game_instance_id=game_instance_id,
                    maintenance_until=None)  # removes maintenance
                messages.add_message(
                    request, messages.INFO,
                    _("Game instance '%(game_instance_id)s' successfully unlocked"
                      ) % SDICT(game_instance_id=game_instance_id))
            elif request.POST.get("change_instance_status"):
                game_instance_id = request.POST["change_instance_status"]
                new_status = request.POST["new_status"]
                datamanager_administrator.change_game_instance_status(
                    game_instance_id=game_instance_id,
                    new_status=new_status)  # change status
                messages.add_message(
                    request, messages.INFO,
                    _("Game instance '%(game_instance_id)s' status changed to '%(new_status)s'"
                      ) % SDICT(game_instance_id=game_instance_id,
                                new_status=new_status))
            elif request.POST.get("delete_game_instance"):
                game_instance_id = request.POST["delete_game_instance"]
                datamanager_administrator.delete_game_instance(
                    game_instance_id=game_instance_id)
                messages.add_message(
                    request, messages.INFO,
                    _("Game instance '%(game_instance_id)s' was deleted") %
                    SDICT(game_instance_id=game_instance_id))
            elif request.POST.get("backup_game_instance"):
                game_instance_id = request.POST["backup_game_instance"]
                backup_comment = slugify(
                    request.POST["backup_comment"].strip()) or None
                datamanager_administrator.backup_game_instance_data(
                    game_instance_id=game_instance_id, comment=backup_comment)
                messages.add_message(
                    request, messages.INFO,
                    _("Game instance '%(game_instance_id)s' backup with comment '%(backup_comment)s' done"
                      ) % SDICT(game_instance_id=game_instance_id,
                                backup_comment=(backup_comment or "<empty>")))
            elif request.POST.get("compute_enforced_session_ticket"):
                game_instance_id = request.POST["game_instance_id"].strip(
                )  # manually entered
                login = request.POST["login"].strip()
                is_observer = bool(request.POST.get("is_observer"))
                authentication_token = authentication.compute_enforced_login_token(
                    game_instance_id=game_instance_id,
                    login=login,
                    is_observer=is_observer)
                messages.add_message(
                    request, messages.INFO,
                    _("Auto-connection token for instance=%(game_instance_id)s, login=%(login)s and is_observer=%(is_observer)s is displayed below"
                      ) % SDICT(game_instance_id=game_instance_id,
                                login=login,
                                is_observer=is_observer))
                session_token_display = urlencode({
                    authentication.ENFORCED_SESSION_TICKET_NAME:
                    authentication_token
                })
            else:
                raise ValueError(_("Unknown admin action"))

    except Exception as e:
        messages.add_message(request, messages.ERROR,
                             _("Unexpected error: %s") % e)

    instances_metadata = datamanager_administrator.get_all_instances_metadata()

    for _meta in instances_metadata:
        _activation_link = _build_activation_url(
            game_instance_id=_meta["instance_id"],
            creator_login=_meta["creator_login"],
            creator_email=_meta["creator_email"])
        _meta["activation_link"] = _activation_link

    return render(
        request,
        "meta_administration/manage_instances.html",
        {
            'instances_metadata':
            instances_metadata,  # enriched info
            'utc_now':
            datetime.utcnow(),
            'notifications':
            get_messages(request),
            'possible_game_statuses':
            sorted(GAME_STATUSES),
            'deletable_statuses':
            [GAME_STATUSES.terminated, GAME_STATUSES.aborted],
            'game_creation_form':
            game_creation_form
            or GameInstanceCreationForm(require_email=require_email),
            'session_token_display':
            session_token_display,
        })