Exemplo n.º 1
0
def landing(request):
    delete_expired_alerts()
    delete_expired_notifications()
    usage_events = UsageEvent.objects.filter(operator=request.user.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)
    landing_page_choices = LandingPageChoice.objects.all()
    if request.device == 'desktop':
        landing_page_choices = landing_page_choices.exclude(
            hide_from_desktop_computers=True)
    if request.device == 'mobile':
        landing_page_choices = landing_page_choices.exclude(
            hide_from_mobile_devices=True)
    if not request.user.is_staff and not request.user.is_superuser and not request.user.is_technician:
        landing_page_choices = landing_page_choices.exclude(
            hide_from_users=True)

    if not settings.ALLOW_CONDITIONAL_URLS:
        # validate all urls
        landing_page_choices = [
            landing_page_choice for landing_page_choice in landing_page_choices
            if valid_url_for_landing(landing_page_choice.url)
        ]

    dictionary = {
        'now':
        timezone.now(),
        'alerts':
        Alert.objects.filter(Q(user=None) | Q(user=request.user),
                             debut_time__lte=timezone.now(),
                             expired=False,
                             deleted=False),
        'usage_events':
        usage_events,
        'upcoming_reservations':
        Reservation.objects.filter(
            user=request.user.id,
            end__gt=timezone.now(),
            cancelled=False,
            missed=False,
            shortened=False).exclude(
                tool_id__in=tools_in_use,
                start__lte=fifteen_minutes_from_now).order_by('start')[:3],
        'disabled_resources':
        Resource.objects.filter(available=False),
        'landing_page_choices':
        landing_page_choices,
        'notification_counts':
        get_notificaiton_counts(request.user),
        'self_log_in':
        able_to_self_log_in_to_area(request.user),
        'self_log_out':
        able_to_self_log_out_of_area(request.user),
    }
    return render(request, 'landing.html', dictionary)
Exemplo n.º 2
0
def landing(request):
	user: User = request.user
	delete_expired_alerts()
	delete_expired_notifications()
	if user.access_expiration:
		if user.access_expiration < timezone.now().date():
			user.training_required = True
			user.save()
	usage_events = UsageEvent.objects.filter(operator=user.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)
	landing_page_choices = LandingPageChoice.objects.all()
	if request.device == "desktop":
		landing_page_choices = landing_page_choices.exclude(hide_from_desktop_computers=True)
	if request.device == "mobile":
		landing_page_choices = landing_page_choices.exclude(hide_from_mobile_devices=True)
	if not user.is_staff and not user.is_superuser and not user.is_technician:
		landing_page_choices = landing_page_choices.exclude(hide_from_users=True)

	if not settings.ALLOW_CONDITIONAL_URLS:
		# validate all urls
		landing_page_choices = [
			landing_page_choice
			for landing_page_choice in landing_page_choices
			if valid_url_for_landing(landing_page_choice.url)
		]

	upcoming_reservations = Reservation.objects.filter(
		user=user.id, end__gt=timezone.now(), cancelled=False, missed=False, shortened=False
	).exclude(tool_id__in=tools_in_use, start__lte=fifteen_minutes_from_now).exclude(ancestor__shortened=True)
	if user.in_area():
		upcoming_reservations = upcoming_reservations.exclude(
			area=user.area_access_record().area, start__lte=fifteen_minutes_from_now
		)
	upcoming_reservations = upcoming_reservations.order_by("start")[:3]
	dictionary = {
		"now": timezone.now(),
		"alerts": Alert.objects.filter(
			Q(user=None) | Q(user=user), debut_time__lte=timezone.now(), expired=False, deleted=False
		),
		"usage_events": usage_events,
		"upcoming_reservations": upcoming_reservations,
		"disabled_resources": Resource.objects.filter(available=False),
		"landing_page_choices": landing_page_choices,
		"self_log_in": able_to_self_log_in_to_area(request.user),
		"self_log_out": able_to_self_log_out_of_area(request.user),
		"expires_soon": user.access_expiration < timezone.now().date() + timedelta(weeks=2) if user.access_expiration else False
	}
	return render(request, "landing.html", dictionary)
