code formatting (black, isort and flake8)

This commit is contained in:
2024-08-10 17:48:08 +02:00
parent 9408208ed6
commit 2f94b0f510
7 changed files with 39 additions and 32 deletions

View File

@@ -15,15 +15,15 @@ def get_ep_client():
# Get api key from settings # Get api key from settings
if not os.path.isfile(api_key_path): if not os.path.isfile(api_key_path):
logger.info(f"API Key file is missing. Path: {api_key_path}") logger.info("API Key file is missing. Path: %s", api_key_path)
return None return None
with open(os.path.abspath(api_key_path), "r") as f: with open(os.path.abspath(api_key_path)) as f:
api_key = f.read() api_key = f.read()
api_key = api_key.rstrip() api_key = api_key.rstrip()
if api_key == "": if api_key == "":
logger.info(f"API Key is missing. Path: {api_key_path}") logger.info("API Key is missing. Path: %s", api_key_path)
return None return None
# Connection to Etherpad Client # Connection to Etherpad Client
@@ -36,7 +36,7 @@ def get_ep_client():
api_version="1.2.14", api_version="1.2.14",
) )
except EtherpadException as e: except EtherpadException as e:
logger.info(f"Connection to Etherpad Client failed. Error: {e}") logger.info("Connection to Etherpad Client failed. Error: %s", e)
return None return None
return ep_c return ep_c
@@ -56,7 +56,7 @@ def get_ep_group(ep_group_name: str = "fet") -> dict[str, str]:
return ep_group return ep_group
def ep_pad_exists(pad_id: str | None = None) -> (bool | None): def ep_pad_exists(pad_id: str | None = None) -> bool | None:
"""Check if pad exists. """Check if pad exists.
Parameters Parameters
@@ -82,10 +82,10 @@ def ep_pad_exists(pad_id: str | None = None) -> (bool | None):
lists = ep_c.listPads(groupID=ep_group["groupID"]) lists = ep_c.listPads(groupID=ep_group["groupID"])
if any(pad_id in s for s in lists["padIDs"]): if any(pad_id in s for s in lists["padIDs"]):
logger.info(f"Etherpad exists. Pad: {pad_id}") logger.info("Etherpad exists. Pad: %s", pad_id)
return True return True
logger.info(f"Etherpad doesn't exist. Pad: {pad_id}") logger.info("Etherpad doesn't exist. Pad: %s", pad_id)
return False return False
@@ -106,13 +106,13 @@ def ep_create_new_pad(pad_id: str | None, text="helloworld"):
if ep_pad_exists(pad_id) is False: if ep_pad_exists(pad_id) is False:
ep_c.createGroupPad(groupID=ep_group["groupID"], padName=pad_id, text=text) ep_c.createGroupPad(groupID=ep_group["groupID"], padName=pad_id, text=text)
logger.info(f"Create new etherpad. Pad: {pad_id}") logger.info("Create new etherpad. Pad: %s", pad_id)
return pad_id return pad_id
return None return None
def ep_get_html(pad_id: str | None) -> (str | None): def ep_get_html(pad_id: str | None) -> str | None:
if (ep_c := get_ep_client()) is None: if (ep_c := get_ep_client()) is None:
return None return None

View File

