Skip to content

Commit

Permalink
Update syntax to drop support
Browse files Browse the repository at this point in the history
  • Loading branch information
KatherineMichel committed May 17, 2020
1 parent 0056b53 commit 267aa05
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 26 deletions.
8 changes: 4 additions & 4 deletions pinax/notifications/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from ..hooks import hookset


class BaseBackend(object):
class BaseBackend:
"""
The base backend.
"""
Expand Down Expand Up @@ -35,15 +35,15 @@ def get_formatted_messages(self, formats, label, context):
format_templates = {}
for fmt in formats:
format_templates[fmt] = render_to_string((
"pinax/notifications/{0}/{1}".format(label, fmt),
"pinax/notifications/{0}".format(fmt)), context)
f"pinax/notifications/{label}/{fmt}",
f"pinax/notifications/{fmt}"), context)
return format_templates

def default_context(self):
use_ssl = getattr(settings, "PINAX_USE_SSL", False)
default_http_protocol = "https" if use_ssl else "http"
current_site = Site.objects.get_current()
base_url = "{0}://{1}".format(default_http_protocol, current_site.domain)
base_url = f"{default_http_protocol}://{current_site.domain}"
return {
"default_http_protocol": default_http_protocol,
"current_site": current_site,
Expand Down
2 changes: 1 addition & 1 deletion pinax/notifications/backends/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class EmailBackend(BaseBackend):
spam_sensitivity = 2

def can_send(self, user, notice_type, scoping):
can_send = super(EmailBackend, self).can_send(user, notice_type, scoping)
can_send = super().can_send(user, notice_type, scoping)
if can_send and user.email:
return True
return False
Expand Down
8 changes: 4 additions & 4 deletions pinax/notifications/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ def load_model(path):
return django_apps.get_model(path)
except ValueError:
raise ImproperlyConfigured(
"{0} must be of the form 'app_label.model_name'".format(path)
f"{path} must be of the form 'app_label.model_name'"
)
except LookupError:
raise ImproperlyConfigured("{0} has not been installed".format(path))
raise ImproperlyConfigured(f"{path} has not been installed")


def load_path_attr(path):
Expand All @@ -24,11 +24,11 @@ def load_path_attr(path):
try:
mod = importlib.import_module(module)
except ImportError as e:
raise ImproperlyConfigured("Error importing {0}: '{1}'".format(module, e))
raise ImproperlyConfigured(f"Error importing {module}: '{e}'")
try:
attr = getattr(mod, attr)
except AttributeError:
raise ImproperlyConfigured("Module '{0}' does not define a '{1}'".format(module, attr))
raise ImproperlyConfigured(f"Module '{module}' does not define a '{attr}'")
return attr


Expand Down
12 changes: 6 additions & 6 deletions pinax/notifications/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ def send_all(*args):
for user, label, extra_context, sender in notices:
try:
user = get_user_model().objects.get(pk=user)
logging.info("emitting notice {0} to {1}".format(label, user))
logging.info(f"emitting notice {label} to {user}")
# call this once per user to be atomic and allow for logging to
# accurately show how long each takes.
if notification.send_now([user], label, extra_context, sender):
sent_actual += 1
except get_user_model().DoesNotExist:
# Ignore deleted users, just warn about them
logging.warning(
"not emitting notice {0} to user {1} since it does not exist".format(
"not emitting notice {} to user {} since it does not exist".format(
label,
user)
)
Expand All @@ -76,18 +76,18 @@ def send_all(*args):
_, e, _ = sys.exc_info()
# email people
current_site = Site.objects.get_current()
subject = "[{0} emit_notices] {1}".format(current_site.name, e)
subject = f"[{current_site.name} emit_notices] {e}"
message = "\n".join(
traceback.format_exception(*sys.exc_info()) # pylint: disable-msg=W0142
)
mail_admins(subject, message, fail_silently=True)
# log it as critical
logging.critical("an exception occurred: {0}".format(e))
logging.critical(f"an exception occurred: {e}")
finally:
logging.debug("releasing lock...")
lock.release()
logging.debug("released.")

logging.info("")
logging.info("{0} batches, {1} sent".format(batches, sent,))
logging.info("done in {0:.2f} seconds".format(time.time() - start_time))
logging.info(f"{batches} batches, {sent} sent")
logging.info("done in {:.2f} seconds".format(time.time() - start_time))
4 changes: 2 additions & 2 deletions pinax/notifications/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .utils import load_media_defaults


class DefaultHookSet(object):
class DefaultHookSet:

def notice_setting_for_user(self, user, notice_type, medium, scoping=None):
kwargs = {
Expand Down Expand Up @@ -39,7 +39,7 @@ def notice_setting_for_user(self, user, notice_type, medium, scoping=None):
return setting


class HookProxy(object):
class HookProxy:

def __getattr__(self, attr):
return getattr(settings.PINAX_NOTIFICATIONS_HOOKSET, attr)
Expand Down
6 changes: 3 additions & 3 deletions pinax/notifications/lockfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def __init__(self, path, threaded=True):
tname = ""
dirname = os.path.dirname(self.lock_file)
self.unique_name = os.path.join(dirname,
"%s.%s%s" % (self.hostname,
"{}.{}{}".format(self.hostname,
tname,
self.pid))

Expand Down Expand Up @@ -243,7 +243,7 @@ class LinkFileLock(LockBase):
def acquire(self, timeout=None):
try:
open(self.unique_name, "wb").close()
except IOError:
except OSError:
raise LockFailed("failed to create %s" % self.unique_name)

end_time = time.time()
Expand Down Expand Up @@ -309,7 +309,7 @@ def __init__(self, path, threaded=True):
# it.
self.unique_name = os.path.join(
self.lock_file,
"{}.{}{}".format(self.hostname, tname, self.pid)
f"{self.hostname}.{tname}{self.pid}"
)

def attempt_acquire(self, timeout, end_time, wait):
Expand Down
4 changes: 2 additions & 2 deletions pinax/notifications/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ def test_for_user(self):

class TestProcedures(BaseTest):
def setUp(self):
super(TestProcedures, self).setUp()
super().setUp()
self.lang = Language.objects.create(user=self.user, language="en_US")
mail.outbox = []

def tearDown(self):
super(TestProcedures, self).tearDown()
super().tearDown()
self.lang.delete()
NoticeQueueBatch.objects.all().delete()

Expand Down
2 changes: 1 addition & 1 deletion pinax/notifications/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_notice_settings(self):
request.user = self.user
response = NoticeSettingsView.as_view()(request)
self.assertEqual(response.status_code, 200) # pylint: disable-msg=E1103
label = "setting-{0}-{1}".format(
label = "setting-{}-{}".format(
notice_type_2.pk,
email_id
)
Expand Down
6 changes: 3 additions & 3 deletions pinax/notifications/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class NoticeSettingsView(TemplateView):

@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(NoticeSettingsView, self).dispatch(*args, **kwargs)
return super().dispatch(*args, **kwargs)

@property
def scoping(self):
Expand All @@ -27,7 +27,7 @@ def setting_for_user(self, notice_type, medium_id):
)

def form_label(self, notice_type, medium_id):
return "setting-{0}-{1}".format(
return "setting-{}-{}".format(
notice_type.pk,
medium_id
)
Expand Down Expand Up @@ -72,7 +72,7 @@ def get_context_data(self, **kwargs):
],
"rows": self.settings_table(),
}
context = super(NoticeSettingsView, self).get_context_data(**kwargs)
context = super().get_context_data(**kwargs)
context.update({
"notice_types": NoticeType.objects.all(),
"notice_settings": settings
Expand Down

0 comments on commit 267aa05

Please sign in to comment.