Skip to content
This repository has been archived by the owner on Aug 23, 2020. It is now read-only.

Signals #49

Open
danmir opened this issue Sep 10, 2015 · 8 comments
Open

Signals #49

danmir opened this issue Sep 10, 2015 · 8 comments

Comments

@danmir
Copy link

danmir commented Sep 10, 2015

Hello. I'm trying to send email on user_registered signal to get full information about this user. I made signals.py file with the following code (as in official django docs on signals):

from registration.signals import user_registered
from django.dispatch import receiver
from django.core.mail import send_mail

@receiver(user_registered)
def user_registered_callback(sender, **kwargs):
    raise Exception(kwargs)
    msg = "User: {} User email: {} User google id {} ".format(kwargs["user"], kwargs["user"]['email1'],
                                                             kwargs["profile"]["google_plus_acc_num"])
    msg += kwargs
    send_mail('New mm user', msg, 'email_from',
              ['email_to'], fail_silently=False)

Lately I have added raise Exception(kwargs) to see if smth. happens or not.
Unfortunately nothing happens nor Exception neither sending email.
Did I made a mistake using your library ?
Thanks.

@lambdalisue
Copy link
Owner

does signal.py called? usually signal related codes are writen in model.py or called from model.py

@lambdalisue
Copy link
Owner

add 's'. signals.py nd models.py

@danmir
Copy link
Author

danmir commented Sep 10, 2015

Thanks again for your help. Wrote signal's code at models.py - all works great.
Also is there any possibilities to get additional fields (suplement model) at the user_registered signal ?
I have listed all fields from user and profile

['DoesNotExist', 'Meta', 'MultipleObjectsReturned', 'REQUIRED_FIELDS', 'USERNAME_FIELD', '__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__format__', '__getattribute__', '__hash__', '__init__', u'__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__unicode__', '__weakref__', '_base_manager', '_check_column_name_clashes', '_check_field_name_clashes', '_check_fields', '_check_id_field', '_check_index_together', '_check_local_fields', '_check_long_column_names', '_check_m2m_through_same_relationship', '_check_managers', '_check_model', '_check_ordering', '_check_swappable', '_check_unique_together', '_default_manager', '_deferred', '_do_insert', '_do_update', '_get_FIELD_display', '_get_next_or_previous_by_FIELD', '_get_next_or_previous_in_order', '_get_pk_val', '_get_unique_checks', '_meta', '_perform_date_checks', '_perform_unique_checks', '_registration_profile_cache', '_save_parents', '_save_table', '_set_pk_val', '_state', 'check', 'check_password', 'clean', 'clean_fields', 'date_error_message', 'date_joined', 'delete', 'email', 'email_user', 'first_name', 'from_db', 'full_clean', 'get_all_permissions', 'get_deferred_fields', 'get_full_name', 'get_group_permissions', 'get_next_by_date_joined', 'get_previous_by_date_joined', 'get_session_auth_hash', 'get_short_name', 'get_username', 'groups', 'has_module_perms', 'has_perm', 'has_perms', 'has_usable_password', 'id', 'is_active', 'is_anonymous', 'is_authenticated', 'is_staff', 'is_superuser', 'last_login', 'last_name', 'logentry_set', 'natural_key', 'objects', 'password', 'pk', 'prepare_database_save', 'refresh_from_db', 'registration_profile', 'save', 'save_base', 'serializable_value', 'set_password', 'set_unusable_password', 'unique_error_message', 'user_permissions', 'username', 'validate_unique']

And

['DoesNotExist', 'MultipleObjectsReturned', 'STATUS_LIST', '__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__format__', '__getattribute__', '__hash__', '__init__', u'__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__supplementtut_myregistrationsupplement_supplement_cache', '__unicode__', '__weakref__', '_base_manager', '_check_column_name_clashes', '_check_field_name_clashes', '_check_fields', '_check_id_field', '_check_index_together', '_check_local_fields', '_check_long_column_names', '_check_m2m_through_same_relationship', '_check_managers', '_check_model', '_check_ordering', '_check_swappable', '_check_unique_together', '_default_manager', '_deferred', '_do_insert', '_do_update', '_get_FIELD_display', '_get_next_or_previous_by_FIELD', '_get_next_or_previous_in_order', '_get_pk_val', '_get_status', '_get_supplement', '_get_supplement_class', '_get_unique_checks', '_meta', '_perform_date_checks', '_perform_unique_checks', '_registration_defaultregistrationsupplement_supplement', '_save_parents', '_save_table', '_send_email', '_set_pk_val', '_set_status', '_state', '_status', '_supplementtut_myregistrationsupplement_supplement', '_user_cache', 'activation_key', 'activation_key_expired', 'check', 'clean', 'clean_fields', 'date_error_message', 'delete', 'from_db', 'full_clean', 'get__status_display', 'get_deferred_fields', 'get_status_display', 'id', 'objects', 'pk', 'prepare_database_save', 'refresh_from_db', 'save', 'save_base', 'send_acceptance_email', 'send_activation_email', 'send_registration_email', 'send_rejection_email', 'serializable_value', 'status', 'supplement', 'supplement_class', 'unique_error_message', 'user', 'user_id', 'validate_unique']

Nor supplement neither supplement_class don't have information about additional fields from registration form

@lambdalisue
Copy link
Owner

hum, it looks a bug. you may need to get supplement from DB while the instance does not have it when signal is called. i'll try to fix it but if you are in rush, get it from db with profile _pk.

@lambdalisue
Copy link
Owner

Well, it looks working.
https://github.com/lambdalisue/django-inspectional-registration/compare/fix/issue49#diff-2f7bbcc43d8f44a93ca21d4758b5e381R249

How did you access to the supplemental information?

@danmir
Copy link
Author

danmir commented Sep 20, 2015

I made a request to my db knowing the profile_id from profile object inside user_registered signal

@lambdalisue
Copy link
Owner

What happen if you use the following code (I assumed that your supplement class
has remarks field.)

from registration.signals import user_registered
from django.dispatch import receiver
from django.core.mail import send_mail

@receiver(user_registered)
def user_registered_callback(sender, user, profile, **kwargs):
    raise Exception("Supplement remarks: %s" % profile.supplement.remarks)

@lambdalisue
Copy link
Owner

ping @danmir

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants