def date_parameters_dictionary(request): if request.GET.get('start_date') and request.GET.get('end_date'): start_date, end_date = parse_start_and_end_date(request.GET.get('start_date'), request.GET.get('end_date')) else: start_date, end_date = get_month_timeframe() kind = request.GET.get("type") identifier = request.GET.get("id") customer = request.GET.get("customer") tool = request.GET.get("tool") dictionary = { 'month_list': month_list(), 'start_date': start_date, 'end_date': end_date, 'kind': kind, 'identifier': identifier, 'tab_url': get_url_for_other_tab(request), 'customer': None, 'tool': None, 'billing_service': get_billing_service().get('available', False), } if request.user.is_staff: dictionary['users'] = User.objects.all() dictionary['tools'] = Tool.objects.all() try: if customer: dictionary['customer'] = User.objects.get(id=customer) if tool: dictionary['tool'] = Tool.objects.get(id=tool) except: pass return dictionary, start_date, end_date, kind, identifier
def date_parameters_dictionary(request): if request.GET.get('start_date') and request.GET.get('end_date'): start_date, end_date = parse_start_and_end_date( request.GET.get('start_date'), request.GET.get('end_date')) else: start_date, end_date = get_month_timeframe() kind = request.GET.get("type") identifier = request.GET.get("id") dictionary = { 'month_list': month_list(), 'start_date': start_date, 'end_date': end_date, 'kind': kind, 'identifier': identifier, 'tab_url': get_url_for_other_tab(request), 'billing_service': False if not hasattr(settings, 'BILLING_SERVICE') or not settings.BILLING_SERVICE['available'] else True, } return dictionary, start_date, end_date, kind, identifier
def usage(request): first_of_the_month, last_of_the_month = get_month_timeframe( request.GET.get('timeframe')) dictionary = { 'area_access': AreaAccessRecord.objects.filter(customer=request.user, end__gt=first_of_the_month, end__lte=last_of_the_month, active_flag=True), 'consumables': ConsumableWithdraw.objects.filter(customer=request.user, date__gt=first_of_the_month, date__lte=last_of_the_month, active_flag=True), 'missed_reservations': Reservation.objects.filter(user=request.user, missed=True, end__gt=first_of_the_month, end__lte=last_of_the_month), 'staff_charges': StaffCharge.objects.filter(customer=request.user, end__gt=first_of_the_month, end__lte=last_of_the_month, active_flag=True), 'training_sessions': TrainingSession.objects.filter(trainee=request.user, date__gt=first_of_the_month, date__lte=last_of_the_month), 'usage_events': UsageEvent.objects.filter(user=request.user, end__gt=first_of_the_month, end__lte=last_of_the_month, active_flag=True), 'month_list': month_list(), 'timeframe': request.GET.get('timeframe') or first_of_the_month.strftime('%B, %Y'), 'billing_active_by_default': True if hasattr(settings, 'BILLING_SERVICE') and settings.BILLING_SERVICE['available'] else False } dictionary['no_charges'] = not ( dictionary['area_access'] or dictionary['consumables'] or dictionary['missed_reservations'] or dictionary['staff_charges'] or dictionary['training_sessions'] or dictionary['usage_events']) return render(request, 'usage/usage.html', dictionary)
def date_parameters_dictionary(request): if request.GET.get('start_date') and request.GET.get('end_date'): start_date, end_date = parse_start_and_end_date(request.GET.get('start_date'), request.GET.get('end_date')) else: start_date, end_date = get_month_timeframe() kind = request.GET.get("type") identifier = request.GET.get("id") dictionary = { 'month_list': month_list(), 'start_date': start_date, 'end_date': end_date, 'kind': kind, 'identifier': identifier, 'tab_url': get_url_for_other_tab(request), 'billing_service': get_billing_service().get('available', False), } return dictionary, start_date, end_date, kind, identifier
def date_parameters_dictionary(request): dates = False if request.GET.get('start_date') and request.GET.get('end_date'): start_date, end_date = parse_start_and_end_date( request.GET.get('start_date'), request.GET.get('end_date')) dates = True else: start_date, end_date = get_month_timeframe( request.GET.get('timeframe')) dictionary = { 'month_list': month_list(), 'timeframe': request.GET.get('timeframe') or start_date.strftime('%B, %Y'), 'start_date': start_date, 'end_date': end_date, 'dates': dates, 'tab_url': get_url_for_other_tab(request) } return dictionary, start_date, end_date
def nanofab_usage(request): first_of_the_month, last_of_the_month = get_month_timeframe( request.GET.get('timeframe')) dictionary = { 'area_access': AreaAccessRecord.objects.filter(customer=request.user, end__gt=first_of_the_month, end__lte=last_of_the_month), 'consumables': ConsumableWithdraw.objects.filter(customer=request.user, date__gt=first_of_the_month, date__lte=last_of_the_month), 'missed_reservations': Reservation.objects.filter(user=request.user, missed=True, end__gt=first_of_the_month, end__lte=last_of_the_month), 'staff_charges': StaffCharge.objects.filter(customer=request.user, end__gt=first_of_the_month, end__lte=last_of_the_month), 'training_sessions': TrainingSession.objects.filter(trainee=request.user, date__gt=first_of_the_month, date__lte=last_of_the_month), 'usage_events': UsageEvent.objects.filter(user=request.user, end__gt=first_of_the_month, end__lte=last_of_the_month), 'month_list': month_list(), 'timeframe': request.GET.get('timeframe') or first_of_the_month.strftime('%B, %Y'), } dictionary['no_charges'] = not ( dictionary['area_access'] or dictionary['consumables'] or dictionary['missed_reservations'] or dictionary['staff_charges'] or dictionary['training_sessions'] or dictionary['usage_events']) return render(request, 'nanofab_usage.html', dictionary)
def remote_work(request): first_of_the_month, last_of_the_month = get_month_timeframe(request.GET.get('date')) operator = request.GET.get('operator') if operator: if operator == "all staff": operator = None else: operator = get_object_or_404(User, id=operator) else: operator = request.user usage_events = UsageEvent.objects.filter(operator__is_staff=True, start__gte=first_of_the_month, start__lte=last_of_the_month).exclude(operator=F('user')) staff_charges = StaffCharge.objects.filter(start__gte=first_of_the_month, start__lte=last_of_the_month) if operator: usage_events = usage_events.exclude(~Q(operator_id=operator.id)) staff_charges = staff_charges.exclude(~Q(staff_member_id=operator.id)) dictionary = { 'usage': usage_events, 'staff_charges': staff_charges, 'staff_list': User.objects.filter(is_staff=True), 'month_list': month_list(), 'selected_staff': operator.id if operator else "all staff", 'selected_month': request.GET.get('date'), } return render(request, 'remote_work.html', dictionary)
def remote_work(request): if request.GET.get("start_date") and request.GET.get("end_date"): start_date, end_date = parse_start_and_end_date( request.GET.get("start_date"), request.GET.get("end_date")) else: start_date, end_date = get_month_timeframe() operator = request.GET.get("operator") if operator: if operator == "all staff": operator = None else: operator = get_object_or_404(User, id=operator) else: operator = request.user project = request.GET.get("project") if project and project != "all projects": project = get_object_or_404(Project, id=project) else: project = None usage_events = UsageEvent.objects.filter( operator__is_staff=True, start__gte=start_date, start__lte=end_date).exclude(operator=F("user")) staff_charges = StaffCharge.objects.filter(start__gte=start_date, start__lte=end_date) if operator: usage_events = usage_events.exclude(~Q(operator_id=operator.id)) staff_charges = staff_charges.exclude(~Q(staff_member_id=operator.id)) if project: usage_events = usage_events.filter(project=project) staff_charges = staff_charges.filter(project=project) csv_export = bool(request.GET.get("csv", False)) if csv_export: table_result = BasicDisplayTable() TYPE, ID, ITEM, STAFF, CUSTOMER, PROJECT, START, END = ( "item_type", "item_id", "item", "staff_member", "customer", "project", "start_date", "end_date", ) table_result.headers = [ (TYPE, "Item Type"), (ID, "Item Id"), (ITEM, "Item"), (STAFF, "Staff"), (CUSTOMER, "Customer"), (PROJECT, "Project"), (START, "Start"), (END, "End"), ] for usage in usage_events: table_result.add_row({ ID: usage.tool.id, TYPE: "Tool Usage", ITEM: usage.tool, STAFF: usage.operator, CUSTOMER: usage.user, START: usage.start.astimezone( timezone.get_current_timezone()).strftime( "%m/%d/%Y @ %I:%M %p"), END: usage.end.astimezone(timezone.get_current_timezone()).strftime( "%m/%d/%Y @ %I:%M %p") if usage.end else "", PROJECT: usage.project, }) for staff_charge in staff_charges: for access in staff_charge.areaaccessrecord_set.all(): table_result.add_row({ ID: access.area.id, TYPE: "Area Access", ITEM: access.area, STAFF: staff_charge.staff_member, CUSTOMER: access.customer, START: access.start.astimezone( timezone.get_current_timezone()).strftime( "%m/%d/%Y @ %I:%M %p"), END: access.end.astimezone(timezone.get_current_timezone()). strftime("%m/%d/%Y @ %I:%M %p") if access.end else "", PROJECT: access.project, }) table_result.add_row({ ID: staff_charge.id, TYPE: "Staff Charge", ITEM: "Staff Charge", STAFF: staff_charge.staff_member, CUSTOMER: staff_charge.customer, START: staff_charge.start.astimezone( timezone.get_current_timezone()).strftime( "%m/%d/%Y @ %I:%M %p"), END: staff_charge.end.astimezone(timezone.get_current_timezone()). strftime("%m/%d/%Y @ %I:%M %p") if staff_charge.end else "", PROJECT: staff_charge.project, }) response = table_result.to_csv() filename = f"remote_work_{start_date.strftime('%m_%d_%Y')}_to_{end_date.strftime('%m_%d_%Y')}.csv" response["Content-Disposition"] = f'attachment; filename="{filename}"' return response dictionary = { "usage": usage_events, "staff_charges": staff_charges, "staff_list": User.objects.filter(is_staff=True), "project_list": Project.objects.filter(active=True), "start_date": start_date, "end_date": end_date, "month_list": month_list(), "selected_staff": operator.id if operator else "all staff", "selected_project": project.id if project else "all projects", } return render(request, "remote_work.html", dictionary)