Enable ruff's "pylint" rules

This commit is contained in:
Adam Goldsmith 2024-01-18 14:00:36 -05:00
parent 3728442680
commit 37cb41af1b
5 changed files with 30 additions and 28 deletions

View File

@ -50,7 +50,7 @@ class DoorController:
) # ignore insecure SSL ) # ignore insecure SSL
xml = etree.XML(r.content) xml = etree.XML(r.content)
if ( if (
r.status_code != 200 r.status_code != requests.codes.ok
or len(xml.findall("{http://www.hidglobal.com/VertX}Error")) > 0 or len(xml.findall("{http://www.hidglobal.com/VertX}Error")) > 0
): ):
raise RemoteError(r) raise RemoteError(r)
@ -75,7 +75,7 @@ class DoorController:
) )
resp_xml = etree.XML(r.content) resp_xml = etree.XML(r.content)
# probably meed to be more sane about this # probably meed to be more sane about this
if r.status_code != 200 or len(resp_xml.findall("{*}Error")) > 0: if r.status_code != requests.codes.ok or len(resp_xml.findall("{*}Error")) > 0:
raise RemoteError(r) raise RemoteError(r)
return resp_xml return resp_xml

View File

@ -1,5 +1,6 @@
import csv import csv
import datetime import datetime
from enum import Enum
from io import StringIO from io import StringIO
import requests import requests
@ -32,18 +33,20 @@ CRM = {
27: "Payment", 27: "Payment",
} }
# Types of fields, extracted from a html snippet in all.js + some guessing
typ = { # Types of fields ("typ"), extracted from a html snippet in all.js + some guessing
1: "Text input", class FieldType(Enum):
2: "Password", # inferred from data TEXT_INPUT = 1
3: "Simple text area", PASSWORD = 2 # inferred from data
4: "Rich text area", SIMPLE_TEXT_AREA = 3
7: "Address", RICH_TEXT_AREA = 4
8: "Check box", ADDRESS = 7
9: "Select", CHECKBOX = 8
11: "Display value stored in field (ie. read only)", SELECT = 9
12: "Required waiver/terms", # Display value stored in field
} READ_ONLY = 11
REQUIRED_WAIVER_TERMS = 12
# more constants, this time extracted from the members csv export in all.js # more constants, this time extracted from the members csv export in all.js
staticFlags = { staticFlags = {
@ -85,7 +88,7 @@ class MembershipWorks:
data={"eml": username, "pwd": password}, data={"eml": username, "pwd": password},
headers={"X-Org": "10000"}, headers={"X-Org": "10000"},
) )
if r.status_code != 200 or "SF" not in r.json(): if r.status_code != requests.codes.ok or "SF" not in r.json():
raise MembershipWorksRemoteError("login", r) raise MembershipWorksRemoteError("login", r)
self.org_info = r.json() self.org_info = r.json()
self.auth_token = self.org_info["SF"] self.auth_token = self.org_info["SF"]
@ -168,7 +171,7 @@ class MembershipWorks:
BASE_URL + "/v2/accounts", BASE_URL + "/v2/accounts",
params={"dek": ",".join([folder_map[f] for f in folders])}, params={"dek": ",".join([folder_map[f] for f in folders])},
) )
if r.status_code != 200 or "usr" not in r.json(): if r.status_code != requests.codes.ok or "usr" not in r.json():
raise MembershipWorksRemoteError("user listing", r) raise MembershipWorksRemoteError("user listing", r)
# get list of member ID matching the search # get list of member ID matching the search
@ -196,7 +199,7 @@ class MembershipWorks:
"var": columns, "var": columns,
}, },
) )
if r.status_code != 200: if r.status_code != requests.codes.ok:
raise MembershipWorksRemoteError("csv generation", r) raise MembershipWorksRemoteError("csv generation", r)
if r.text[0] == "\ufeff": if r.text[0] == "\ufeff":
@ -221,7 +224,7 @@ class MembershipWorks:
"edp": end_date.strftime("%s"), "edp": end_date.strftime("%s"),
}, },
) )
if r.status_code != 200: if r.status_code != requests.codes.ok:
raise MembershipWorksRemoteError("csv generation", r) raise MembershipWorksRemoteError("csv generation", r)
if json: if json:
return r.json() return r.json()

View File

@ -18,9 +18,6 @@ class MembershipWorksRouter:
return None return None
def allow_relation(self, obj1, obj2, **hints): def allow_relation(self, obj1, obj2, **hints):
if ( if self.app_label in (obj1._meta.app_label, obj2._meta.app_label):
obj1._meta.app_label == self.app_label
or obj2._meta.app_label == self.app_label
):
return True return True
return None return None

View File

@ -4,7 +4,7 @@ from datetime import datetime, timedelta
from django.conf import settings from django.conf import settings
from django.db import transaction from django.db import transaction
from membershipworks.membershipworks_api import MembershipWorks from membershipworks.membershipworks_api import FieldType, MembershipWorks
from membershipworks.models import ( from membershipworks.models import (
Event, Event,
EventCategory, EventCategory,
@ -24,8 +24,7 @@ def flags_for_member(csv_member, all_flags, folders):
if flag.type == "folder": if flag.type == "folder":
if csv_member["Account ID"] in folders[flag.id]: if csv_member["Account ID"] in folders[flag.id]:
yield flag yield flag
else: elif csv_member[flag.name] == flag.name:
if csv_member[flag.name] == flag.name:
yield flag yield flag
@ -52,7 +51,10 @@ def scrape_members(membershipworks: MembershipWorks):
for csv_member in members: for csv_member in members:
for field in membershipworks._all_fields().values(): for field in membershipworks._all_fields().values():
# convert checkboxes to real booleans # convert checkboxes to real booleans
if field.get("typ") == 8 and field["lbl"] in csv_member: if (
field.get("typ") == FieldType.CHECKBOX.value
and field["lbl"] in csv_member
):
csv_member[field["lbl"]] = ( csv_member[field["lbl"]] = (
True if csv_member[field["lbl"]] == "Y" else False True if csv_member[field["lbl"]] == "Y" else False
) )

View File

@ -43,7 +43,7 @@ admin_email = "cmsmanage.django_q2_admin_email_reporter:AdminEmailReporter"
[tool.ruff] [tool.ruff]
line-length = 88 line-length = 88
select = ["E4", "E7", "E9", "F", "I", "C4", "UP", "PERF"] select = ["E4", "E7", "E9", "F", "I", "C4", "UP", "PERF", "PL"]
[tool.ruff.lint.isort] [tool.ruff.lint.isort]
known-first-party = [ known-first-party = [