Example #1
0
    def handle_noargs(self, **options):
        current_time = timezone.localtime(timezone.now())
        current_date = current_time.date()
        ctime_tuple = (current_time.hour, current_time.minute)

        if self.compare_times(ctime_tuple, self.get_time_setting('OPEN_TIME')):
            weekly_closures, onetime_closures = get_closures(current_date)
            self.stdout.write('Active weekly closures: {}'.format(
                ', '.join(weekly_closures) if weekly_closures else '(none)'))
            self.stdout.write('Active one-time closures: {}'.format(
                ', '.join(onetime_closures) if onetime_closures else '(none)'))

            closure_set = weekly_closures | onetime_closures
            locations = Location.objects.exclude(uid__in=closure_set)
            count = open_locations(locations, current_time)

            self.stdout.write(
                'Opened {} location{}'.format(count, '' if count == 1 else 's'))

        elif self.compare_times(ctime_tuple, self.get_time_setting('CLOSE_TIME')):
            locations = Location.objects.all()
            count = close_locations(locations, current_time)

            self.stdout.write(
                'Closed {} location{}'.format(count, '' if count == 1 else 's'))

        else:
            self.stdout.write('Exiting: current time ({0}) is not OPEN_TIME '
                '({1[0]:02}:{1[1]:02}) or CLOSE_TIME ({2[0]:02}:{2[1]:02})'
                .format(current_time, settings.OPEN_TIME, settings.CLOSE_TIME))
Example #2
0
    def handle(self, *args, **options):
        current_time = timezone.localtime(timezone.now())
        current_date = current_time.date()

        if not options['force']:
            weekly_closures, onetime_closures = get_closures(current_date)
            self.stdout.write('Active weekly closures: {}'.format(
                ', '.join(weekly_closures) if weekly_closures else '(none)'))
            self.stdout.write('Active one-time closures: {}'.format(
                ', '.join(onetime_closures) if onetime_closures else '(none)'))

            location_ids = set(args) - (weekly_closures | onetime_closures)
            locations = Location.objects.filter(uid__in=location_ids)
        else:
            locations = Location.objects.filter(uid__in=args)

        count = open_locations(locations, current_time)

        self.stdout.write(
            'Opened {} location{}'.format(count, '' if count == 1 else 's'))