forked from enviPath/enviPy
Compare commits
12 Commits
170f00504f
...
2e24666744
| Author | SHA1 | Date | |
|---|---|---|---|
| 2e24666744 | |||
| d9c8c9746d | |||
| d668315064 | |||
| 05a17ecdcf | |||
| 2bdedc39ee | |||
| c9564a3dca | |||
| 512b51137f | |||
| 5750257cfb | |||
| 0bad0eb087 | |||
| c01ad663b7 | |||
| f1936eea8f | |||
| 624acccb3e |
112
epdb/admin.py
112
epdb/admin.py
@ -1,8 +1,5 @@
|
|||||||
import logging
|
|
||||||
|
|
||||||
from django.conf import settings as s
|
from django.conf import settings as s
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.contrib import messages
|
|
||||||
|
|
||||||
from .models import (
|
from .models import (
|
||||||
AdditionalInformation,
|
AdditionalInformation,
|
||||||
@ -32,8 +29,6 @@ from .models import (
|
|||||||
|
|
||||||
Package = s.GET_PACKAGE_MODEL()
|
Package = s.GET_PACKAGE_MODEL()
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class AdditionalInformationAdmin(admin.ModelAdmin):
|
class AdditionalInformationAdmin(admin.ModelAdmin):
|
||||||
pass
|
pass
|
||||||
@ -50,113 +45,6 @@ class UserAdmin(admin.ModelAdmin):
|
|||||||
"date_joined",
|
"date_joined",
|
||||||
]
|
]
|
||||||
|
|
||||||
actions = ["send_welcome_mail", "send_affiliation_mail"]
|
|
||||||
|
|
||||||
@admin.action(description="Send welcome mail")
|
|
||||||
def send_welcome_mail(self, request, queryset):
|
|
||||||
from django.core.mail import EmailMultiAlternatives
|
|
||||||
|
|
||||||
tpl = """Hello {username},
|
|
||||||
|
|
||||||
Your account has been successfully activated.
|
|
||||||
|
|
||||||
To log in, please visit
|
|
||||||
https://envipath.org/password_reset/
|
|
||||||
and request a new password.
|
|
||||||
|
|
||||||
If you have any questions or feedback, feel free to visit our community forum at
|
|
||||||
https://community.envipath.org/.
|
|
||||||
You do not need to register again for the forum - you can log in using your enviPath account by clicking "Log In" and then "Log in with enviPath."
|
|
||||||
|
|
||||||
Best regards,
|
|
||||||
|
|
||||||
The enviPath Team"""
|
|
||||||
|
|
||||||
users = []
|
|
||||||
|
|
||||||
for user in queryset:
|
|
||||||
if user.is_active:
|
|
||||||
logger.info(f"{user.username} already active - not sending mail again")
|
|
||||||
continue
|
|
||||||
try:
|
|
||||||
msg = EmailMultiAlternatives(
|
|
||||||
"Your enviPath Account Is Now Active",
|
|
||||||
tpl.format(username=user.username),
|
|
||||||
"admin@envipath.org",
|
|
||||||
[user.email],
|
|
||||||
bcc=["admin@envipath.org"],
|
|
||||||
)
|
|
||||||
|
|
||||||
msg.send(fail_silently=False)
|
|
||||||
|
|
||||||
user.is_active = True
|
|
||||||
user.password = "ASDF"
|
|
||||||
user.save()
|
|
||||||
|
|
||||||
users.append(user)
|
|
||||||
logger.info(f"{user.username} -> {user.email} mail sent")
|
|
||||||
except Exception as e:
|
|
||||||
logger.info(f"Error sending mail to {user.username}: {e}")
|
|
||||||
|
|
||||||
self.message_user(
|
|
||||||
request, f"Sent welcome mail to {[u.email for u in users]}", messages.SUCCESS
|
|
||||||
)
|
|
||||||
|
|
||||||
@admin.action(description="Send affiliation mail")
|
|
||||||
def send_affiliation_mail(self, request, queryset):
|
|
||||||
from django.core.mail import EmailMultiAlternatives
|
|
||||||
|
|
||||||
tpl = """Dear {username},
|
|
||||||
|
|
||||||
Thank you for your interest in enviPath!
|
|
||||||
|
|
||||||
Please note that the public enviPath system is intended for non-commercial use only.
|
|
||||||
We see that you registered using the email address {email}.
|
|
||||||
If possible, we kindly ask you to register using an official email address that reflects your affiliation (e.g., a university, NGO, or research organization).
|
|
||||||
|
|
||||||
If you would like us to update your account, simply reply to this email and let us know which address we should use.
|
|
||||||
We will then change it in our system, and you will receive a password reset email at the new address.
|
|
||||||
|
|
||||||
If you are registering with a company email address and are interested in commercial use, you are very welcome to book a meeting with us so we can discuss how we can best support you.
|
|
||||||
To book a meeting, please visit https://envipath.com/book
|
|
||||||
|
|
||||||
If changing to an affiliation email address is not possible, please contact us at registration@envipath.org
|
|
||||||
|
|
||||||
Best regards,
|
|
||||||
|
|
||||||
enviPath team"""
|
|
||||||
|
|
||||||
users = []
|
|
||||||
|
|
||||||
for user in queryset:
|
|
||||||
if user.is_active or user.contacted:
|
|
||||||
logger.info(
|
|
||||||
f"{user.username} already active or already contacted - not sending mail again"
|
|
||||||
)
|
|
||||||
continue
|
|
||||||
try:
|
|
||||||
msg = EmailMultiAlternatives(
|
|
||||||
"Regarding your enviPath registration",
|
|
||||||
tpl.format(username=user.username, email=user.email),
|
|
||||||
"admin@envipath.org",
|
|
||||||
[user.email],
|
|
||||||
bcc=["admin@envipath.org"],
|
|
||||||
)
|
|
||||||
|
|
||||||
msg.send(fail_silently=False)
|
|
||||||
|
|
||||||
user.contacted = True
|
|
||||||
user.save()
|
|
||||||
|
|
||||||
users.append(user)
|
|
||||||
logger.info(f"{user.username} -> {user.email} affiliation mail sent")
|
|
||||||
except Exception as e:
|
|
||||||
logger.info(f"Error sending mail to {user.username}: {e}")
|
|
||||||
|
|
||||||
self.message_user(
|
|
||||||
request, f"Sent affiliation mail to {[u.email for u in users]}", messages.SUCCESS
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class UserPackagePermissionAdmin(admin.ModelAdmin):
|
class UserPackagePermissionAdmin(admin.ModelAdmin):
|
||||||
pass
|
pass
|
||||||
|
|||||||
@ -1,17 +0,0 @@
|
|||||||
# Generated by Django 6.0.3 on 2026-04-21 19:56
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
dependencies = [
|
|
||||||
("epdb", "0023_alter_compoundstructure_options_and_more"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name="user",
|
|
||||||
name="contacted",
|
|
||||||
field=models.BooleanField(blank=True, null=True),
|
|
||||||
),
|
|
||||||
]
|
|
||||||
@ -75,7 +75,6 @@ class User(AbstractUser):
|
|||||||
blank=False,
|
blank=False,
|
||||||
)
|
)
|
||||||
is_reviewer = models.BooleanField(default=False)
|
is_reviewer = models.BooleanField(default=False)
|
||||||
contacted = models.BooleanField(null=True, blank=True)
|
|
||||||
|
|
||||||
USERNAME_FIELD = "email"
|
USERNAME_FIELD = "email"
|
||||||
REQUIRED_FIELDS = ["username"]
|
REQUIRED_FIELDS = ["username"]
|
||||||
|
|||||||
Reference in New Issue
Block a user