def get_check_date(self, obj): date_expired = obj.date_expired date_now = datetime.date(timezone.now()) if date_now >= date_expired: obj.status = 'dead' obj.save() return 1
def validate_date_created(self, value): if value < 1: raise serializers.ValidationError('Please enter a valid year') if value > timezone.now().year: raise serializers.ValidationError( 'Creation date cannot be in the future.') return datetime.date(datetime(year=value, month=1, day=1))
def add_secs_to_time(timeval, secs_to_add): import datetime dummy_date = datetime.date(1, 1, 1) full_datetime = datetime.datetime.combine(dummy_date, timeval) added_datetime = full_datetime + datetime.timedelta(seconds=secs_to_add) return added_datetime.time()
def get(self, request, room_id): room = Room.objects.get(id=room_id) reservations = room.roomreservations_set.filter( date__gte=str(datetime.date().today())).order_by('date') return render(request, template_name="details_room.html", context={ "room": room, "reservations": reservations })
def expire_loans(cls): for loan in cls.objects.exclude(status__exact=Loan.STATUS_CLOSED): if datetime.date(loan.date_of_expire) < datetime.now(): loan.status = cls.STATUS_EXPIRED loan.save() print( f'[{default_datetime.now()}] #{loan.pk} {cls.STATUS_EXPIRED}' ) else: loan.status = cls.STATUS_OPEN loan.save() print( f'[{default_datetime.now()}] #{loan.pk} {cls.STATUS_OPEN}')
def state_report(request, is_filter=True): report = EarthQuake.objects.filter(Origin_Time__contains=datetime.date(datetime.today())) if request.is_ajax(): query = Q() if request.POST.get('state'): state = request.POST.get('state') query &= (Q(Region__icontains=state)) if request.POST.get('magnitude'): magnitude = request.POST.get('magnitude') query &= (Q(Magnitude=magnitude)) if request.POST.get('fdate'): from_date = request.POST.get('fdate') query &= (Q( Origin_Time__gte=from_date)) if request.POST.get('tdate'): to_date = request.POST.get('tdate') query &= (Q(Origin_Time__lte=to_date)) report = EarthQuake.objects.filter(query) global whatToShow whatToShow = report return render(request, 'Report.html', {'earthquakes': report.reverse(), 'content':"report"})