@@ -61,7 +61,9 @@ class BillCreateForm(forms.ModelForm):
iban_text = forms.CharField(required=False, label="IBAN", initial="", max_length=34) iban_text = forms.CharField(required=False, label="IBAN", initial="", max_length=34)
bic_text = forms.CharField(required=False, label="BIC", initial="", max_length=11) bic_text = forms.CharField(required=False, label="BIC", initial="", max_length=11)
saving = forms.BooleanField( saving = forms.BooleanField(
required=False, label="Bankdaten für die nächsten Rechnungen speichern.", initial=False required=False,
label="Bankdaten für die nächsten Rechnungen speichern.",
initial=False,
) )
# Resolution # Resolution
@@ -138,7 +140,9 @@ class BillUpdateForm(forms.ModelForm):
iban_text = forms.CharField(required=False, label="IBAN", initial="", max_length=34) iban_text = forms.CharField(required=False, label="IBAN", initial="", max_length=34)
bic_text = forms.CharField(required=False, label="BIC", initial="", max_length=11) bic_text = forms.CharField(required=False, label="BIC", initial="", max_length=11)
saving = forms.BooleanField( saving = forms.BooleanField(
required=False, label="Bankdaten für die nächsten Rechnungen speichern.", initial=False required=False,
label="Bankdaten für die nächsten Rechnungen speichern.",
initial=False,
) )
# only digital bill # only digital bill
@@ -401,7 +405,7 @@ class BillAdminForm(forms.ModelForm):
qs = qs.filter(status=Wiref.Status.OPENED) qs = qs.filter(status=Wiref.Status.OPENED)
# add wiref id if wiref is already transferred. # add wiref id if wiref is already transferred.
bill = kwargs.get("instance", None) bill = kwargs.get("instance")
if bill is not None and bill.wiref is not None and bill.wiref.status != Wiref.Status.OPENED: if bill is not None and bill.wiref is not None and bill.wiref.status != Wiref.Status.OPENED:
qs |= self.fields["wiref"].queryset.filter(wiref_id=bill.wiref.wiref_id) qs |= self.fields["wiref"].queryset.filter(wiref_id=bill.wiref.wiref_id)
@@ -425,7 +429,7 @@ class ResolutionAdminForm(forms.ModelForm):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) # to get the self.fields set super().__init__(*args, **kwargs) # to get the self.fields set
resolution = kwargs.get("instance", None) resolution = kwargs.get("instance")
bills = Bill.objects.filter(resolution=resolution) bills = Bill.objects.filter(resolution=resolution)
total = 0 total = 0
for elem in bills: for elem in bills:
@@ -475,7 +479,7 @@ class WirefAdminForm(forms.ModelForm):
self.fields["wiref_id"].required = True self.fields["wiref_id"].required = True
wiref = kwargs.get("instance", None) wiref = kwargs.get("instance")
total = 0 total = 0
if wiref is not None: if wiref is not None:

View File

