From cf6cb6236459587b86e9a9a3d85f8e2c8fb7987e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20Caux?= <git@jscaux.org> Date: Fri, 15 Apr 2022 16:10:57 +0200 Subject: [PATCH] Refactor to enable `migrate` on empty database --- scipost_django/careers/views.py | 4 ++-- scipost_django/commentaries/views.py | 6 +++--- scipost_django/common/utils.py | 11 +++++++++-- scipost_django/invitations/utils.py | 6 ++---- scipost_django/invitations/views.py | 6 +++--- scipost_django/journals/forms.py | 9 ++++----- scipost_django/journals/models/update.py | 5 +++-- scipost_django/journals/utils.py | 7 +++---- scipost_django/journals/views.py | 4 ++-- scipost_django/mails/core.py | 11 ++++++----- scipost_django/mails/mixins.py | 4 ++-- scipost_django/ontology/forms.py | 18 +++++++++++------- scipost_django/petitions/views.py | 4 ++-- scipost_django/preprints/models.py | 4 ++-- scipost_django/production/utils.py | 4 ++-- scipost_django/scipost/forms.py | 4 ++-- scipost_django/scipost/tasks.py | 4 ++-- scipost_django/scipost/utils.py | 4 ++-- scipost_django/scipost/views.py | 10 +++++----- scipost_django/submissions/utils.py | 5 ++--- scipost_django/submissions/views.py | 7 +++---- scipost_django/theses/forms.py | 4 ++-- scipost_django/webinars/views.py | 4 ++-- 23 files changed, 76 insertions(+), 69 deletions(-) diff --git a/scipost_django/careers/views.py b/scipost_django/careers/views.py index b4712d166..db41a094a 100644 --- a/scipost_django/careers/views.py +++ b/scipost_django/careers/views.py @@ -4,13 +4,13 @@ __license__ = "AGPL v3" from django.contrib import messages from django.contrib.auth.mixins import UserPassesTestMixin -from django.contrib.sites.models import Site from django.urls import reverse_lazy from django.shortcuts import get_object_or_404, redirect from django.views.generic.detail import DetailView from django.views.generic.edit import CreateView, UpdateView from django.views.generic.list import ListView +from common.utils import get_current_domain from mails.utils import DirectMailUtil from .models import JobOpening, JobApplication @@ -85,7 +85,7 @@ class JobOpeningApplyView(CreateView): "careers/jobapplication_ack", delayed_processing=False, bcc=[ - "admin@{domain}".format(domain=Site.objects.get_current().domain), + "admin@{domain}".format(domain=get_current_domain()), ], jobapplication=self.object, ) diff --git a/scipost_django/commentaries/views.py b/scipost_django/commentaries/views.py index e9ac27b9f..9a72d41bf 100644 --- a/scipost_django/commentaries/views.py +++ b/scipost_django/commentaries/views.py @@ -5,7 +5,6 @@ __license__ = "AGPL v3" from django.shortcuts import get_object_or_404, render from django.contrib import messages from django.contrib.auth.decorators import login_required, permission_required -from django.contrib.sites.models import Site from django.core.mail import EmailMessage from django.urls import reverse, reverse_lazy from django.db import transaction @@ -30,6 +29,7 @@ from .forms import ( from comments.models import Comment from comments.forms import CommentForm +from common.utils import get_current_domain from journals.models import Publication from scipost.mixins import PaginationMixin @@ -141,7 +141,7 @@ def vet_commentary_requests(request, commentary_id=None): request.POST or None, user=request.user, commentary_id=commentary_id ) if form.is_valid(): - domain = Site.objects.get_current().domain + domain = get_current_domain() # Get commentary commentary = form.get_commentary() @@ -194,7 +194,7 @@ def modify_commentary_request(request, commentary_id): ) form = RequestCommentaryForm(request.POST or None, instance=commentary) if form.is_valid(): - domain = Site.objects.get_current().domain + domain = get_current_domain() # Process commentary data commentary = form.save(commit=False) diff --git a/scipost_django/common/utils.py b/scipost_django/common/utils.py index d5253b54d..5d3e35bd2 100644 --- a/scipost_django/common/utils.py +++ b/scipost_django/common/utils.py @@ -125,16 +125,23 @@ def jatsify_tags(text): return jatsified +def get_current_domain(): + try: + return Site.objects.get_current().domain + except: + return "fake.domain" + + # MARKED FOR DEPRECATION class BaseMailUtil(object): - mail_sender = "no-reply@%s" % Site.objects.get_current().domain + mail_sender = "no-reply@%s" % get_current_domain() mail_sender_title = "" @classmethod def load(cls, _dict, request=None): cls._context = _dict cls._context["request"] = request - cls._context["domain"] = Site.objects.get_current().domain + cls._context["domain"] = get_current_domain() for var_name in _dict: setattr(cls, var_name, _dict[var_name]) diff --git a/scipost_django/invitations/utils.py b/scipost_django/invitations/utils.py index 0962bf956..98f4d6775 100644 --- a/scipost_django/invitations/utils.py +++ b/scipost_django/invitations/utils.py @@ -2,13 +2,11 @@ __copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)" __license__ = "AGPL v3" -from django.contrib.sites.models import Site - -from common.utils import BaseMailUtil +from common.utils import get_current_domain, BaseMailUtil class Utils(BaseMailUtil): - mail_sender = "invitations@%s" % Site.objects.get_current().domain + mail_sender = "invitations@%s" % get_current_domain() mail_sender_title = "SciPost Invitation" @classmethod diff --git a/scipost_django/invitations/views.py b/scipost_django/invitations/views.py index 80bb7d189..bcd27f899 100644 --- a/scipost_django/invitations/views.py +++ b/scipost_django/invitations/views.py @@ -4,7 +4,6 @@ __license__ = "AGPL v3" from django.contrib import messages from django.contrib.auth.decorators import login_required, permission_required -from django.contrib.sites.models import Site from django.db import transaction from django.shortcuts import render, redirect from django.urls import reverse_lazy, reverse @@ -29,6 +28,7 @@ from .models import RegistrationInvitation, CitationNotification from scipost.models import Contributor from scipost.mixins import PaginationMixin, PermissionsMixin +from common.utils import get_current_domain from mails.views import MailFormView @@ -223,7 +223,7 @@ class RegistrationInvitationsUpdateView( def get_mail_config(self): config = super().get_mail_config() if self.object.invitation_type == INVITATION_EDITORIAL_FELLOW: - domain = Site.objects.get_current().domain + domain = get_current_domain() config["from_email"] = f"jscaux@{domain}" config["from_name"] = "J-S Caux" return config @@ -282,7 +282,7 @@ class RegistrationInvitationsReminderView( def get_mail_config(self): config = super().get_mail_config() if self.object.invitation_type == INVITATION_EDITORIAL_FELLOW: - domain = Site.objects.get_current().domain + domain = get_current_domain() config["from_email"] = f"jscaux@{domain}" config["from_name"] = "J-S Caux" return config diff --git a/scipost_django/journals/forms.py b/scipost_django/journals/forms.py index f71d223cb..cbf381d3a 100644 --- a/scipost_django/journals/forms.py +++ b/scipost_django/journals/forms.py @@ -12,7 +12,6 @@ from datetime import datetime from django import forms from django.conf import settings -from django.contrib.sites.models import Site from django.db.models import Q from django.forms import BaseModelFormSet, modelformset_factory from django.template import loader @@ -41,7 +40,7 @@ from .models import ( from .utils import JournalUtils -from common.utils import jatsify_tags +from common.utils import get_current_domain, jatsify_tags from funders.models import Grant, Funder from journals.models import Journal from mails.utils import DirectMailUtil @@ -271,7 +270,7 @@ class CreateMetadataXMLForm(forms.ModelForm): # Render from template template = loader.get_template("xml/publication_crossref.html") context = { - "domain": Site.objects.get_current().domain, + "domain": get_current_domain(), "publication": publication, "doi_batch_id": doi_batch_id, "deposit_email": settings.CROSSREF_DEPOSIT_EMAIL, @@ -649,7 +648,7 @@ class DraftPublicationForm(forms.ModelForm): paper_nr, issue.until_date.strftime("%Y"), doi_string, - Site.objects.get_current().domain, + get_current_domain(), doi_string, ) @@ -686,7 +685,7 @@ class DraftPublicationForm(forms.ModelForm): paper_nr, timezone.now().year, doi_string, - Site.objects.get_current().domain, + get_current_domain(), doi_string, ) self.fields["BiBTeX_entry"].initial = bibtex_entry diff --git a/scipost_django/journals/models/update.py b/scipost_django/journals/models/update.py index 128ce0e7a..554a1bd8c 100644 --- a/scipost_django/journals/models/update.py +++ b/scipost_django/journals/models/update.py @@ -7,13 +7,14 @@ import random import string from django.conf import settings -from django.contrib.sites.models import Site from django.contrib.contenttypes.fields import GenericRelation from django.contrib.postgres.fields import JSONField from django.db import models from django.template import loader from django.urls import reverse +from common.utils import get_current_domain + class PublicationUpdate(models.Model): """ @@ -119,7 +120,7 @@ class PublicationUpdate(models.Model): # Render from template template = loader.get_template("xml/publication_update_crossref.html") context = { - "domain": Site.objects.get_current().domain, + "domain": get_current_domain(), "update": self, "doi_batch_id": doi_batch_id, "deposit_email": settings.CROSSREF_DEPOSIT_EMAIL, diff --git a/scipost_django/journals/utils.py b/scipost_django/journals/utils.py index c968b11a0..ffa81b056 100644 --- a/scipost_django/journals/utils.py +++ b/scipost_django/journals/utils.py @@ -2,20 +2,19 @@ __copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)" __license__ = "AGPL v3" -from django.contrib.sites.models import Site from django.core.mail import EmailMessage -from common.utils import BaseMailUtil +from common.utils import get_current_domain, BaseMailUtil class JournalUtils(BaseMailUtil): - mail_sender = "edadmin@%s" % Site.objects.get_current().domain + mail_sender = "edadmin@%s" % get_current_domain() mail_sender_title = "SciPost Editorial Admin" @classmethod def send_authors_paper_published_email(cls): """Requires loading 'publication' attribute.""" - domain = Site.objects.get_current().domain + domain = get_current_domain() email_text = ( "Dear " + cls.publication.accepted_submission.submitted_by.profile.get_title_display() diff --git a/scipost_django/journals/views.py b/scipost_django/journals/views.py index 9c83c25a4..8c0e550fb 100644 --- a/scipost_django/journals/views.py +++ b/scipost_django/journals/views.py @@ -18,7 +18,6 @@ import plotly.graph_objects as pgo from django.contrib.auth.decorators import login_required from django.contrib.contenttypes.models import ContentType -from django.contrib.sites.models import Site from django.core.exceptions import PermissionDenied from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.urls import reverse, reverse_lazy @@ -79,6 +78,7 @@ from .services import update_citedby from .utils import JournalUtils from comments.models import Comment +from common.utils import get_current_domain from funders.forms import FunderSelectForm, GrantSelectForm from funders.models import Grant from mails.views import MailEditorSubview @@ -1452,7 +1452,7 @@ def generic_metadata_xml_deposit(request, **kwargs): For PublicationUpdates, the deposit type is `journal_article` and the journal is used as container. """ - domain = Site.objects.get_current().domain + domain = get_current_domain() type_of_object = kwargs["type_of_object"] object_id = int(kwargs["object_id"]) diff --git a/scipost_django/mails/core.py b/scipost_django/mails/core.py index f66ece12e..bbc2d05db 100644 --- a/scipost_django/mails/core.py +++ b/scipost_django/mails/core.py @@ -7,11 +7,12 @@ import re import inspect from django.conf import settings -from django.contrib.sites.models import Site from django.core.mail import EmailMultiAlternatives from django.db import models from django.template.loader import get_template +from common.utils import get_current_domain + from .exceptions import ConfigurationError @@ -68,7 +69,7 @@ class MailEngine: } self.template_variables = kwargs # Add the 'domain' template variable to all templates using the Sites framework: - self.template_variables["domain"] = Site.objects.get_current().domain + self.template_variables["domain"] = get_current_domain() def __repr__(self): return '<%(cls)s code="%(code)s", validated=%(validated)s sent=%(sent)s>' % { @@ -130,14 +131,14 @@ class MailEngine: % ( self.mail_data.get("from_name", "SciPost"), self.mail_data.get( - "from_email", "noreply@%s" % Site.objects.get_current().domain + "from_email", "noreply@%s" % get_current_domain() ), ), self.mail_data["recipient_list"], bcc=self.mail_data["bcc"], reply_to=[ self.mail_data.get( - "from_email", "noreply@%s" % Site.objects.get_current().domain + "from_email", "noreply@%s" % get_current_domain() ) ], headers={ @@ -280,7 +281,7 @@ class MailEngine: return entry # if the email address is given as a prefix of the form `[recipient]@`, add domain name: elif re.match("[^@]+@$", entry): - return "%s%s" % (entry, Site.objects.get_current().domain) + return "%s%s" % (entry, get_current_domain()) elif self.template_variables["object"]: mail_to = self.template_variables["object"] for attr in entry.split("."): diff --git a/scipost_django/mails/mixins.py b/scipost_django/mails/mixins.py index 59e1cee96..ae3060d64 100644 --- a/scipost_django/mails/mixins.py +++ b/scipost_django/mails/mixins.py @@ -10,11 +10,11 @@ from html2text import HTML2Text from django.core.mail import EmailMultiAlternatives from django.contrib.auth import get_user_model -from django.contrib.sites.models import Site from django.conf import settings from django.template import loader from scipost.models import Contributor +from common.utils import get_current_domain class MailUtilsMixin: @@ -59,7 +59,7 @@ class MailUtilsMixin: "bcc_to": kwargs.pop("bcc", ""), "from_address_name": kwargs.pop("from_name", "SciPost"), "from_address": kwargs.pop( - "from", "no-reply@%s" % Site.objects.get_current().domain + "from", "no-reply@%s" % get_current_domain() ), } diff --git a/scipost_django/ontology/forms.py b/scipost_django/ontology/forms.py index 20f806c49..02b6146fb 100644 --- a/scipost_django/ontology/forms.py +++ b/scipost_django/ontology/forms.py @@ -3,6 +3,7 @@ __license__ = "AGPL v3" from django import forms +from django.db.utils import ProgrammingError from crispy_forms.helper import FormHelper from crispy_forms.layout import Layout, Div @@ -15,13 +16,16 @@ from .models import Branch, AcademicField, Specialty, Tag, Topic def academic_field_slug_choices(): choices = (("All", (("all", "All"),)),) - for branch in Branch.objects.all(): - if branch.name != "Multidisciplinary" and branch.journals.active().exists(): - subchoices = () - for acad_field in branch.academic_fields.all(): - if acad_field.journals.active().exists(): - subchoices += ((acad_field.slug, acad_field.name),) - choices += ((branch.name, subchoices),) + try: + for branch in Branch.objects.all(): + if branch.name != "Multidisciplinary" and branch.journals.active().exists(): + subchoices = () + for acad_field in branch.academic_fields.all(): + if acad_field.journals.active().exists(): + subchoices += ((acad_field.slug, acad_field.name),) + choices += ((branch.name, subchoices),) + except ProgrammingError: # when running on new, empty database + pass return choices diff --git a/scipost_django/petitions/views.py b/scipost_django/petitions/views.py index f6b1d86c9..da8541769 100644 --- a/scipost_django/petitions/views.py +++ b/scipost_django/petitions/views.py @@ -7,11 +7,11 @@ import random import string from django.contrib import messages -from django.contrib.sites.models import Site from django.core.mail import EmailMultiAlternatives from django.shortcuts import get_object_or_404, render, redirect from django.template import Context, Template +from common.utils import get_current_domain from mails.utils import DirectMailUtil from .models import Petition, PetitionSignatory @@ -49,7 +49,7 @@ def petition(request, slug): current_user=request.user, ) if form.is_valid(): - domain = Site.objects.get_current().domain + domain = get_current_domain() signature = form.save(commit=False) signature.petition = petition message = ( diff --git a/scipost_django/preprints/models.py b/scipost_django/preprints/models.py index 5e27bf3dc..4d7d911dc 100644 --- a/scipost_django/preprints/models.py +++ b/scipost_django/preprints/models.py @@ -4,11 +4,11 @@ __license__ = "AGPL v3" import requests -from django.contrib.sites.models import Site from django.urls import reverse from django.db import models from django.http import Http404 +from common.utils import get_current_domain from submissions.exceptions import PreprintDocumentNotFoundError @@ -68,7 +68,7 @@ class Preprint(models.Model): """Return the absolute URL of the pdf for the meta tag for Google Scholar.""" if self._file: # means this is a SciPost-hosted preprint return "https://%s%s" % ( - Site.objects.get_current().domain, + get_current_domain(), self.get_absolute_url(), ) elif self.is_arXiv: diff --git a/scipost_django/production/utils.py b/scipost_django/production/utils.py index 1e202e22a..994670e10 100644 --- a/scipost_django/production/utils.py +++ b/scipost_django/production/utils.py @@ -5,7 +5,7 @@ from django.contrib.auth.models import Group from django.contrib.sites.models import Site from guardian.shortcuts import assign_perm -from common.utils import BaseMailUtil +from common.utils import get_current_domain, BaseMailUtil def proofs_id_to_slug(id): @@ -29,7 +29,7 @@ def get_or_create_production_stream(submission): class ProductionUtils(BaseMailUtil): - mail_sender = "proofs@%s" % Site.objects.get_current().domain + mail_sender = "proofs@%s" % get_current_domain() mail_sender_title = "SciPost Production" @classmethod diff --git a/scipost_django/scipost/forms.py b/scipost_django/scipost/forms.py index 58556ebc0..2af2ae31b 100644 --- a/scipost_django/scipost/forms.py +++ b/scipost_django/scipost/forms.py @@ -12,7 +12,6 @@ from django.contrib.auth.models import User, Group from django.contrib.auth.forms import AuthenticationForm from django.contrib.auth.password_validation import validate_password from django.contrib.auth.validators import UnicodeUsernameValidator -from django.contrib.sites.models import Site from django.core.exceptions import ValidationError from django.http import Http404 from django.utils import timezone @@ -45,6 +44,7 @@ from common.forms import ModelChoiceFieldwithid from colleges.models import Fellowship, PotentialFellowshipEvent from commentaries.models import Commentary from comments.models import Comment +from common.utils import get_current_domain from funders.models import Grant from invitations.models import CitationNotification from journals.models import PublicationAuthorsTable, Publication @@ -62,7 +62,7 @@ from submissions.models import ( ) from theses.models import ThesisLink -domain = Site.objects.get_current().domain +domain = get_current_domain() REGISTRATION_REFUSAL_CHOICES = ( (None, "-"), diff --git a/scipost_django/scipost/tasks.py b/scipost_django/scipost/tasks.py index d84fab4fc..f4c69eb00 100644 --- a/scipost_django/scipost/tasks.py +++ b/scipost_django/scipost/tasks.py @@ -2,12 +2,12 @@ __copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)" __license__ = "AGPL v3" -from django.contrib.sites.models import Site from django.core.mail import send_mail from SciPost_v1.celery import app +from common.utils import get_current_domain -domain = Site.objects.get_current().domain +domain = get_current_domain() @app.task(bind=True) diff --git a/scipost_django/scipost/utils.py b/scipost_django/scipost/utils.py index ea97efa80..daaaf89ca 100644 --- a/scipost_django/scipost/utils.py +++ b/scipost_django/scipost/utils.py @@ -2,9 +2,9 @@ __copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)" __license__ = "AGPL v3" -from django.contrib.sites.models import Site +from common.utils import get_current_domain -domain = Site.objects.get_current().domain +domain = get_current_domain() from common.utils import BaseMailUtil diff --git a/scipost_django/scipost/views.py b/scipost_django/scipost/views.py index 8990cf725..6f1c457b7 100644 --- a/scipost_django/scipost/views.py +++ b/scipost_django/scipost/views.py @@ -21,7 +21,6 @@ from django.contrib.auth.views import ( PasswordResetConfirmView, ) from django.contrib.messages.views import SuccessMessageMixin -from django.contrib.sites.models import Site from django.core import mail from django.core.exceptions import PermissionDenied from django.core.mail import EmailMessage, EmailMultiAlternatives @@ -71,6 +70,7 @@ from commentaries.models import Commentary from commentaries.forms import CommentarySearchForm from comments.models import Comment from comments.forms import CommentSearchForm +from common.utils import get_current_domain from invitations.constants import STATUS_REGISTERED from invitations.models import RegistrationInvitation from journals.models import Journal, Publication, PublicationAuthorsTable @@ -666,7 +666,7 @@ def vet_registration_request_ack(request, contributor_id): form = VetRegistrationForm(request.POST or None) contributor = Contributor.objects.get(pk=contributor_id) if form.is_valid(): - domain = Site.objects.get_current().domain + domain = get_current_domain() if form.promote_to_registered_contributor(): contributor.status = NORMAL_CONTRIBUTOR contributor.vetted_by = request.user.contributor @@ -1619,7 +1619,7 @@ def email_group_members(request): """ form = EmailGroupMembersForm(request.POST or None) if form.is_valid(): - domain = Site.objects.get_current().domain + domain = get_current_domain() group_members = ( form.cleaned_data["group"] .user_set.filter(contributor__isnull=False) @@ -1700,7 +1700,7 @@ def email_particular(request): if request.method == "POST": form = EmailParticularForm(request.POST) if form.is_valid(): - domain = Site.objects.get_current().domain + domain = get_current_domain() email_text = form.cleaned_data["email_text"] email_text_html = "{{ email_text|linebreaks }}" email_context = {"email_text": form.cleaned_data["email_text"]} @@ -1739,7 +1739,7 @@ def send_precooked_email(request): """ form = SendPrecookedEmailForm(request.POST or None) if form.is_valid(): - domain = Site.objects.get_current().domain + domain = get_current_domain() precookedEmail = form.cleaned_data["email_option"] if form.cleaned_data["email_address"] in precookedEmail.emailed_to: errormessage = "This message has already been sent to this address" diff --git a/scipost_django/submissions/utils.py b/scipost_django/submissions/utils.py index d08280ec0..65fc7e3e8 100644 --- a/scipost_django/submissions/utils.py +++ b/scipost_django/submissions/utils.py @@ -4,7 +4,6 @@ __license__ = "AGPL v3" import datetime -from django.contrib.sites.models import Site from django.core.mail import EmailMessage, EmailMultiAlternatives from django.template import Context, Template @@ -17,9 +16,9 @@ from .constants import ( ) from scipost.utils import EMAIL_FOOTER -from common.utils import BaseMailUtil +from common.utils import get_current_domain, BaseMailUtil -domain = Site.objects.get_current().domain +domain = get_current_domain() class SubmissionUtils(BaseMailUtil): diff --git a/scipost_django/submissions/views.py b/scipost_django/submissions/views.py index d252e1d0d..236b71332 100644 --- a/scipost_django/submissions/views.py +++ b/scipost_django/submissions/views.py @@ -20,7 +20,6 @@ from django.contrib.auth.mixins import ( UserPassesTestMixin, ) from django.contrib.messages.views import SuccessMessageMixin -from django.contrib.sites.models import Site from django.core.exceptions import PermissionDenied from django.core.paginator import Paginator from django.db import transaction, IntegrityError @@ -115,7 +114,7 @@ from colleges.permissions import ( ) from comments.forms import CommentForm from common.helpers import get_new_secrets_key -from common.utils import workdays_between +from common.utils import get_current_domain, workdays_between from invitations.constants import STATUS_SENT from invitations.models import RegistrationInvitation from journals.models import Journal, Publication @@ -792,7 +791,7 @@ def report_pdf_compile(request, report_id): messages.success(request, "Upload complete.") return redirect(reverse("submissions:reports_accepted_list")) context = { - "domain": Site.objects.get_current().domain, + "domain": get_current_domain(), "report": report, "form": form, } @@ -828,7 +827,7 @@ def treated_submission_pdf_compile(request, identifier_w_vn_nr): messages.success(request, "Upload complete.") return redirect(reverse("submissions:treated_submissions_list")) context = { - "domain": Site.objects.get_current().domain, + "domain": get_current_domain(), "submission": submission, "form": form, } diff --git a/scipost_django/theses/forms.py b/scipost_django/theses/forms.py index 70ef57f20..83a48f36f 100644 --- a/scipost_django/theses/forms.py +++ b/scipost_django/theses/forms.py @@ -3,7 +3,6 @@ __license__ = "AGPL v3" from django import forms -from django.contrib.sites.models import Site from django.core.mail import EmailMessage from django.template.loader import render_to_string @@ -13,6 +12,7 @@ from crispy_bootstrap5.bootstrap5 import FloatingField from scipost.models import Contributor from scipost.utils import build_absolute_uri_using_site +from common.utils import get_current_domain from .models import ThesisLink from .helpers import past_years @@ -124,7 +124,7 @@ class VetThesisLinkForm(BaseRequestThesisLinkForm): thesislink.delete() - domain = Site.objects.get_current().domain + domain = get_current_domain() email = EmailMessage( subject_line, message_plain, diff --git a/scipost_django/webinars/views.py b/scipost_django/webinars/views.py index 7b4b0dbf2..0e8fc8e9b 100644 --- a/scipost_django/webinars/views.py +++ b/scipost_django/webinars/views.py @@ -3,13 +3,13 @@ __license__ = "AGPL v3" from django.contrib import messages -from django.contrib.sites.models import Site from django.shortcuts import get_object_or_404, redirect, render from django.urls import reverse from .models import Webinar from .forms import WebinarRegistrationForm +from common.utils import get_current_domain from mails.utils import DirectMailUtil @@ -44,7 +44,7 @@ def webinar_register(request, slug): "webinars/webinar_registration_ack", delayed_processing=False, bcc=[ - "admin@{domain}".format(domain=Site.objects.get_current().domain), + "admin@{domain}".format(domain=get_current_domain()), ], registration=registration, ) -- GitLab