Skip to content

Commit

Permalink
Revert "More Pylint fixes"
Browse files Browse the repository at this point in the history
This reverts commit 7d091e8.
  • Loading branch information
ricardobranco777 committed Jul 2, 2023
1 parent 7d091e8 commit de980c2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
2 changes: 1 addition & 1 deletion ocw/apps.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.apps import AppConfig
import os
import logging
from django.apps import AppConfig
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.executors.pool import ThreadPoolExecutor
from pytz import utc
Expand Down
9 changes: 5 additions & 4 deletions ocw/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ class ProviderChoice(ChoiceEnum):
def from_str(provider):
if provider.upper() == ProviderChoice.GCE:
return ProviderChoice.GCE
if provider.upper() == ProviderChoice.EC2:
elif provider.upper() == ProviderChoice.EC2:
return ProviderChoice.EC2
if provider.upper() == ProviderChoice.AZURE:
elif provider.upper() == ProviderChoice.AZURE:
return ProviderChoice.AZURE
if provider.upper() == ProviderChoice.OSTACK:
elif provider.upper() == ProviderChoice.OSTACK:
return ProviderChoice.OSTACK
raise ValueError(f"{provider} is not convertable to ProviderChoice")
else:
raise ValueError(f"{provider} is not convertable to ProviderChoice")


class StateChoice(ChoiceEnum):
Expand Down
10 changes: 5 additions & 5 deletions ocw/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
from datetime import datetime, timedelta, timezone
from django.db import models
from datetime import datetime, timedelta, timezone
from webui.PCWConfig import PCWConfig
import json
from .enums import ProviderChoice, StateChoice


Expand Down Expand Up @@ -36,15 +36,15 @@ def age_formated(self):
return format_seconds(self.age.total_seconds())

def ttl_formated(self):
return format_seconds(self.ttl.total_seconds()) if self.ttl else ""
return format_seconds(self.ttl.total_seconds()) if (self.ttl) else ""

def all_time_fields(self):
all_time_pattern = "(age={}, first_seen={}, last_seen={}, ttl={})"
first_fmt = 'None'
last_fmt = 'None'
if self.first_seen:
if (self.first_seen):
first_fmt = self.first_seen.strftime('%Y-%m-%d %H:%M')
if self.last_seen:
if (self.last_seen):
last_fmt = self.last_seen.strftime('%Y-%m-%d %H:%M')
return all_time_pattern.format(self.age_formated(), first_fmt, last_fmt, self.ttl_formated())

Expand Down
17 changes: 9 additions & 8 deletions ocw/tables.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# tutorial/tables.py
from django_tables2.utils import A
from django.utils.html import format_html
from django.templatetags.static import static
from django.template.loader import get_template
import django_tables2 as tables
import django_filters
from .models import Instance
from .models import ProviderChoice
from .models import StateChoice
from django_tables2.utils import A
from django.utils.html import format_html
from django.templatetags.static import static
from django.template.loader import get_template


class NoHeaderLinkColumn(tables.LinkColumn):
Expand Down Expand Up @@ -40,7 +40,8 @@ def render(self, value, record, bound_column):
if value:
return format_html('<img alt="Email notification was send" src="{}" width=20 height=20/>',
static('img/notified.png'))
return ""
else:
return ""


class TagsColumn(tables.TemplateColumn):
Expand Down Expand Up @@ -82,13 +83,13 @@ class Meta:
exclude = ['active']
template_name = 'django_tables2/bootstrap.html'
row_attrs = {
'class': lambda record: f"state_{record.state}"
'class': lambda record: "state_{}".format(record.state)
}


# Create a BaseFilterSet to support initial value
class BaseFilterSet(django_filters.FilterSet):
def __init__(self, *args, data=None, **kwargs):
def __init__(self, data=None, *args, **kwargs):
if data is not None:
data = data.copy()
for name, f in self.base_filters.items():
Expand All @@ -98,7 +99,7 @@ def __init__(self, *args, data=None, **kwargs):
data.setlistdefault(name, initial)
else:
data.setdefault(name, initial)
super().__init__(data, *args, **kwargs)
super(BaseFilterSet, self).__init__(data, *args, **kwargs)


class InstanceFilter(BaseFilterSet):
Expand Down
11 changes: 5 additions & 6 deletions ocw/views.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
from django.contrib.auth.decorators import login_required
from django.http import JsonResponse, HttpResponse
from django.core.serializers import serialize
from django.shortcuts import redirect
from django_tables2 import SingleTableView
from .lib import db
from .models import Instance
from .tables import InstanceTable
from .tables import InstanceFilter
from django.contrib.auth.decorators import login_required
from django.http import JsonResponse, HttpResponse
from django.core.serializers import serialize


class FilteredSingleTableView(SingleTableView):
filter = None
filter_class = None

def get_table_data(self):
data = super().get_table_data()
data = super(FilteredSingleTableView, self).get_table_data()
self.filter = self.filter_class(self.request.GET, queryset=data)
return self.filter.qs

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context = super(FilteredSingleTableView, self).get_context_data(**kwargs)
context['filter'] = self.filter
return context

Expand Down

0 comments on commit de980c2

Please sign in to comment.