scott2b / django-multimail Goto Github PK
View Code? Open in Web Editor NEWMultiple verified e-mail accounts per user for Django
License: MIT License
Multiple verified e-mail accounts per user for Django
License: MIT License
Multimail seems to be incompatible with Django 1.4+ due to the use of the deprecated user.message_set (models, line #116). See deprecation notes for 1.4: https://docs.djangoproject.com/en/dev/internals/deprecation/. Note that it seems like it may no longer be possible to create messages outside the context of the request cycle as we are doing here.
class EmailAddress(models.Model):
…
email = models.EmailField(max_length=100, unique=True)
But then:
try:
addr = EmailAddress.objects.get(user=user,email=user.email)
# Provides that an address that has been just verified
# without use of django-multimail, is still considered
# verified in conditions of django-multimail
if user.is_active and not addr.verified_at:
addr.verified_at = now()
except EmailAddress.DoesNotExist:
addr = EmailAddress()
addr.user = user
addr.email = user.email
addr.save(verify=False)
The search you do is for user X and e-mail Y. If there's user Z with e-mail Y, you find 0 results, then you try to add (X,Y) which fails due to uniqueness (Y already exists).
I think: before creating a new one (X,Y), you should .filter(email=user.email) to see whether that e-mail (*,Y) already exists.
Just before the code I posted there's another piece of code that needs the same change.
Create an admin.py and register the EmailAddress in the admin panel for easier maintenance.
try:
USER_MODEL = settings.AUTH_USER_MODEL
except AttributeError: # handle Django 1.4
from django.contrib.auth.models import User
USER_MODEL = User
The signals of post_save don't get called when I leave this settings as is (inside models.py)
Though if I delete it all and use only this:
from django.contrib.auth.models import User
USER_MODEL = User
Then, the post_save signal gets caught and the mail_handler works.
I don't understand why is this happening..
Thanks a lot for your help!
set_as_primary checks if the email is not verified and adds an error message, however it still allows the un-verified email to be set as the primary one.
/usr/local/lib/virt_env/lib/python2.7/site-packages/multimail/models.py:27: RemovedInDjango19Warning: Model class multimail.models.EmailAddress doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
class EmailAddress(models.Model):
This ticket explains some of the issue, simple fix, just need to put an app label on the EmailAddress model, will submit a merge request in a bit.
https://code.djangoproject.com/ticket/21719
Is this project dead or not? I didn't found any other solution for this problem. And I wasn't able to get this on Django 1.11. I'm getting exception "Apps aren't loaded yet." when multimail is importing django.contrib.sites.model in util.py file on line 2.
Any idea? Any similar project for newer version of Django?
I'm using this in a project where we assign users an initial account and do not want to allow them to change their primary address. I'm going to submit a merge request with a feature that would disallow that, e.g. an option of MM_DISABLE_CHANGE_PRIMARY_ADDRESS.
Hi,
Great work on a really useful Django package.
I have one request really and that is to make the sending of emails to admins optional via the settings file. I find myself creating users and modifying them in the backend and constantly receiving emails.
Other than that, thanks for the great work!
Cheers,
Aksel
Currently, an EmailAddress is unique_together with the user associated with the address. I don't recall the use case for taking this approach. It seems like it would be better for email addresses to be unique overall.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.