def resolve_full_url_with_subdmain( schema_name, reverse_url_id, resolve_url_args): #TODO: Write Unit Tests for this. """ Enhanced "reverse" function which will include the HTTP PROTOCAL and HTTP DOMAIN for the reversed link with subdomain """ url = env_var('SMEGURUS_APP_HTTP_PROTOCOL') url += schema_name + "." url += env_var('SMEGURUS_APP_HTTP_DOMAIN') url += reverse(reverse_url_id, args=resolve_url_args) url = url.replace("None", "en") return url
def send_activation(self, email): """Function will send to the inputted email the URL that needs to be accessed to activate the account.""" contact_list = [env_var('DEFAULT_TO_EMAIL')] name = "Test Name" subject = "Den Activation" message = "To activate your account, please click this url: " + self.activation_url( email) #TODO: Replace w/ resolve_full_url_with_subdmain send_mail(subject, message, env_var('DEFAULT_FROM_EMAIL'), contact_list, fail_silently=False)
def send_notification(self, calendar_event): # Iterate through all the participants in the CalendarEvent and get their # email only if they request email notification for taks. contact_list = [] for me in calendar_event.pending.all(): if me.notify_when_task_had_an_interaction: contact_list.append(me.owner.email) # Generate the data. subject = "Pending Event #" + str(calendar_event.id) param = { 'user': self.request.user, 'calendar_event': calendar_event, 'url': self.get_calendar_event_url( calendar_event ), #TODO: Replace w/ resolve_full_url_with_subdmain 'web_view_url': self.get_web_view( calendar_event ), #TODO: Replace w/ resolve_full_url_with_subdmain } # Plug-in the data into our templates and render the data. text_content = render_to_string('tenant_calendar/pending_invite.html', param) html_content = render_to_string('tenant_calendar/pending_invite.html', param) # Generate our address. from_email = env_var('DEFAULT_FROM_EMAIL') to = contact_list # Send the email. msg = EmailMultiAlternatives(subject, text_content, from_email, to) msg.attach_alternative(html_content, "text/html") msg.send()
def send_pending_document_review_notification(self, document): """ Function will send a "Pending Document Review" email to the Documents assigned Advisor. """ # Fetch the original administrator for this Organization. org_admin_user = User.objects.filter( groups__id=constants.ORGANIZATION_ADMIN_GROUP_ID).earliest( 'date_joined') # Iterate through all owners of this document and generate the contact # list for all the Advisors for each Entrepreneur. contact_list = [] for me in document.workspace.mes.all(): # If this User profile has an assigned manager then add this person # to the email else just email the administrator. if me.managed_by: contact_list.append(me.managed_by.owner.email) else: contact_list.append(org_admin_user.email) # Assign the original admininistrator User to this unmanaged user. me.managed_by = Me.objects.get(owner=org_admin_user) me.save() # Generate the data. url = resolve_full_url_with_subdmain(self.request.tenant.schema_name, 'tenant_review_detail', [ document.id, ]) web_view_extra_url = resolve_full_url_with_subdmain( self.request.tenant.schema_name, 'foundation_email_pending_document', [ document.id, ]) subject = "Pending Document Review" param = { 'user': self.request.user, 'document': document, 'url': url, 'web_view_url': web_view_extra_url, } # Plug-in the data into our templates and render the data. text_content = render_to_string('tenant_review/pending_doc_review.txt', param) html_content = render_to_string( 'tenant_review/pending_doc_review.html', param) # Generate our address. from_email = env_var('DEFAULT_FROM_EMAIL') to = contact_list # Send the email. msg = EmailMultiAlternatives(subject, text_content, from_email, to) msg.attach_alternative(html_content, "text/html") msg.send()
def handle(self, *args, **options): # First call; current site fetched from database. from django.contrib.sites.models import Site # https://docs.djangoproject.com/en/dev/ref/contrib/sites/#caching-the-current-site-object current_site = Site.objects.get_current() current_site.domain = env_var('SMEGURUS_APP_HTTP_DOMAIN') current_site.save() self.stdout.write( self.style.SUCCESS(_('Successfully updated site object.')))
def begin_processing(self, postal_address): # https://developers.google.com/maps/documentation/geocoding/start#reverse gmaps = googlemaps.Client(key=env_var('GOOGLE_MAPS_API_KEY')) # Geocoding an address geocode_result = gmaps.geocode(str(postal_address)) for geo_data in geocode_result: # Extract the data. postal_address.longitude = geo_data['geometry']['location']['lng'] postal_address.latitude = geo_data['geometry']['location']['lat'] # Save the longitude and latitude. postal_address.save()
def handle(self, *args, **options): #create your public tenant public_tenant = PublicOrganization( schema_name='public', name='SMEGurus', paid_until='2016-12-05', on_trial=False, has_perks=False, has_mentors=False, how_many_served=1, ) try: # print("Creating Public") public_tenant.save() except Exception as e: print(e) # Add one or more domains for the tenant domain = PublicDomain() domain.domain = env_var('SMEGURUS_APP_HTTP_DOMAIN') # don't add your port or www here! on a local server you'll want to use localhost here domain.tenant = public_tenant domain.is_primary = True try: # print("Creating Public Domain") domain.save() except Exception as e: print(e) self.stdout.write( self.style.SUCCESS(_('Successfully setup public database.')) ) # First call; current site fetched from database. from django.contrib.sites.models import Site # https://docs.djangoproject.com/en/dev/ref/contrib/sites/#caching-the-current-site-object current_site = Site.objects.get_current() current_site.domain = env_var('SMEGURUS_APP_HTTP_DOMAIN') current_site.save()
def begin_processing(self, user): # Convert our User's ID into an encrypted value. # Note: https://docs.djangoproject.com/en/dev/topics/signing/ signer = Signer() id_sting = str(user.id).encode() value = signer.sign(id_sting) # Variables used to generate your output. url = settings.SMEGURUS_APP_HTTP_PROTOCOL + '%s' % settings.SMEGURUS_APP_HTTP_DOMAIN + '/en/password_reset/' + value + '/' subject_text = 'Account Password Reset' html_text = _( 'Click the following link to reset your password: %(url)s') % { 'url': str(url) } # Send the email. send_mail(subject_text, html_text, env_var('DEFAULT_FROM_EMAIL'), [user.email], fail_silently=False)
def send_notification(self, message): # Generate the data. subject = "New Message" param = { 'user': self.request.user, 'message': message, 'url': self.get_message_url(message), #TODO: Replace w/ resolve_full_url_with_subdmain 'web_view_url': self.get_web_view(message), #TODO: Replace w/ resolve_full_url_with_subdmain } # Plug-in the data into our templates and render the data. text_content = render_to_string('tenant_message/message.txt', param) html_content = render_to_string('tenant_message/message.html', param) # Generate our address. from_email = env_var('DEFAULT_FROM_EMAIL') to = [message.recipient.owner.email,] # Send the email. msg = EmailMultiAlternatives(subject, text_content, from_email, to) msg.attach_alternative(html_content, "text/html") msg.send()
def send_intake_was_rejected(self, intake): # Generate the data. subject = "Application Reviewed: Rejected" web_view_url = reverse('foundation_email_rejected_intake', args=[intake.id]) param = { 'user': intake.me.owner, 'intake': intake, 'url': self.get_login_url(), #TODO: Replace w/ resolve_full_url_with_subdmain 'web_view_url': self.get_url_with_subdomain(web_view_url), #TODO: Replace w/ resolve_full_url_with_subdmain } # Plug-in the data into our templates and render the data. text_content = render_to_string('tenant_intake/rejected_intake.txt', param) html_content = render_to_string('tenant_intake/rejected_intake.html', param) # Generate our address. from_email = env_var('DEFAULT_FROM_EMAIL') to = [intake.me.owner.email,] # Send the email. msg = EmailMultiAlternatives(subject, text_content, from_email, to) msg.attach_alternative(html_content, "text/html") msg.send()
def send_entrepreneur_activation(self, user): # Generate the data. subject = 'Account Activation - SME Gurus' param = { 'user': user, 'url': self.get_activation_url( user ), # Generate our activation URL. #TODO: Replace w/ resolve_full_url_with_subdmain } # Plug-in the data into our templates and render the data. text_content = render_to_string( 'foundation_auth/activate_entrepreneur.txt', param) html_content = render_to_string( 'foundation_auth/activate_entrepreneur.html', param) # Generate our address. from_email = env_var('DEFAULT_FROM_EMAIL') to = user.email # Send the email. msg = EmailMultiAlternatives(subject, text_content, from_email, [to]) msg.attach_alternative(html_content, "text/html") msg.send()
def begin_processing(self, me): #-----------------------------# # Expel our User. # #-----------------------------# me.is_in_intake = False me.save() #-----------------------------# # Send a notification email. # #-----------------------------# # Variables used to generate your output. url = settings.SMEGURUS_APP_HTTP_PROTOCOL + '%s' % settings.SMEGURUS_APP_HTTP_DOMAIN + '/en/login/' subject_text = 'You are enrolled!' html_text = _( 'Congradulations you have been enrolled! Click the link to get started: %(url)s' ) % { 'url': str(url) } # Send the email. send_mail(subject_text, html_text, env_var('DEFAULT_FROM_EMAIL'), [me.owner.email], fail_silently=False)
def send_intake_is_pending(self, intake, contact_list): """Function will send pending new intake needs to be reviewed email.""" # Generate the data. subject = "New Entrepreneur Application!" url = reverse('tenant_intake_employee_pending_details', args=[intake.id]) web_view_url = reverse('foundation_email_pending_intake', args=[intake.id]) param = { 'user': intake.me.owner, 'url': self.get_url_with_subdomain(url), #TODO: Replace w/ resolve_full_url_with_subdmain 'intake': intake, 'web_view_url': self.get_url_with_subdomain(web_view_url), #TODO: Replace w/ resolve_full_url_with_subdmain } # Plug-in the data into our templates and render the data. text_content = render_to_string('tenant_intake/pending_intake.txt', param) html_content = render_to_string('tenant_intake/pending_intake.html', param) # Generate our address. from_email = env_var('DEFAULT_FROM_EMAIL') # Send the email. msg = EmailMultiAlternatives(subject, text_content, from_email, contact_list) msg.attach_alternative(html_content, "text/html") msg.send()
def get_s3_url(self): return "https://" + env_var('AWS_STORAGE_BUCKET_NAME') + ".s3.amazonaws.com/media/"+str(self.datafile)