@@ -121,7 +121,11 @@ class Wiref(models.Model):
class Bill(models.Model): class Bill(models.Model):
# members can be deleted but never their bills # members can be deleted but never their bills
bill_creator = models.ForeignKey( bill_creator = models.ForeignKey(
Member, on_delete=models.PROTECT, blank=True, null=True, verbose_name="Verantwortliche:r" Member,
on_delete=models.PROTECT,
blank=True,
null=True,
verbose_name="Verantwortliche:r",
) )
bankdata = models.ForeignKey( bankdata = models.ForeignKey(

View File

@@ -4,7 +4,6 @@ from django.core.management.base import BaseCommand
from gallery.utils import create_thumbs, get_folder_list from gallery.utils import create_thumbs, get_folder_list
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)

View File

@@ -3,7 +3,7 @@ from collections import deque
from django import template from django import template
from django.db.models import F from django.db.models import F
from members.models import JobMember, JobGroup from members.models import JobGroup, JobMember
register = template.Library() register = template.Library()

View File

@@ -131,7 +131,7 @@ class Post(models.Model):
articles = ArticleManager() articles = ArticleManager()
def __str__(self): def __str__(self):
return "Post (%s, %s): %s" % ( return "Post ({}, {}): {}".format(
self.slug, self.slug,
self.public_date.strftime("%d.%m.%Y"), self.public_date.strftime("%d.%m.%Y"),
self.title, self.title,
@@ -151,7 +151,7 @@ class Post(models.Model):
super().save(*args, **kwargs) super().save(*args, **kwargs)
@property @property
def agenda_html(self) -> (str | None): def agenda_html(self) -> str | None:
"Agenda HTML from Etherpad Pad" "Agenda HTML from Etherpad Pad"
if self.agenda_key in [None, "#"]: if self.agenda_key in [None, "#"]:
return None return None
@@ -159,7 +159,7 @@ class Post(models.Model):
return ep_get_html(self.agenda_key) return ep_get_html(self.agenda_key)
@property @property
def protocol_html(self) -> (str | None): def protocol_html(self) -> str | None:
"Protocol HTML from Etherpad Pad" "Protocol HTML from Etherpad Pad"
if self.protocol_key in [None, "#"]: if self.protocol_key in [None, "#"]:
return None return None
@@ -167,7 +167,7 @@ class Post(models.Model):
return ep_get_html(self.protocol_key) return ep_get_html(self.protocol_key)
@agenda_html.setter @agenda_html.setter
def agenda_html(self, value: str) -> (str | None): def agenda_html(self, value: str) -> str | None:
if self.agenda_key is None: if self.agenda_key is None:
self.create_agenda_key() self.create_agenda_key()
@@ -175,11 +175,11 @@ class Post(models.Model):
return None return None
ep_set_html(self.agenda_key, value) ep_set_html(self.agenda_key, value)
request_logger.info(f"Set agenda etherpad. Post: {self.slug}. Key: {self.agenda_key}") request_logger.info("Set agenda etherpad. Post: %s. Key: %s", self.slug, self.agenda_key)
return value return value
@protocol_html.setter @protocol_html.setter
def protocol_html(self, value: str) -> (str | None): def protocol_html(self, value: str) -> str | None:
if self.protocol_key is None: if self.protocol_key is None:
self.create_protocol_key() self.create_protocol_key()
@@ -187,14 +187,16 @@ class Post(models.Model):
return None return None
ep_set_html(self.protocol_key, value) ep_set_html(self.protocol_key, value)
request_logger.info(f"Set protocol etherpad. Post: {self.slug}. Key: {self.protocol_key}") request_logger.info(
"Set protocol etherpad. Post: %s. Key: %s", self.slug, self.protocol_key
)
return value return value
_agenda_filename = None _agenda_filename = None
_agenda_url = None _agenda_url = None
@property @property
def agenda_url(self) -> (str | None): def agenda_url(self) -> str | None:
if self.has_agenda is not True: if self.has_agenda is not True:
self._agenda_url = None self._agenda_url = None
self._agenda_filename = None self._agenda_filename = None
@@ -213,7 +215,7 @@ class Post(models.Model):
return self._agenda_url return self._agenda_url
@property @property
def agenda_filename(self) -> (str | None): def agenda_filename(self) -> str | None:
if self._agenda_filename is not None: if self._agenda_filename is not None:
return self._agenda_filename return self._agenda_filename
@@ -226,7 +228,7 @@ class Post(models.Model):
_protocol_url = None _protocol_url = None
@property @property
def protocol_url(self) -> (str | None): def protocol_url(self) -> str | None:
if self.has_protocol is not True: if self.has_protocol is not True:
self._protocol_url = None self._protocol_url = None
self._protocol_filename = None self._protocol_filename = None
@@ -245,7 +247,7 @@ class Post(models.Model):
return self._protocol_url return self._protocol_url
@property @property
def protocol_filename(self) -> (str | None): def protocol_filename(self) -> str | None:
if self._protocol_filename is not None: if self._protocol_filename is not None:
return self._protocol_filename return self._protocol_filename

View File

@@ -11,6 +11,4 @@ register = template.Library()
@stringfilter @stringfilter
def tags_to_url(value): def tags_to_url(value):
# return "Tag to url: %s" % value # return "Tag to url: %s" % value
return mark_safe( return mark_safe(re.sub(r"\#([\d\w-]+)", r'<a href="/posts/t/\g<1>">#\g<1></a>', value))
re.sub(r"\#([\d\w-]+)", r'<a href="/posts/t/\g<1>">#\g<1></a>', value)
)