mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-22 01:21:07 +00:00
Changes accessor to site model object
This commit is contained in:
parent
cb9782c93d
commit
4c8b089d8b
96 changed files with 50 additions and 145 deletions
|
@ -112,7 +112,7 @@ def first_search_result(
|
|||
def get_connectors() -> Iterator[abstract_connector.AbstractConnector]:
|
||||
"""load all connectors"""
|
||||
queryset = models.Connector.objects.filter(active=True)
|
||||
if models.SiteSettings.objects.get().disable_federation:
|
||||
if models.SiteSettings.get().disable_federation:
|
||||
queryset = queryset.exclude(connector_file="bookwyrm_connector")
|
||||
|
||||
for info in queryset.order_by("priority").all():
|
||||
|
|
|
@ -8,7 +8,7 @@ def site_settings(request):
|
|||
if not request.is_secure():
|
||||
request_protocol = "http://"
|
||||
|
||||
site = models.SiteSettings.objects.get()
|
||||
site = models.SiteSettings.get()
|
||||
theme = "css/themes/bookwyrm-light.scss"
|
||||
if (
|
||||
hasattr(request, "user")
|
||||
|
|
|
@ -9,7 +9,7 @@ from bookwyrm.settings import DOMAIN, BASE_URL
|
|||
|
||||
def email_data():
|
||||
"""fields every email needs"""
|
||||
site = models.SiteSettings.objects.get()
|
||||
site = models.SiteSettings.get()
|
||||
return {
|
||||
"site_name": site.name,
|
||||
"logo": site.logo_small_url,
|
||||
|
|
|
@ -141,7 +141,7 @@ class Importer:
|
|||
# pylint: disable=no-self-use
|
||||
def get_import_limit(self, user: User) -> tuple[int, int]:
|
||||
"""check if import limit is set and return how many imports are left"""
|
||||
site_settings = SiteSettings.objects.get()
|
||||
site_settings = SiteSettings.get()
|
||||
import_size_limit = site_settings.import_size_limit
|
||||
import_limit_reset = site_settings.import_limit_reset
|
||||
enforce_limit = import_size_limit and import_limit_reset
|
||||
|
|
|
@ -6,7 +6,7 @@ from bookwyrm import models
|
|||
|
||||
def get_admin_code():
|
||||
"""get that code"""
|
||||
return models.SiteSettings.objects.get().admin_code
|
||||
return models.SiteSettings.get().admin_code
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
|
|
@ -269,7 +269,7 @@ def preview_image(instance: SiteSettings, *args, **kwargs) -> None:
|
|||
@app.task(queue=MISC)
|
||||
def check_for_updates_task() -> None:
|
||||
"""See if git remote knows about a new version"""
|
||||
site = SiteSettings.objects.get()
|
||||
site = SiteSettings.get()
|
||||
release = get_data(RELEASE_API, timeout=3, is_activitypub=False)
|
||||
available_version = release.get("tag_name", None)
|
||||
if available_version:
|
||||
|
|
|
@ -172,7 +172,7 @@ def generate_instance_layer(content_width):
|
|||
"""Places components for instance preview"""
|
||||
font_instance = get_font("light", size=28)
|
||||
|
||||
site = models.SiteSettings.objects.get()
|
||||
site = models.SiteSettings.get()
|
||||
|
||||
if site.logo_small:
|
||||
with Image.open(site.logo_small) as logo_img:
|
||||
|
@ -426,7 +426,7 @@ def generate_site_preview_image_task():
|
|||
if not settings.ENABLE_PREVIEW_IMAGES:
|
||||
return
|
||||
|
||||
site = models.SiteSettings.objects.get()
|
||||
site = models.SiteSettings.get()
|
||||
|
||||
if site.logo:
|
||||
logo = site.logo
|
||||
|
|
|
@ -43,7 +43,6 @@ class BookwyrmBooksImport(TestCase):
|
|||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "password", local=True
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
work = models.Work.objects.create(title="Test Work")
|
||||
cls.book = models.Edition.objects.create(
|
||||
title="Example Edition",
|
||||
|
|
|
@ -37,7 +37,6 @@ class CalibreImport(TestCase):
|
|||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "password", local=True
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
work = models.Work.objects.create(title="Test Work")
|
||||
cls.book = models.Edition.objects.create(
|
||||
title="Example Edition",
|
||||
|
|
|
@ -43,7 +43,6 @@ class GoodreadsImport(TestCase):
|
|||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "password", local=True
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
work = models.Work.objects.create(title="Test Work")
|
||||
cls.book = models.Edition.objects.create(
|
||||
title="Example Edition",
|
||||
|
|
|
@ -46,7 +46,6 @@ class GenericImporter(TestCase):
|
|||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "password", local=True
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
work = models.Work.objects.create(title="Test Work")
|
||||
cls.book = models.Edition.objects.create(
|
||||
title="Example Edition",
|
||||
|
@ -374,7 +373,7 @@ class GenericImporter(TestCase):
|
|||
|
||||
def test_import_limit(self, *_):
|
||||
"""checks if import limit works"""
|
||||
site_settings = models.SiteSettings.objects.get()
|
||||
site_settings = models.SiteSettings.get()
|
||||
site_settings.import_size_limit = 2
|
||||
site_settings.import_limit_reset = 2
|
||||
site_settings.save()
|
||||
|
|
|
@ -45,7 +45,6 @@ class LibrarythingImport(TestCase):
|
|||
cls.local_user = models.User.objects.create_user(
|
||||
"mmai", "mmai@mmai.mmai", "password", local=True
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
work = models.Work.objects.create(title="Test Work")
|
||||
cls.book = models.Edition.objects.create(
|
||||
title="Example Edition",
|
||||
|
|
|
@ -43,7 +43,6 @@ class OpenLibraryImport(TestCase):
|
|||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "password", local=True
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
work = models.Work.objects.create(title="Test Work")
|
||||
cls.book = models.Edition.objects.create(
|
||||
title="Example Edition",
|
||||
|
|
|
@ -43,7 +43,6 @@ class StorygraphImport(TestCase):
|
|||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "password", local=True
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
work = models.Work.objects.create(title="Test Work")
|
||||
cls.book = models.Edition.objects.create(
|
||||
title="Example Edition",
|
||||
|
|
|
@ -28,7 +28,7 @@ class ContextProcessor(TestCase):
|
|||
)
|
||||
cls.anonymous_user = AnonymousUser
|
||||
cls.anonymous_user.is_authenticated = False
|
||||
cls.site = models.SiteSettings.objects.create()
|
||||
cls.site = models.SiteSettings.get()
|
||||
|
||||
def setUp(self):
|
||||
"""other test data"""
|
||||
|
|
|
@ -26,7 +26,6 @@ class Emailing(TestCase):
|
|||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""other test data"""
|
||||
|
|
|
@ -12,8 +12,6 @@ class MergeBookDataModel(TestCase):
|
|||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
"""shared data"""
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
cls.jrr_tolkien = models.Author.objects.create(
|
||||
name="J.R.R. Tolkien",
|
||||
aliases=["JRR Tolkien", "Tolkien"],
|
||||
|
|
|
@ -92,7 +92,7 @@ class PreviewImages(TestCase):
|
|||
parent_work=self.work,
|
||||
)
|
||||
|
||||
self.site = models.SiteSettings.objects.create()
|
||||
self.site = models.SiteSettings.get()
|
||||
|
||||
settings.ENABLE_PREVIEW_IMAGES = True
|
||||
|
||||
|
|
|
@ -27,8 +27,6 @@ class AnnouncementViews(TestCase):
|
|||
localname="mouse",
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
|
|
@ -34,7 +34,6 @@ class AutomodViews(TestCase):
|
|||
initdb.init_permissions()
|
||||
group = Group.objects.get(name="moderator")
|
||||
cls.local_user.groups.set([group])
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -33,7 +33,6 @@ class CeleryStatusViews(TestCase):
|
|||
initdb.init_permissions()
|
||||
group = Group.objects.get(name="admin")
|
||||
cls.local_user.groups.set([group])
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -34,8 +34,6 @@ class DashboardViews(TestCase):
|
|||
group = Group.objects.get(name="moderator")
|
||||
cls.local_user.groups.set([group])
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
|
|
@ -34,8 +34,6 @@ class EmailBlocklistViews(TestCase):
|
|||
group = Group.objects.get(name="moderator")
|
||||
cls.local_user.groups.set([group])
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
|
|
@ -33,7 +33,6 @@ class EmailConfigViews(TestCase):
|
|||
initdb.init_permissions()
|
||||
group = Group.objects.get(name="admin")
|
||||
cls.local_user.groups.set([group])
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -46,8 +46,6 @@ class FederationViews(TestCase):
|
|||
group = Group.objects.get(name="moderator")
|
||||
cls.local_user.groups.set([group])
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
|
|
@ -33,7 +33,6 @@ class ImportsAdminViews(TestCase):
|
|||
initdb.init_permissions()
|
||||
group = Group.objects.get(name="admin")
|
||||
cls.local_user.groups.set([group])
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -34,8 +34,6 @@ class IPBlocklistViews(TestCase):
|
|||
group = Group.objects.get(name="moderator")
|
||||
cls.local_user.groups.set([group])
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
|
|
@ -41,8 +41,6 @@ class LinkDomainViews(TestCase):
|
|||
added_by=cls.local_user,
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
|
|
@ -41,7 +41,6 @@ class ReportViews(TestCase):
|
|||
initdb.init_permissions()
|
||||
group = Group.objects.get(name="moderator")
|
||||
cls.local_user.groups.set([group])
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -34,7 +34,7 @@ class SiteSettingsViews(TestCase):
|
|||
group = Group.objects.get(name="admin")
|
||||
cls.local_user.groups.set([group])
|
||||
|
||||
cls.site = models.SiteSettings.objects.create()
|
||||
cls.site = models.SiteSettings.get()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
@ -73,7 +73,7 @@ class SiteSettingsViews(TestCase):
|
|||
validate_html(result.render())
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
site = models.SiteSettings.objects.get()
|
||||
site = models.SiteSettings.get()
|
||||
self.assertEqual(site.name, "Name!")
|
||||
|
||||
def test_site_post_invalid(self):
|
||||
|
|
|
@ -42,7 +42,7 @@ class AdminThemesViews(TestCase):
|
|||
group = Group.objects.get(name="admin")
|
||||
cls.local_user.groups.set([group])
|
||||
|
||||
cls.site = models.SiteSettings.objects.create()
|
||||
cls.site = models.SiteSettings.get()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -34,7 +34,6 @@ class UserAdminViews(TestCase):
|
|||
initdb.init_permissions()
|
||||
group = Group.objects.get(name="moderator")
|
||||
cls.local_user.groups.set([group])
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -52,8 +52,6 @@ class BookViews(TestCase):
|
|||
parent_work=cls.work,
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
|
|
@ -49,7 +49,6 @@ class EditBookViews(TestCase):
|
|||
remote_id="https://example.com/book/1",
|
||||
parent_work=cls.work,
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -37,8 +37,6 @@ class BookViews(TestCase):
|
|||
physical_format="paperback",
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
|
|
@ -47,8 +47,6 @@ class LinkViews(TestCase):
|
|||
parent_work=cls.work,
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
|
|
@ -31,7 +31,6 @@ class ImportViews(TestCase):
|
|||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -26,7 +26,6 @@ class ImportManualReviewViews(TestCase):
|
|||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
cls.job = models.ImportJob.objects.create(user=cls.local_user, mappings={})
|
||||
|
||||
work = models.Work.objects.create(title="Test Work")
|
||||
|
|
|
@ -27,7 +27,6 @@ class ImportTroubleshootViews(TestCase):
|
|||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -29,7 +29,6 @@ class ImportUserViews(TestCase):
|
|||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_get_user_import_page(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
|
|
|
@ -54,7 +54,6 @@ class Inbox(TestCase):
|
|||
inbox="https://example.com/users/rat/inbox",
|
||||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_inbox_invalid_get(self):
|
||||
"""shouldn't try to handle if the user is not found"""
|
||||
|
|
|
@ -45,8 +45,6 @@ class InboxAdd(TestCase):
|
|||
parent_work=work,
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
@responses.activate
|
||||
def test_handle_add_book_to_shelf(self):
|
||||
"""shelving a book"""
|
||||
|
|
|
@ -48,8 +48,6 @@ class InboxActivities(TestCase):
|
|||
remote_id="https://example.com/status/1",
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.create_json = {
|
||||
|
|
|
@ -37,8 +37,6 @@ class InboxBlock(TestCase):
|
|||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_handle_blocks(self):
|
||||
"""create a "block" database entry from an activity"""
|
||||
self.local_user.followers.add(self.remote_user)
|
||||
|
|
|
@ -47,7 +47,6 @@ class TransactionInboxCreate(TransactionTestCase):
|
|||
"cc": ["https://example.com/user/mouse/followers"],
|
||||
"object": {},
|
||||
}
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_create_status_transaction(self, *_):
|
||||
"""the "it justs works" mode"""
|
||||
|
|
|
@ -44,8 +44,6 @@ class InboxActivities(TestCase):
|
|||
remote_id="https://example.com/status/1",
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_delete_status(self):
|
||||
"""remove a status"""
|
||||
self.assertFalse(self.status.deleted)
|
||||
|
|
|
@ -38,8 +38,6 @@ class InboxRelationships(TestCase):
|
|||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_follow(self):
|
||||
"""remote user wants to follow local user"""
|
||||
activity = {
|
||||
|
|
|
@ -47,8 +47,6 @@ class InboxActivities(TestCase):
|
|||
remote_id="https://example.com/status/1",
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.create_json = {
|
||||
|
|
|
@ -44,8 +44,6 @@ class InboxRemove(TestCase):
|
|||
parent_work=cls.work,
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_handle_unshelve_book(self):
|
||||
"""remove a book from a shelf"""
|
||||
shelf = models.Shelf.objects.create(user=self.remote_user, name="Test Shelf")
|
||||
|
|
|
@ -39,8 +39,6 @@ class InboxUpdate(TestCase):
|
|||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.update_json = {
|
||||
|
|
|
@ -29,7 +29,6 @@ class InviteViews(TestCase):
|
|||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -29,7 +29,6 @@ class LandingViews(TestCase):
|
|||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
@ -94,7 +93,7 @@ class LandingViews(TestCase):
|
|||
|
||||
def test_impressum_page_on(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
site = models.SiteSettings.objects.get()
|
||||
site = models.SiteSettings.get()
|
||||
site.show_impressum = True
|
||||
site.save()
|
||||
|
||||
|
|
|
@ -47,7 +47,9 @@ class LoginViews(TestCase):
|
|||
localname="badger",
|
||||
two_factor_auth=True,
|
||||
)
|
||||
models.SiteSettings.objects.create(id=1, require_confirm_email=False)
|
||||
site = models.SiteSettings.get()
|
||||
site.require_confirm_email = False
|
||||
site.save()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -31,7 +31,6 @@ class PasswordViews(TestCase):
|
|||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
models.SiteSettings.objects.create(id=1)
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -35,9 +35,10 @@ class RegisterViews(TestCase):
|
|||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
cls.settings = models.SiteSettings.objects.create(
|
||||
id=1, require_confirm_email=False, allow_registration=True
|
||||
)
|
||||
cls.settings = models.SiteSettings.get()
|
||||
cls.settings.require_confirm_email = False
|
||||
cls.settings.allow_registration = True
|
||||
cls.settings.save()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -43,8 +43,6 @@ class ListViews(TestCase):
|
|||
):
|
||||
cls.list = models.List.objects.create(name="Test List", user=cls.local_user)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
|
|
@ -43,8 +43,6 @@ class ListViews(TestCase):
|
|||
):
|
||||
cls.list = models.List.objects.create(name="Test List", user=cls.local_user)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
|
|
@ -72,8 +72,6 @@ class ListViews(TestCase):
|
|||
):
|
||||
cls.list = models.List.objects.create(name="Test List", user=cls.local_user)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
|
|
@ -38,8 +38,6 @@ class ListItemViews(TestCase):
|
|||
):
|
||||
cls.list = models.List.objects.create(name="Test List", user=cls.local_user)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
|
|
@ -35,8 +35,6 @@ class ListViews(TestCase):
|
|||
"rat@local.com", "rat@rat.com", "ratword", local=True, localname="rat"
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
|
|
@ -39,8 +39,6 @@ class BlockViews(TestCase):
|
|||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
|
|
@ -27,7 +27,6 @@ class ChangePasswordViews(TestCase):
|
|||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
models.SiteSettings.objects.create(id=1)
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -52,8 +52,6 @@ class DeleteUserViews(TestCase):
|
|||
shelf=cls.local_user.shelf_set.first(),
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
|
|
@ -50,8 +50,6 @@ class EditUserViews(TestCase):
|
|||
shelf=cls.local_user.shelf_set.first(),
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
|
|
@ -14,7 +14,6 @@ class ExportUserViews(TestCase):
|
|||
|
||||
def setUp(self):
|
||||
self.factory = RequestFactory()
|
||||
models.SiteSettings.objects.create()
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
|
|
|
@ -46,7 +46,6 @@ class ShelfViews(TestCase):
|
|||
cls.shelf = models.Shelf.objects.create(
|
||||
name="Test Shelf", identifier="test-shelf", user=cls.local_user
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -52,7 +52,6 @@ class ShelfActionViews(TestCase):
|
|||
cls.shelf = models.Shelf.objects.create(
|
||||
name="Test Shelf", identifier="test-shelf", user=cls.local_user
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -44,7 +44,6 @@ class AnnualSummary(TestCase):
|
|||
parent_work=cls.work,
|
||||
pages=300,
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -46,7 +46,6 @@ class AuthorViews(TestCase):
|
|||
remote_id="https://example.com/book/1",
|
||||
parent_work=cls.work,
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -29,7 +29,6 @@ class DirectoryViews(TestCase):
|
|||
localname="mouse",
|
||||
remote_id="https://example.com/users/mouse",
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -26,7 +26,6 @@ class DiscoverViews(TestCase):
|
|||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -48,7 +48,6 @@ class FeedViews(TestCase):
|
|||
title="Example Edition",
|
||||
remote_id="https://example.com/book/1",
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -20,7 +20,6 @@ class FollowViews(TestCase):
|
|||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
"""we need basic test data and mocks"""
|
||||
models.SiteSettings.objects.create()
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
|
|
|
@ -39,7 +39,6 @@ class GetStartedViews(TestCase):
|
|||
title="Example Edition",
|
||||
remote_id="https://example.com/book/1",
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -43,7 +43,6 @@ class GoalViews(TestCase):
|
|||
title="Example Edition",
|
||||
remote_id="https://example.com/book/1",
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -48,7 +48,6 @@ class GroupViews(TestCase):
|
|||
cls.membership = models.GroupMember.objects.create(
|
||||
group=cls.testgroup, user=cls.local_user
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -67,8 +67,6 @@ class HashtagView(TestCase):
|
|||
for status in cls.statuses_bookclub:
|
||||
status.mention_hashtags.add(cls.hashtag_bookclub)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
|
|
@ -37,7 +37,6 @@ class IsbnViews(TestCase):
|
|||
remote_id="https://example.com/book/1",
|
||||
parent_work=cls.work,
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -32,7 +32,6 @@ class NotificationViews(TestCase):
|
|||
)
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
|
||||
cls.status = models.Status.objects.create(content="hi", user=cls.local_user)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -41,7 +41,6 @@ class ReportViews(TestCase):
|
|||
user=cls.local_user,
|
||||
content="Test status",
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -28,7 +28,6 @@ class RssFeedView(TestCase):
|
|||
remote_id="https://example.com/book/1",
|
||||
parent_work=work,
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -39,7 +39,6 @@ class Views(TestCase):
|
|||
remote_id="https://example.com/book/1",
|
||||
parent_work=cls.work,
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -16,7 +16,9 @@ class SetupViews(TestCase):
|
|||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
"""we need basic test data and mocks"""
|
||||
cls.site = models.SiteSettings.objects.create(install_mode=True)
|
||||
cls.site = models.SiteSettings.get()
|
||||
cls.site.install_mode = True
|
||||
cls.site.save()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -118,7 +118,6 @@ class StatusViews(TestCase):
|
|||
remote_id="https://example.com/book/1",
|
||||
parent_work=work,
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -27,7 +27,6 @@ class UpdateViews(TestCase):
|
|||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -46,7 +46,6 @@ class UserViews(TestCase):
|
|||
user=cls.local_user,
|
||||
shelf=cls.local_user.shelf_set.first(),
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -41,7 +41,6 @@ class WellknownViews(TestCase):
|
|||
inbox="https://example.com/users/rat/inbox",
|
||||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -47,7 +47,7 @@ class Dashboard(View):
|
|||
"email_sender"
|
||||
] = f"{settings.EMAIL_SENDER_NAME}@{settings.EMAIL_SENDER_DOMAIN}"
|
||||
|
||||
site = models.SiteSettings.objects.get()
|
||||
site = models.SiteSettings.get()
|
||||
# pylint: disable=protected-access
|
||||
data["missing_conduct"] = (
|
||||
not site.code_of_conduct
|
||||
|
|
|
@ -18,7 +18,7 @@ class FederationSettings(View):
|
|||
|
||||
def get(self, request):
|
||||
"""show the current settings"""
|
||||
site = models.SiteSettings.objects.get()
|
||||
site = models.SiteSettings.get()
|
||||
data = {
|
||||
"form": forms.FederationSettings(instance=site),
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ class FederationSettings(View):
|
|||
|
||||
def post(self, request):
|
||||
"""Update federation settings"""
|
||||
site = models.SiteSettings.objects.get()
|
||||
site = models.SiteSettings.get()
|
||||
form = forms.FederationSettings(request.POST, instance=site)
|
||||
if not form.is_valid():
|
||||
data = {"form": form}
|
||||
|
|
|
@ -47,7 +47,7 @@ class ImportList(View):
|
|||
user_paginated = Paginator(user_imports, PAGE_LENGTH)
|
||||
user_page = user_paginated.get_page(request.GET.get("page"))
|
||||
|
||||
site_settings = models.SiteSettings.objects.get()
|
||||
site_settings = models.SiteSettings.get()
|
||||
data = {
|
||||
"imports": page,
|
||||
"user_imports": user_page,
|
||||
|
@ -75,7 +75,7 @@ class ImportList(View):
|
|||
# pylint: disable=unused-argument
|
||||
def disable_imports(request):
|
||||
"""When you just need people to please stop starting imports"""
|
||||
site = models.SiteSettings.objects.get()
|
||||
site = models.SiteSettings.get()
|
||||
site.imports_enabled = False
|
||||
site.save(update_fields=["imports_enabled"])
|
||||
return redirect("settings-imports")
|
||||
|
@ -86,7 +86,7 @@ def disable_imports(request):
|
|||
# pylint: disable=unused-argument
|
||||
def enable_imports(request):
|
||||
"""When you just need people to please stop starting imports"""
|
||||
site = models.SiteSettings.objects.get()
|
||||
site = models.SiteSettings.get()
|
||||
site.imports_enabled = True
|
||||
site.save(update_fields=["imports_enabled"])
|
||||
return redirect("settings-imports")
|
||||
|
@ -96,7 +96,7 @@ def enable_imports(request):
|
|||
@permission_required("bookwyrm.edit_instance_settings", raise_exception=True)
|
||||
def set_import_size_limit(request):
|
||||
"""Limit the amount of books users can import at once"""
|
||||
site = models.SiteSettings.objects.get()
|
||||
site = models.SiteSettings.get()
|
||||
import_size_limit = int(request.POST.get("limit"))
|
||||
import_limit_reset = int(request.POST.get("reset"))
|
||||
site.import_size_limit = import_size_limit
|
||||
|
@ -120,7 +120,7 @@ def set_user_import_completed(request, import_id):
|
|||
@permission_required("bookwyrm.edit_instance_settings", raise_exception=True)
|
||||
def set_user_import_limit(request):
|
||||
"""Limit how ofter users can import and export their account"""
|
||||
site = models.SiteSettings.objects.get()
|
||||
site = models.SiteSettings.get()
|
||||
site.user_import_time_limit = int(request.POST.get("limit"))
|
||||
site.save(update_fields=["user_import_time_limit"])
|
||||
return redirect("settings-imports")
|
||||
|
@ -131,7 +131,7 @@ def set_user_import_limit(request):
|
|||
# pylint: disable=unused-argument
|
||||
def enable_user_exports(request):
|
||||
"""Allow users to export account data"""
|
||||
site = models.SiteSettings.objects.get()
|
||||
site = models.SiteSettings.get()
|
||||
site.user_exports_enabled = True
|
||||
site.save(update_fields=["user_exports_enabled"])
|
||||
return redirect("settings-imports")
|
||||
|
@ -142,7 +142,7 @@ def enable_user_exports(request):
|
|||
# pylint: disable=unused-argument
|
||||
def disable_user_exports(request):
|
||||
"""Don't allow users to export account data"""
|
||||
site = models.SiteSettings.objects.get()
|
||||
site = models.SiteSettings.get()
|
||||
site.user_exports_enabled = False
|
||||
site.save(update_fields=["user_exports_enabled"])
|
||||
return redirect("settings-imports")
|
||||
|
|
|
@ -18,13 +18,13 @@ class Site(View):
|
|||
|
||||
def get(self, request):
|
||||
"""edit form"""
|
||||
site = models.SiteSettings.objects.get()
|
||||
site = models.SiteSettings.get()
|
||||
data = {"site_form": forms.SiteForm(instance=site)}
|
||||
return TemplateResponse(request, "settings/site.html", data)
|
||||
|
||||
def post(self, request):
|
||||
"""edit the site settings"""
|
||||
site = models.SiteSettings.objects.get()
|
||||
site = models.SiteSettings.get()
|
||||
form = forms.SiteForm(request.POST, request.FILES, instance=site)
|
||||
if not form.is_valid():
|
||||
data = {"site_form": form}
|
||||
|
@ -45,13 +45,13 @@ class RegistrationLimited(View):
|
|||
|
||||
def get(self, request):
|
||||
"""edit form"""
|
||||
site = models.SiteSettings.objects.get()
|
||||
site = models.SiteSettings.get()
|
||||
data = {"form": forms.RegistrationLimitedForm(instance=site)}
|
||||
return TemplateResponse(request, "settings/registration_limited.html", data)
|
||||
|
||||
def post(self, request):
|
||||
"""edit the site settings"""
|
||||
site = models.SiteSettings.objects.get()
|
||||
site = models.SiteSettings.get()
|
||||
form = forms.RegistrationLimitedForm(request.POST, request.FILES, instance=site)
|
||||
if not form.is_valid():
|
||||
data = {"form": form}
|
||||
|
@ -72,13 +72,13 @@ class Registration(View):
|
|||
|
||||
def get(self, request):
|
||||
"""edit form"""
|
||||
site = models.SiteSettings.objects.get()
|
||||
site = models.SiteSettings.get()
|
||||
data = {"form": forms.RegistrationForm(instance=site)}
|
||||
return TemplateResponse(request, "settings/registration.html", data)
|
||||
|
||||
def post(self, request):
|
||||
"""edit the site settings"""
|
||||
site = models.SiteSettings.objects.get()
|
||||
site = models.SiteSettings.get()
|
||||
form = forms.RegistrationForm(request.POST, request.FILES, instance=site)
|
||||
if not form.is_valid():
|
||||
data = {"form": form}
|
||||
|
|
|
@ -54,7 +54,7 @@ class Import(View):
|
|||
elif seconds:
|
||||
data["recent_avg_minutes"] = seconds / 60
|
||||
|
||||
site_settings = models.SiteSettings.objects.get()
|
||||
site_settings = models.SiteSettings.get()
|
||||
time_range = timezone.now() - datetime.timedelta(
|
||||
days=site_settings.import_limit_reset
|
||||
)
|
||||
|
@ -71,7 +71,7 @@ class Import(View):
|
|||
|
||||
def post(self, request):
|
||||
"""ingest a book data csv"""
|
||||
site = models.SiteSettings.objects.get()
|
||||
site = models.SiteSettings.get()
|
||||
if not site.imports_enabled:
|
||||
raise PermissionDenied()
|
||||
|
||||
|
@ -149,7 +149,7 @@ class UserImport(View):
|
|||
jobs = BookwyrmImportJob.objects.filter(user=request.user).order_by(
|
||||
"-created_date"
|
||||
)
|
||||
site = models.SiteSettings.objects.get()
|
||||
site = models.SiteSettings.get()
|
||||
hours = site.user_import_time_limit
|
||||
allowed = (
|
||||
jobs.first().created_date < timezone.now() - datetime.timedelta(hours=hours)
|
||||
|
|
|
@ -42,7 +42,7 @@ def privacy(request):
|
|||
@require_GET
|
||||
def impressum(request):
|
||||
"""more information about the instance"""
|
||||
site = models.SiteSettings.objects.get()
|
||||
site = models.SiteSettings.get()
|
||||
if not site.show_impressum:
|
||||
raise Http404()
|
||||
return TemplateResponse(request, "about/impressum.html")
|
||||
|
|
|
@ -16,7 +16,7 @@ class Home(View):
|
|||
if request.user.is_authenticated:
|
||||
feed_view = Feed.as_view()
|
||||
return feed_view(request, "home")
|
||||
site = models.SiteSettings.objects.get()
|
||||
site = models.SiteSettings.get()
|
||||
|
||||
if site.install_mode:
|
||||
return redirect("setup")
|
||||
|
|
|
@ -166,7 +166,7 @@ class ExportUser(View):
|
|||
last_job = self.user_jobs.first()
|
||||
if not last_job:
|
||||
return None
|
||||
site = models.SiteSettings.objects.get()
|
||||
site = models.SiteSettings.get()
|
||||
blocked_until = last_job.created_date + timedelta(
|
||||
hours=site.user_import_time_limit
|
||||
)
|
||||
|
|
|
@ -22,7 +22,7 @@ class InstanceConfig(View):
|
|||
def get(self, request):
|
||||
"""Check out this cool instance"""
|
||||
# only allow this view when an instance is being configured
|
||||
site = models.SiteSettings.objects.get()
|
||||
site = models.SiteSettings.get()
|
||||
if not site.install_mode:
|
||||
raise PermissionDenied()
|
||||
|
||||
|
@ -55,7 +55,7 @@ class CreateAdmin(View):
|
|||
def get(self, request):
|
||||
"""Create admin user form"""
|
||||
# only allow this view when an instance is being configured
|
||||
site = models.SiteSettings.objects.get()
|
||||
site = models.SiteSettings.get()
|
||||
if not site.install_mode:
|
||||
raise PermissionDenied()
|
||||
|
||||
|
@ -65,7 +65,7 @@ class CreateAdmin(View):
|
|||
@transaction.atomic
|
||||
def post(self, request):
|
||||
"""Create that user"""
|
||||
site = models.SiteSettings.objects.get()
|
||||
site = models.SiteSettings.get()
|
||||
# you can't create an admin user if you're in config mode
|
||||
if not site.install_mode:
|
||||
raise PermissionDenied()
|
||||
|
|
Loading…
Reference in a new issue