def filter_queryset(self, request, queryset, view): request_params = request.query_params active = request_params.get('active') if isinstance(active, basestring) and active.lower() == 'true'\ or isinstance(active, bool) and active: queryset = MaintenanceRecord.active() return queryset
def has_permission(self, request, view): records = MaintenanceRecord.active()\ .filter(provider__isnull=True) if records: if not request.user.is_staff: raise ServiceUnavailable( detail=get_maintenance_messages(records)) return True
def handle_show(self, **options): records = MaintenanceRecord.active() if not records: self.stdout.write("There are no active records") return for record in records: self.stdout.write(str(record))
def handle_start(self, **options): start_date = options['start_date'] if isinstance(start_date, str): try: start_date = parse(start_date) except Exception as exc: raise CommandError("Error parsing start_date: {}".format(exc)) record = MaintenanceRecord(title=options['title'], message=options['message'], start_date=start_date) if options['dry_run']: self.stdout.write("{}: {}".format(self.style.NOTICE("Dry run"), record)) else: record.save() self.stdout.write("{}: {}".format( self.style.SUCCESS("Record created"), record))
def handle_start(self, **options): start_date = options['start_date'] if isinstance(start_date, str): try: start_date = parse(start_date) except Exception as exc: raise CommandError("Error parsing start_date: {}".format(exc)) record = MaintenanceRecord( title=options['title'], message=options['message'], start_date=start_date ) if options['dry_run']: self.stdout.write( "{}: {}".format(self.style.NOTICE("Dry run"), record) ) else: record.save() self.stdout.write( "{}: {}".format(self.style.SUCCESS("Record created"), record) )
def has_permission(self, request, view): records = MaintenanceRecord.active()\ .filter(provider__isnull=True) if records: request_username = request.user.username #TODO: Optional logic related to session_username -- the one who is 'Authenticated'.. atmo_user = AtmosphereUser.objects.filter( username=request_username).first() if atmo_user and request_username in settings.MAINTENANCE_EXEMPT_USERNAMES: return True else: raise ServiceUnavailable( detail=get_maintenance_messages(records)) return True
def handle_stop(self): records = MaintenanceRecord.active() self.stdout.write( "Preparing to process {0} records ...".format(len(records))) for record in records: self.stdout.write(" - End dating ... {0}".format(record)) record.end_date = timezone.now() record.save() self.stdout.write("Done ...") return True
def handle_stop(self, **options): records = MaintenanceRecord.active() if not records: self.stdout.write("There are no active records") return for record in records: record.end_date = timezone.now() if options['dry_run']: self.stdout.write("{}: {}".format(self.style.NOTICE("Dry run"), record)) continue else: record.save() self.stdout.write("{}: {}".format( self.style.SUCCESS("Record enddated"), record))
def handle_stop(self, **options): records = MaintenanceRecord.active() if not records: self.stdout.write("There are no active records") return for record in records: record.end_date = timezone.now() if options['dry_run']: self.stdout.write( "{}: {}".format(self.style.NOTICE("Dry run"), record) ) continue else: record.save() self.stdout.write( "{}: {}".format( self.style.SUCCESS("Record enddated"), record ) )