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
xml = etree.XML(r.content)
if (
r.status_code != 200
r.status_code != requests.codes.ok
or len(xml.findall("{http://www.hidglobal.com/VertX}Error")) > 0
):
raise RemoteError(r)
@ -75,7 +75,7 @@ class DoorController:
)
resp_xml = etree.XML(r.content)
# 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)
return resp_xml

View File

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

View File

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

View File

@ -4,7 +4,7 @@ from datetime import datetime, timedelta
from django.conf import settings
from django.db import transaction
from membershipworks.membershipworks_api import MembershipWorks
from membershipworks.membershipworks_api import FieldType, MembershipWorks
from membershipworks.models import (
Event,
EventCategory,
@ -24,9 +24,8 @@ def flags_for_member(csv_member, all_flags, folders):
if flag.type == "folder":
if csv_member["Account ID"] in folders[flag.id]:
yield flag
else:
if csv_member[flag.name] == flag.name:
yield flag
elif csv_member[flag.name] == flag.name:
yield flag
def update_flags(mw_flags) -> list[Flag]:
@ -52,7 +51,10 @@ def scrape_members(membershipworks: MembershipWorks):
for csv_member in members:
for field in membershipworks._all_fields().values():
# 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"]] = (
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]
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]
known-first-party = [