示例#1
0
def init_session(request):
    """
    Initialize the session for the check-in interface.

    Only run for GET requests
    """
    if not request.user.is_authenticated():
        request.session.flush()

    if not Configuration.checkin_enabled():
        raise ConfigurationError(_('Check-in interface not enabled'))

    # initialize locale
    init_locale(request)

    # set test cookie
    request.session.set_test_cookie()

    # initialize vars
    request.session['checkin_device'] = None
    request.session['checkin_customer'] = None

    user = User.get_checkin_user()
    location = user.location

    if not request.session.get('company_name'):
        request.session['company_name'] = Configuration.conf('company_name')

    if request.user.is_authenticated():

        # these are our fallback defaults
        user = request.user
        location = user.location

        try:
            location_id = request.GET['l']
        except KeyError:
            # not given - try session, then default to user's location
            location_id = request.session.get('checkin_location', location.pk)
        finally:
            location = get_object_or_404(Location, pk=location_id)

        try:
            user_id = request.GET['u']
        except KeyError:
            # not given - default to session, then auth user
            user_id = request.session.get('checkin_user', user.pk)

        user = get_object_or_404(User, pk=user_id)
        request.session['checkin_locations'] = Location.get_checkin_list()

        checkin_users = User.get_checkin_group()
        queryset = checkin_users.filter(location=location)
        request.session['checkin_users'] = User.serialize(queryset)

    request.session['checkin_user'] = user.pk
    request.session['checkin_location'] = location.pk
    request.session['checkin_user_name'] = user.get_name()
    request.session['checkin_location_name'] = location.title
示例#2
0
文件: checkin.py 项目: ipwnosx/Servo
def get_checkin_locations(user):
    """
    Return possible checkin location choices for this user.
    """
    if user.is_authenticated:
        return user.locations.enabled()
    else:
        return User.get_checkin_user().locations.enabled()
示例#3
0
def init_session(request):
    # initialize some basic vars
    if not request.user.is_authenticated():
        request.session.flush()

    # initialize locale
    init_locale(request)

    request.session['checkin_device']   = None
    request.session['checkin_customer'] = None

    user = User.get_checkin_user()
    location = user.location

    if not request.session.get('company_name'):
        request.session['company_name'] = Configuration.conf('company_name')

    if request.user.is_authenticated():

        # these are our fallback defaults
        user = request.user
        location = user.location

        try:
            location_id = request.GET['l']
        except KeyError:
            # not given - try session, then default to user's location
            location_id = request.session.get('checkin_location', location.pk)
        finally:
            location = get_object_or_404(Location, pk=location_id)

        try:
            user_id = request.GET['u']
        except KeyError:
            # not given - default to session, then auth user
            user_id = request.session.get('checkin_user', user.pk)
        
        user = get_object_or_404(User, pk=user_id)
        request.session['checkin_locations'] = Location.get_checkin_list()

        checkin_users = User.get_checkin_group()
        queryset = checkin_users.filter(location=location)
        request.session['checkin_users'] = User.serialize(queryset)
    
    request.session['checkin_user'] = user.pk
    request.session['checkin_location'] = location.pk
    request.session['checkin_user_name'] = user.get_name()
    request.session['checkin_location_name'] = location.title
示例#4
0
文件: checkin.py 项目: filipp/Servo
def reset_session(request):

    # initialize some basic vars
    if not request.user.is_authenticated():
        request.session.flush()

    # initialize locale
    init_locale(request)

    request.session['checkin_device'] = None
    request.session['checkin_customer'] = None

    if not request.session.get('company_name'):
        request.session['company_name'] = Configuration.conf('company_name')

    if request.user.is_authenticated():

        if request.GET.get('u'):
            user = User.objects.get(pk=request.GET['u'])
        else:
            user = request.user

        if request.GET.get('l'):
            location = Location.objects.get(pk=request.GET['l'])
        else:
            location = user.location

        checkin_users = User.get_checkin_group()
        request.session['checkin_users'] = User.get_checkin_group_list()
        request.session['checkin_locations'] = request.user.get_location_list()

        queryset = checkin_users.filter(location=location)
        request.session['checkin_users'] = User.serialize(queryset)

    else:
        user = User.get_checkin_user()
        location = user.location
    
    request.session['checkin_user'] = user.pk
    request.session['checkin_location'] = location.pk
    request.session['checkin_user_name'] = user.get_name()
    request.session['checkin_location_name'] = location.title