Exemple #1
0
def choices(request):
    try:
        customer = User.objects.get(badge_number=request.GET['badge_number'])
    except:
        dictionary = {
            'message':
            "Your badge wasn't recognized. If you got a new one recently then we'll need to update your account. Please visit the laboratory user office to resolve the problem."
        }
        return render(request, 'kiosk/acknowledgement.html', dictionary)
    dictionary = {
        'customer':
        customer,
        'usage_events':
        UsageEvent.objects.filter(
            operator=customer.id, end=None,
            active_flag=True).order_by('tool__name').prefetch_related(
                'tool', 'project'),
        'tools':
        Tool.objects.filter(visible=True, location=request.GET['location']),
        'tool_summary':
        create_tool_summary(request),
        'categories': [
            t[0] for t in Tool.objects.filter(visible=True).order_by(
                'category').values_list('category').distinct()
        ],
    }
    return render(request, 'kiosk/choices.html', dictionary)
Exemple #2
0
def refresh_sidebar_icons(request, item_type=None):
    area_summary = []
    tool_summary = []
    item_type = ReservationItemType(item_type)
    if item_type == ReservationItemType.NONE:
        tool_summary = create_tool_summary()
        area_summary = create_area_summary()
    elif item_type == ReservationItemType.AREA:
        area_summary = create_area_summary()
    elif item_type == ReservationItemType.TOOL:
        tool_summary = create_tool_summary()

    return render(request, 'refresh_sidebar_icons.html', {
        'tool_summary': tool_summary,
        'area_summary': area_summary
    })
Exemple #3
0
def category_choices(request, category, user_id):
    try:
        customer = User.objects.get(id=user_id)
    except:
        dictionary = {
            'message':
            "Your badge wasn't recognized. If you got a new one recently then we'll need to update your account. Please contact staff to resolve the problem."
        }
        return render(request, 'kiosk/acknowledgement.html', dictionary)
    tools = Tool.objects.filter(visible=True, _category=category)
    dictionary = {
        'customer':
        customer,
        'category':
        category,
        'tools':
        tools,
        'unqualified_tools': [
            tool for tool in tools if not customer.is_staff
            and tool not in customer.qualifications.all()
        ],
        'tool_summary':
        create_tool_summary(),
    }
    return render(request, 'kiosk/category_choices.html', dictionary)
Exemple #4
0
def choices(request):
    try:
        customer = User.objects.get(badge_number=request.GET['badge_number'])
        usage_events = UsageEvent.objects.filter(operator=customer.id,
                                                 end=None).prefetch_related(
                                                     'tool', 'project')
        tools_in_use = [u.tool.tool_or_parent_id() for u in usage_events]
        fifteen_minutes_from_now = timezone.now() + timedelta(minutes=15)
        reservations = Reservation.objects.filter(
            end__gt=timezone.now(),
            user=customer,
            missed=False,
            cancelled=False,
            shortened=False).exclude(
                tool_id__in=tools_in_use,
                start__lte=fifteen_minutes_from_now).order_by('start')
        if customer.in_area():
            reservations = reservations.exclude(
                area=customer.area_access_record().area,
                start__lte=fifteen_minutes_from_now)
    except:
        dictionary = {
            'message':
            "Your badge wasn't recognized. If you got a new one recently then we'll need to update your account. Please contact staff to resolve the problem."
        }
        return render(request, 'kiosk/acknowledgement.html', dictionary)

    categories = [
        t[0] for t in Tool.objects.filter(visible=True).order_by(
            '_category').values_list('_category').distinct()
    ]
    unqualified_categories = [
        category for category in categories
        if not customer.is_staff and not Tool.objects.filter(
            visible=True,
            _category=category,
            id__in=customer.qualifications.all().values_list('id')).exists()
    ]
    dictionary = {
        'now':
        timezone.now(),
        'customer':
        customer,
        'usage_events':
        UsageEvent.objects.filter(
            operator=customer.id,
            end=None).order_by('tool__name').prefetch_related(
                'tool', 'project'),
        'upcoming_reservations':
        reservations,
        'tool_summary':
        create_tool_summary(),
        'categories':
        categories,
        'unqualified_categories':
        unqualified_categories,
    }
    return render(request, 'kiosk/choices.html', dictionary)
Exemple #5
0
def choices(request):
    try:
        customer = User.objects.get(badge_number=request.GET["badge_number"])
        usage_events = (UsageEvent.objects.filter(
            operator=customer.id,
            end=None).order_by("tool__name").prefetch_related(
                "tool", "project"))
        tools_in_use = [u.tool.tool_or_parent_id() for u in usage_events]
        fifteen_minutes_from_now = timezone.now() + timedelta(minutes=15)
        tool_reservations = (Reservation.objects.filter(
            tool__isnull=False,
            end__gt=timezone.now(),
            user=customer,
            missed=False,
            cancelled=False,
            shortened=False,
        ).exclude(tool_id__in=tools_in_use,
                  start__lte=fifteen_minutes_from_now).exclude(
                      ancestor__shortened=True).order_by("start"))
    except:
        dictionary = {
            "message":
            "Your badge wasn't recognized. If you got a new one recently then we'll need to update your account. Please contact staff to resolve the problem."
        }
        return render(request, "kiosk/acknowledgement.html", dictionary)

    categories = [
        t[0] for t in Tool.objects.filter(visible=True).order_by(
            "_category").values_list("_category").distinct()
    ]
    unqualified_categories = [
        category for category in categories
        if not customer.is_staff and not Tool.objects.filter(
            visible=True,
            _category=category,
            id__in=customer.qualifications.all().values_list("id")).exists()
    ]
    dictionary = {
        "now": timezone.now(),
        "customer": customer,
        "usage_events": list(usage_events),
        "upcoming_reservations": tool_reservations,
        "tool_summary": create_tool_summary(),
        "categories": categories,
        "unqualified_categories": unqualified_categories,
    }
    return render(request, "kiosk/choices.html", dictionary)
Exemple #6
0
def category_choices(request, category, user_id):
    try:
        customer = User.objects.get(id=user_id)
    except:
        dictionary = {
            'message':
            "Your badge wasn't recognized. If you got a new one recently then we'll need to update your account. Please visit the laboratory user office to resolve the problem."
        }
        return render(request, 'kiosk/acknowledgement.html', dictionary)
    tools = Tool.objects.filter(visible=True, category=category)
    dictionary = {
        'customer': customer,
        'category': category,
        'tools': tools,
        'tool_summary': create_tool_summary(request),
    }
    return render(request, 'kiosk/category_choices.html', dictionary)
Exemple #7
0
def calendar(request, tool_id=None):
    """ Present the calendar view to the user. """

    if request.device == 'mobile':
        if tool_id:
            return redirect('view_calendar', tool_id)
        else:
            return redirect('choose_tool', 'view_calendar')

    tools = Tool.objects.filter(visible=True).order_by('category', 'name')
    rendered_tool_tree_html = ToolTree().render(None, {'tools': tools})
    tool_summary = create_tool_summary(request)
    dictionary = {
        'rendered_tool_tree_html': rendered_tool_tree_html,
        'tools': tools,
        'auto_select_tool': tool_id,
        'tool_summary': tool_summary,
    }
    if request.user.is_staff:
        dictionary['users'] = User.objects.all()
    return render(request, 'calendar/calendar.html', dictionary)
Exemple #8
0
def refresh_sidebar_icons(request):
    tool_summary = create_tool_summary(request)
    return render(request, 'refresh_sidebar_icons.html',
                  {'tool_summary': tool_summary})