Exemple #1
0
def _checkin_igb_trusted(request, current_map):
    """
    Runs the specific code for the case that the request came from an igb that
    trusts us, returns None if no further action is required, returns a string
    containing the html for a system add dialog if we detect that a new system
    needs to be added
    """
    can_edit = current_map.get_permission(request.user) == 2
    current_location = (request.eve_systemid, request.eve_charname, request.eve_shipname, request.eve_shiptypename)
    char_cache_key = "char_%s_location" % request.eve_charid
    old_location = cache.get(char_cache_key)
    result = None
    current_system = get_object_or_404(System, pk=current_location[0])
    silent_map = request.POST.get("silent", "false") == "true"
    kspace_map = request.POST.get("kspace", "false") == "true"

    if old_location != current_location:
        if old_location:
            old_system = get_object_or_404(System, pk=old_location[0])
            old_system.remove_active_pilot(request.eve_charid)
        request.user.update_location(
            current_system.pk, request.eve_charid, request.eve_charname, request.eve_shipname, request.eve_shiptypename
        )
        cache.set(char_cache_key, current_location, 60 * 5)
        # Conditions for the system to be automagically added to the map.
        if (
            can_edit
            and old_location
            and old_system in current_map
            and current_system not in current_map
            and not _is_moving_from_kspace_to_kspace(old_system, current_system, kspace_map)
        ):
            context = {
                "oldsystem": current_map.systems.filter(system=old_system).all()[0],
                "newsystem": current_system,
                "wormholes": utils.get_possible_wh_types(old_system, current_system),
            }

            if request.POST.get("silent", "false") != "true":
                result = render_to_string(
                    "igb_system_add_dialog.html", context, context_instance=RequestContext(request)
                )
            else:
                new_ms = current_map.add_system(request.user, current_system, "", context["oldsystem"])
                k162_type = WormholeType.objects.get(name="K162")
                new_ms.connect_to(context["oldsystem"], k162_type, k162_type)
                result = "silent"
    else:
        cache.set(char_cache_key, current_location, 60 * 5)
        # Use add_active_pilot to refresh the user's record in the global
        # location cache
        current_system.add_active_pilot(
            request.user.username,
            request.eve_charid,
            request.eve_charname,
            request.eve_shipname,
            request.eve_shiptypename,
        )

    return result
Exemple #2
0
def _checkin_igb_trusted(request, current_map):
    """
    Runs the specific code for the case that the request came from an igb that
    trusts us, returns None if no further action is required, returns a string
    containing the html for a system add dialog if we detect that a new system
    needs to be added
    """
    can_edit = current_map.get_permission(request.user) == 2
    current_location = (request.eve_systemid, request.eve_charname,
                        request.eve_shipname, request.eve_shiptypename)
    char_cache_key = 'char_%s_location' % request.eve_charid
    old_location = cache.get(char_cache_key)
    result = None
    current_system = get_object_or_404(System, pk=current_location[0])

    if old_location != current_location:
        if old_location:
            old_system = get_object_or_404(System, pk=old_location[0])
            old_system.remove_active_pilot(request.eve_charid)
        request.user.update_location(current_system.pk, request.eve_charid,
                                     request.eve_charname,
                                     request.eve_shipname,
                                     request.eve_shiptypename)
        cache.set(char_cache_key, current_location, 60 * 5)
        #Conditions for the system to be automagically added to the map.
        if (can_edit and old_location and old_system in current_map
                and current_system not in current_map
                and not _is_moving_from_kspace_to_kspace(
                    old_system, current_system)):
            context = {
                'oldsystem':
                current_map.systems.filter(system=old_system).all()[0],
                'newsystem':
                current_system,
                'wormholes':
                utils.get_possible_wh_types(old_system, current_system),
            }

            if request.POST.get('silent', 'false') != 'true':
                result = render_to_string(
                    'igb_system_add_dialog.html',
                    context,
                    context_instance=RequestContext(request))
            else:
                new_ms = current_map.add_system(request.user, current_system,
                                                '', context['oldsystem'])
                k162_type = WormholeType.objects.get(name="K162")
                new_ms.connect_to(context['oldsystem'], k162_type, k162_type)
                result = 'silent'
    else:
        cache.set(char_cache_key, current_location, 60 * 5)
        # Use add_active_pilot to refresh the user's record in the global
        # location cache
        current_system.add_active_pilot(request.user.username,
                                        request.eve_charid,
                                        request.eve_charname,
                                        request.eve_shipname,
                                        request.eve_shiptypename)

    return result
