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
Пример #2
0
 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
Пример #3
0
 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 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
Пример #5
0
    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))
Пример #6
0
    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_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)
            )
Пример #9
0
 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
Пример #10
0
    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
Пример #11
0
    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
                    )
                )