use PEP 572

This commit is contained in:
2024-01-23 23:38:59 +00:00
parent 2eadadc452
commit 5f5414f29a
4 changed files with 34 additions and 47 deletions

View File

@@ -15,8 +15,7 @@ class LoginForm(AuthenticationForm):
password = self.cleaned_data.get("password")
if username is not None and password:
auth_user = authentication(username, password)
if auth_user is None:
if (auth_user := authentication(username, password)) is None:
raise ValidationError(
"Bitte Benutzername und Passwort korrekt eingeben.",
code="invalid_login",
@@ -44,8 +43,7 @@ class LoginForm(AuthenticationForm):
class LdapPasswordChangeForm(PasswordChangeForm):
def clean_old_password(self):
old_password = self.cleaned_data.get("old_password")
auth_user = authentication(self.user, old_password)
if auth_user is None:
if not authentication(self.user, old_password):
raise ValidationError(
self.error_messages["password_incorrect"],
code="password_incorrect",

View File

@@ -12,7 +12,7 @@ def get_ep_client():
api_key = ""
ep_c = None
# get api key from settings
# Get api key from settings
with open(os.path.abspath(settings.ETHERPAD_CLIENT["apikey"]), "r") as f:
api_key = f.read()
api_key = api_key.rstrip()
@@ -39,8 +39,7 @@ def get_ep_client():
def get_ep_group(ep_group_name="fet"):
ep_group = None
ep_c = get_ep_client()
if ep_c is None:
if (ep_c := get_ep_client()) is None:
return None
if settings.ETHERPAD_CLIENT["group"] == "":
@@ -55,12 +54,10 @@ def ep_pad_exists(pad_id=None):
if pad_id is None:
return None
ep_c = get_ep_client()
if ep_c is None:
if (ep_c := get_ep_client()) is None:
return None
ep_group = get_ep_group()
if ep_group is None:
if (ep_group := get_ep_group()) is None:
return None
lists = ep_c.listPads(groupID=ep_group["groupID"])
@@ -81,33 +78,29 @@ def ep_create_new_pad(pad_id, text="helloworld"):
if pad_id is None:
return None
ep_c = get_ep_client()
if ep_c is None:
if (ep_c := get_ep_client()) is None:
return None
ep_group = get_ep_group()
if ep_group is None:
if (ep_group := get_ep_group()) is None:
return None
pad_id_status = ep_pad_exists(pad_id)
if pad_id_status is None:
return None
elif pad_id_status is True:
return None
else:
ep_c.createGroupPad(groupID=ep_group["groupID"], padName=pad_id, text=text)
if ep_pad_exists(pad_id) is False:
ep_c.createGroupPad(
groupID=ep_group["groupID"],
padName=pad_id,
text=text
)
logger.info("Neues Etherpad '%s' erzeugt.", pad_id)
return pad_id
return None
def ep_get_html(pad_id):
ep_c = get_ep_client()
if ep_c is None:
if (ep_c := get_ep_client()) is None:
return None
ep_group = get_ep_group()
if ep_group is None:
if (ep_group := get_ep_group()) is None:
return None
if ep_pad_exists(pad_id):
@@ -117,12 +110,10 @@ def ep_get_html(pad_id):
def ep_set_html(pad_id, html):
ep_c = get_ep_client()
if ep_c is None:
if (ep_c := get_ep_client()) is None:
return None
ep_group = get_ep_group()
if ep_group is None:
if (ep_group := get_ep_group()) is None:
return None
if ep_pad_exists(pad_id):
@@ -133,12 +124,10 @@ def ep_set_html(pad_id, html):
def ep_get_url(pad_id):
ep_c = get_ep_client()
if ep_c is None:
if (ep_c := get_ep_client()) is None:
return None
ep_group = get_ep_group()
if ep_group is None:
if (ep_group := get_ep_group()) is None:
return None
if ep_pad_exists(pad_id):

View File

@@ -10,16 +10,15 @@ from .api import get_ep_client, get_ep_group
@ep_authenticated_user
def _create_ep_session(request, expires):
ep_c = get_ep_client()
if ep_c is None:
if (ep_c := get_ep_client()) is None:
return None
ep_group = get_ep_group()
if ep_group is None:
if (ep_group := get_ep_group()) is None:
return None, None
author = ep_c.createAuthorIfNotExistsFor(
name=str(request.user), authorMapper=str(request.user)
name=str(request.user),
authorMapper=str(request.user),
)
try:
@@ -37,8 +36,7 @@ def _create_ep_session(request, expires):
def add_ep_cookie(request, response):
expires = timezone.now() + timedelta(hours=3)
ep_session = _create_ep_session(request, expires)
if ep_session:
if (ep_session := _create_ep_session(request, expires)):
response.set_cookie(
"sessionID",
ep_session,
@@ -46,7 +44,12 @@ def add_ep_cookie(request, response):
domain=settings.HOST_NAME,
path="/",
)
response.set_cookie("sessionID", ep_session, expires=expires, path="/etherpad")
response.set_cookie(
"sessionID",
ep_session,
expires=expires,
path="/etherpad"
)
return response

View File

@@ -65,10 +65,7 @@ class BillCreateForm(forms.ModelForm):
}
def __init__(self, *args, **kwargs):
if "user" in kwargs:
user = kwargs.pop("user")
else:
user = None
user = kwargs.pop("user") if "user" in kwargs else None
super().__init__(*args, **kwargs) # to get the self.fields set