Exemple #3
0
def _checkin_igb_trusted(request, current_map):
    """
    Runs the specific code for the case that the request came from an igb that
    trusts us, returns None if no further action is required, returns a string
    containing the html for a system add dialog if we detect that a new system
    needs to be added
    """
    current_system = System.objects.get(name=request.eve_systemname)
    old_system = None
    result = None
    threshold = datetime.now(pytz.utc) - timedelta(minutes=5)
    recently_active = request.user.locations.filter(
        timestamp__gt=threshold,
        charactername=request.eve_charname
    ).all()

    if recently_active.count():
        old_system = request.user.locations.get(
            charactername=request.eve_charname
        ).system

    #Conditions for the system to be automagically added to the map.
    if (
        old_system in current_map
        and current_system not in current_map
        and not _is_moving_from_kspace_to_kspace(old_system, current_system)
        and recently_active.count()
    ):
        context = {
            'oldsystem': current_map.systems.filter(
                system=old_system).all()[0],
            'newsystem': current_system,
            'wormholes': utils.get_possible_wh_types(old_system,
                                                     current_system),
        }

        result = render_to_string('igb_system_add_dialog.html', context,
                                  context_instance=RequestContext(request))

    current_system.add_active_pilot(request.user, request.eve_charname,
                                    request.eve_shipname,
                                    request.eve_shiptypename)
    return result
Exemple #4
0
def _checkin_igb_trusted(request, current_map):
    """
    Runs the specific code for the case that the request came from an igb that
    trusts us, returns None if no further action is required, returns a string
    containing the html for a system add dialog if we detect that a new system
    needs to be added
    """
    current_system = System.objects.get(name=request.eve_systemname)
    old_system = None
    result = None
    threshold = datetime.now(pytz.utc) - timedelta(minutes=5)
    recently_active = request.user.locations.filter(
        timestamp__gt=threshold,
        charactername=request.eve_charname
    ).all()

    if recently_active.count():
        old_system = request.user.locations.get(
            charactername=request.eve_charname
        ).system

    #Conditions for the system to be automagically added to the map.
    if (
        old_system in current_map
        and current_system not in current_map
        and not _is_moving_from_kspace_to_kspace(old_system, current_system)
        and recently_active.count()
    ):
        context = {
            'oldsystem': current_map.systems.filter(
                system=old_system).all()[0],
            'newsystem': current_system,
            'wormholes': utils.get_possible_wh_types(old_system,
                                                     current_system),
        }

        result = render_to_string('igb_system_add_dialog.html', context,
                                  context_instance=RequestContext(request))

    current_system.add_active_pilot(request.user, request.eve_charname,
                                    request.eve_shipname,
                                    request.eve_shiptypename)
    return result
Exemple #5
0
def checkin_igb_trusted(request, map):
    """
    Runs the specific code for the case that the request came from an igb that
    trusts us, returns None if no further action is required, returns a string
    containing the html for a system add dialog if we detect that a new system
    needs to be added
    """
    profile = request.user.get_profile()
    currentsystem = System.objects.get(name=request.eve_systemname)
    oldsystem = None
    result = None
    threshold = datetime.now(pytz.utc) - timedelta(minutes=5)
    recentlyactive = request.user.locations.filter(timestamp__gt=threshold,
            charactername=request.eve_charname).all()
    if recentlyactive.count():
        oldsystem = request.user.locations.get(charactername=request.eve_charname).system

    #Conditions for the system to be automagically added to the map. The case
    #of oldsystem == None is handled by a condition on "sys in map" (None cannot
    #be in any map), the case oldsystem == currentsystem is handled by the
    #condition that if two systems are equal one cannot be in and the other not
    #in the same map (i.e 'oldsystem in map and currentsystem not in map' will be
    #False).
    if (
      oldsystem in map
      and currentsystem not in map
      #Stop it from adding everyone's paths through k-space to the map
      and not (oldsystem.is_kspace() and currentsystem.is_kspace())
      and recentlyactive.count()
      ):
        context = { 'oldsystem' : map.systems.filter(system=oldsystem).all()[0],
                    'newsystem' : currentsystem,
                    'wormholes'  : utils.get_possible_wh_types(oldsystem, currentsystem),
                  }
        result = render_to_string('igb_system_add_dialog.html', context,
                                  context_instance=RequestContext(request))

    currentsystem.add_active_pilot(request.user, request.eve_charname,
            request.eve_shipname, request.eve_shiptypename)
    return result