Python formatting
This commit is contained in:
parent
acfb1bb376
commit
08f6a97653
@ -20,7 +20,9 @@ class ActivityStream(RedisStore):
|
|||||||
|
|
||||||
def unread_id(self, user):
|
def unread_id(self, user):
|
||||||
"""the redis key for this user's unread count for this stream"""
|
"""the redis key for this user's unread count for this stream"""
|
||||||
return "{}-unread".format(self.stream_id(user)) # pylint: disable=consider-using-f-string
|
return "{}-unread".format(
|
||||||
|
self.stream_id(user)
|
||||||
|
) # pylint: disable=consider-using-f-string
|
||||||
|
|
||||||
def get_rank(self, obj): # pylint: disable=no-self-use
|
def get_rank(self, obj): # pylint: disable=no-self-use
|
||||||
"""statuses are sorted by date published"""
|
"""statuses are sorted by date published"""
|
||||||
|
@ -222,9 +222,7 @@ def get_data(url, params=None, timeout=10):
|
|||||||
"""wrapper for request.get"""
|
"""wrapper for request.get"""
|
||||||
# check if the url is blocked
|
# check if the url is blocked
|
||||||
if models.FederatedServer.is_blocked(url):
|
if models.FederatedServer.is_blocked(url):
|
||||||
raise ConnectorException(
|
raise ConnectorException(f"Attempting to load data from blocked url: {url}")
|
||||||
f"Attempting to load data from blocked url: {url}"
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
resp = requests.get(
|
resp = requests.get(
|
||||||
|
@ -87,11 +87,7 @@ class Connector(AbstractConnector):
|
|||||||
|
|
||||||
def format_search_result(self, search_result):
|
def format_search_result(self, search_result):
|
||||||
images = search_result.get("image")
|
images = search_result.get("image")
|
||||||
cover = (
|
cover = f"{self.covers_url}/img/entities/{images[0]}" if images else None
|
||||||
f"{self.covers_url}/img/entities/{images[0]}"
|
|
||||||
if images
|
|
||||||
else None
|
|
||||||
)
|
|
||||||
# a deeply messy translation of inventaire's scores
|
# a deeply messy translation of inventaire's scores
|
||||||
confidence = float(search_result.get("_score", 0.1))
|
confidence = float(search_result.get("_score", 0.1))
|
||||||
confidence = 0.1 if confidence < 150 else 0.999
|
confidence = 0.1 if confidence < 150 else 0.999
|
||||||
@ -131,9 +127,7 @@ class Connector(AbstractConnector):
|
|||||||
|
|
||||||
def load_edition_data(self, work_uri):
|
def load_edition_data(self, work_uri):
|
||||||
"""get a list of editions for a work"""
|
"""get a list of editions for a work"""
|
||||||
url = (
|
url = f"{self.books_url}?action=reverse-claims&property=wdt:P629&value={work_uri}&sort=true"
|
||||||
f"{self.books_url}?action=reverse-claims&property=wdt:P629&value={work_uri}&sort=true"
|
|
||||||
)
|
|
||||||
return get_data(url)
|
return get_data(url)
|
||||||
|
|
||||||
def get_edition_from_work_data(self, data):
|
def get_edition_from_work_data(self, data):
|
||||||
|
@ -48,18 +48,12 @@ def password_reset_email(reset_code):
|
|||||||
|
|
||||||
def format_email(email_name, data):
|
def format_email(email_name, data):
|
||||||
"""render the email templates"""
|
"""render the email templates"""
|
||||||
subject = (
|
subject = get_template(f"email/{email_name}/subject.html").render(data).strip()
|
||||||
get_template(f"email/{email_name}/subject.html").render(data).strip()
|
|
||||||
)
|
|
||||||
html_content = (
|
html_content = (
|
||||||
get_template(f"email/{email_name}/html_content.html")
|
get_template(f"email/{email_name}/html_content.html").render(data).strip()
|
||||||
.render(data)
|
|
||||||
.strip()
|
|
||||||
)
|
)
|
||||||
text_content = (
|
text_content = (
|
||||||
get_template(f"email/{email_name}/text_content.html")
|
get_template(f"email/{email_name}/text_content.html").render(data).strip()
|
||||||
.render(data)
|
|
||||||
.strip()
|
|
||||||
)
|
)
|
||||||
return (subject, html_content, text_content)
|
return (subject, html_content, text_content)
|
||||||
|
|
||||||
|
@ -260,10 +260,7 @@ class CreateInviteForm(CustomForm):
|
|||||||
]
|
]
|
||||||
),
|
),
|
||||||
"use_limit": widgets.Select(
|
"use_limit": widgets.Select(
|
||||||
choices=[
|
choices=[(i, _(f"{i} uses")) for i in [1, 5, 10, 25, 50, 100]]
|
||||||
(i, _(f"{i} uses"))
|
|
||||||
for i in [1, 5, 10, 25, 50, 100]
|
|
||||||
]
|
|
||||||
+ [(None, _("Unlimited"))]
|
+ [(None, _("Unlimited"))]
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ class ActivitypubFieldMixin:
|
|||||||
activitypub_field=None,
|
activitypub_field=None,
|
||||||
activitypub_wrapper=None,
|
activitypub_wrapper=None,
|
||||||
deduplication_field=False,
|
deduplication_field=False,
|
||||||
**kwargs
|
**kwargs,
|
||||||
):
|
):
|
||||||
self.deduplication_field = deduplication_field
|
self.deduplication_field = deduplication_field
|
||||||
if activitypub_wrapper:
|
if activitypub_wrapper:
|
||||||
|
@ -181,7 +181,7 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
|
|||||||
self.replies(self),
|
self.replies(self),
|
||||||
remote_id=f"{self.remote_id}/replies",
|
remote_id=f"{self.remote_id}/replies",
|
||||||
collection_only=True,
|
collection_only=True,
|
||||||
**kwargs
|
**kwargs,
|
||||||
).serialize()
|
).serialize()
|
||||||
|
|
||||||
def to_activity_dataclass(self, pure=False): # pylint: disable=arguments-differ
|
def to_activity_dataclass(self, pure=False): # pylint: disable=arguments-differ
|
||||||
|
@ -198,9 +198,7 @@ class User(OrderedCollectionPageMixin, AbstractUser):
|
|||||||
def to_outbox(self, filter_type=None, **kwargs):
|
def to_outbox(self, filter_type=None, **kwargs):
|
||||||
"""an ordered collection of statuses"""
|
"""an ordered collection of statuses"""
|
||||||
if filter_type:
|
if filter_type:
|
||||||
filter_class = apps.get_model(
|
filter_class = apps.get_model(f"bookwyrm.{filter_type}", require_ready=True)
|
||||||
f"bookwyrm.{filter_type}", require_ready=True
|
|
||||||
)
|
|
||||||
if not issubclass(filter_class, Status):
|
if not issubclass(filter_class, Status):
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
"filter_status_class must be a subclass of models.Status"
|
"filter_status_class must be a subclass of models.Status"
|
||||||
|
@ -413,7 +413,7 @@ def generate_user_preview_image_task(user_id):
|
|||||||
|
|
||||||
texts = {
|
texts = {
|
||||||
"text_one": user.display_name,
|
"text_one": user.display_name,
|
||||||
"text_three": "@{user.localname}@{settings.DOMAIN}"
|
"text_three": "@{user.localname}@{settings.DOMAIN}",
|
||||||
}
|
}
|
||||||
|
|
||||||
if user.avatar:
|
if user.avatar:
|
||||||
|
@ -23,7 +23,9 @@ EMAIL_HOST_USER = env("EMAIL_HOST_USER")
|
|||||||
EMAIL_HOST_PASSWORD = env("EMAIL_HOST_PASSWORD")
|
EMAIL_HOST_PASSWORD = env("EMAIL_HOST_PASSWORD")
|
||||||
EMAIL_USE_TLS = env.bool("EMAIL_USE_TLS", True)
|
EMAIL_USE_TLS = env.bool("EMAIL_USE_TLS", True)
|
||||||
EMAIL_USE_SSL = env.bool("EMAIL_USE_SSL", False)
|
EMAIL_USE_SSL = env.bool("EMAIL_USE_SSL", False)
|
||||||
DEFAULT_FROM_EMAIL = "admin@{:s}".format(env("DOMAIN")) # pylint: disable=consider-using-f-string
|
DEFAULT_FROM_EMAIL = "admin@{:s}".format(
|
||||||
|
env("DOMAIN")
|
||||||
|
) # pylint: disable=consider-using-f-string
|
||||||
|
|
||||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user