Exemplo n.º 3
0
def landing(request):

    delete_expired_alerts()
    delete_expired_notifications()
    usage_events = UsageEvent.objects.filter(
        operator=request.user.id, end=None,
        active_flag=True).prefetch_related('tool', 'project')

    aar = request.user.area_access_record()
    if aar is not None:
        if usage_events:
            active_area_access = usage_events.filter(
                tool__requires_area_access=aar.area)
        else:
            active_area_access = False
    else:
        active_area_access = False

    contested_items = False
    if request.user.is_superuser:
        if UsageEvent.objects.filter(
                contested=True,
                validated=False,
                contest_record__contest_resolved=False,
                active_flag=True).exists() or StaffCharge.objects.filter(
                    contested=True,
                    validated=False,
                    contest_record__contest_resolved=False,
                    active_flag=True).exists(
                    ) or AreaAccessRecord.objects.filter(
                        contested=True,
                        validated=False,
                        contest_record__contest_resolved=False,
                        active_flag=True).exists(
                        ) or ConsumableWithdraw.objects.filter(
                            contested=True,
                            validated=False,
                            contest_record__contest_resolved=False,
                            active_flag=True).exists():
            contested_items = True
    else:
        if request.user.is_staff:
            group_name = "Core Admin"
            if request.user.groups.filter(name=group_name).exists():
                if StaffCharge.objects.filter(
                        validated=False,
                        contested=True,
                        contest_record__contest_resolved=False,
                        staff_member__core_ids__in=request.user.core_ids.all(),
                        active_flag=True).exclude(
                            staff_member=request.user
                        ).exists() or UsageEvent.objects.filter(
                            validated=False,
                            contested=True,
                            contest_record__contest_resolved=False,
                            operator__core_ids__in=request.user.core_ids.all(),
                            active_flag=True
                        ).exclude(operator=request.user).exists(
                        ) or AreaAccessRecord.objects.filter(
                            validated=False,
                            contested=True,
                            contest_record__contest_resolved=False,
                            staff_charge__staff_member__core_ids__in=request.
                            user.core_ids.all(),
                            active_flag=True).exclude(
                                staff_charge__staff_member=request.user
                            ).exists() or ConsumableWithdraw.objects.filter(
                                validated=False,
                                contested=True,
                                contest_record__contest_resolved=False,
                                consumable__core_id__in=request.user.core_ids.
                                all(),
                                active_flag=True).exclude(
                                    customer=request.user).exists():
                    contested_items = True
            else:
                if UsageEvent.objects.filter(
                        Q(validated=False,
                          contested=True,
                          contest_record__contest_resolved=False,
                          active_flag=True),
                        Q(tool__primary_owner=request.user)
                        | Q(tool__backup_owners__in=[request.user])
                ).exclude(operator=request.user).exists(
                ) or ConsumableWithdraw.objects.filter(
                        validated=False,
                        contested=True,
                        contest_record__contest_resolved=False,
                        consumable__core_id__in=request.user.core_ids.all(),
                        active_flag=True).exclude(
                            customer=request.user).exists():
                    contested_items = True

    if UsageEvent.objects.filter(
            operator=request.user, validated=False,
            active_flag=True).exists() or StaffCharge.objects.filter(
                staff_member=request.user, validated=False,
                active_flag=True).exists():
        validation_needed = True
    else:
        validation_needed = False

    tools_in_use = [u.tool_id for u in usage_events]
    fifteen_minutes_from_now = timezone.now() + timedelta(minutes=15)
    landing_page_choices = LandingPageChoice.objects.all()
    if request.device == 'desktop':
        landing_page_choices = landing_page_choices.exclude(
            hide_from_desktop_computers=True)
    if request.device == 'mobile':
        landing_page_choices = landing_page_choices.exclude(
            hide_from_mobile_devices=True)
    if not request.user.is_staff and not request.user.is_superuser and not request.user.is_technician:
        landing_page_choices = landing_page_choices.exclude(
            hide_from_users=True)

    user_delegate = False
    if not request.user.groups.filter(name="Technical Staff").exists(
    ) and not request.user.groups.filter(name="Financial Admin").exists(
    ) and not request.user.groups.filter(
            name="PI").exists() and not request.user.is_superuser:
        if User.objects.filter(pi_delegates=request.user).exists():
            user_delegate = True

    dictionary = {
        'now':
        timezone.now(),
        'alerts':
        Alert.objects.filter(Q(user=None) | Q(user=request.user),
                             debut_time__lte=timezone.now()),
        'usage_events':
        usage_events,
        'upcoming_reservations':
        Reservation.objects.filter(
            user=request.user.id,
            end__gt=timezone.now(),
            cancelled=False,
            missed=False,
            shortened=False).exclude(
                tool_id__in=tools_in_use,
                start__lte=fifteen_minutes_from_now).order_by('start')[:3],
        'disabled_resources':
        Resource.objects.filter(available=False),
        'landing_page_choices':
        landing_page_choices,
        'notification_counts':
        get_notificaiton_counts(request.user),
        'self_log_in':
        able_to_self_log_in_to_area(request.user),
        'active_area_access':
        active_area_access,
        'contested_items':
        contested_items,
        'validation_needed':
        validation_needed,
        'user_delegate':
        user_delegate,
    }
    return render(request, 'landing.html', dictionary)