Ejemplo n.º 1
0
 def save(self):
     "save contact forms"
     fromEmail = self.cleaned_data['email']
     toEmail = self.cleaned_data['toEmail']
     subject = self.cleaned_data['subject']
     content = self.cleaned_data['content']
     getLogger().info("Got contact from %s, to = %s, content : %s" % (`fromEmail`, `toEmail`, `content`) )
     from django.core.mail import send_mail
     send_mail(subject, content, fromEmail, [toEmail])
Ejemplo n.º 2
0
 def save(self):
     "save feedback forms"
     email = self.cleaned_data['email']
     type = int(self.cleaned_data['type'])
     content = self.cleaned_data['content']
     getLogger().info("Got feedback from %s, type = %s, content : %s" % (`email`, `type`, `content`) )
     print len(getChoiceValue(FEEDBACK_TYPE_CHOICES, type))
     subject = "[%s] from '%s'" % (getChoiceValue(FEEDBACK_TYPE_CHOICES, type), email)
     from django.core.mail import mail_admins
     mail_admins(subject, content, fail_silently=False)
Ejemplo n.º 3
0
    def create_inactive_user(self, username, password, email,research_field = "NONE", is_supplier = False,
                             send_email=True, profile_callback=None):
        """
        Create a new, inactive ``User``, generates a
        ``RegistrationProfile`` and email its activation key to the
        ``User``, returning the new ``User``.
        
        To disable the email, call with ``send_email=False``.
        
        To enable creation of a custom user profile along with the
        ``User`` (e.g., the model specified in the
        ``AUTH_PROFILE_MODULE`` setting), define a function which
        knows how to create and save an instance of that model with
        appropriate default values, and pass it as the keyword
        argument ``profile_callback``. This function should accept one
        keyword argument:

        ``user``
            The ``User`` to relate the profile to.
        
        """
        new_user = User.objects.create_user(username, email, password)
        new_user.is_active = False
        new_user.save()
        
        registration_profile = self.create_profile(new_user)
        
        if profile_callback is not None:
            profile_callback(user=new_user, research_field = research_field, is_supplier = is_supplier)
        
        if send_email:
            from django.core.mail import send_mail
            current_site = Site.objects.get_current()
            
            subject = render_to_string('registration/activation_email_subject.txt',
                                       { 'site': current_site ,
                                        'username' : username})
            # Email subject *must not* contain newlines
            subject = ''.join(subject.splitlines())

            
            message = render_to_string('registration/activation_email.txt',
                                       { 'activation_key': registration_profile.activation_key,
                                         'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS,
                                         'site': current_site,
                                         'username' :username })
            getLogger().info("Sending email to %s " % str((subject, message, settings.DEFAULT_FROM_EMAIL, new_user.email)) )
            send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [new_user.email])
            getLogger().info("Email sent")
            
        return new_user