def send_notification_email_after_issue_submission_approval( sender, issue_submission, transition_name, request, **kwargs): if not issue_submission.is_validated: return emails = [ issue_submission.contact.email, ] extra_context = { 'issue': issue_submission, 'journal': issue_submission.journal } comment = issue_submission.status_tracks.last().comment if comment: extra_context['comment'] = comment email = Email( emails, from_email=settings.PUBLISHER_EMAIL, html_template='emails/editor/issue_submission_validated_content.html', subject_template= 'emails/editor/issue_submission_validated_subject.html', extra_context=extra_context) email.send()
def main(): # Setup Logging Logging.EnableLogger() Logging.SetFile(filename="stock_analysis_cron_main") Logging.DEBUG("Entering cron main.") with Database("../stocks.db") as db: Logging.DEBUG("Opened stock database successfully.") analysisObj = SecurityManager(db) # First update the stock table analysisObj.updateStocks() Logging.DEBUG("Succesfully updated tracked stocks.") # Now email the updated table to interested recipients # TODO: Deprectate this at some point as it is not useful to anyone really. email = Email() email.setSubject("Periodic Update from Stock Tracker Personal Project") email.addTextMessage( "Here is your wonderful update. The list of tracked stocks was recently updated." "Below you will find the most up to date info on the tracked stocks. Amazing." ) email.addHTMLMessage(analysisObj.getHTMLTable()) email.sendMessage()
def send_notification_email(self, token): email = Email( [token.email, ], html_template='emails/subscription/journal/new_subscription_content.html', subject_template='emails/subscription/journal/new_subscription_subject.html', extra_context={'token': token}) email.send()
def send_notification_email(self, token): email = Email( [token.email, ], html_template='emails/organisation/new_member_content.html', subject_template='emails/organisation/new_member_subject.html', extra_context={'token': token}) email.send()
def send_mail(self, subject_template_name, email_template_name, context, from_email, to_email, **kwargs): """ Overrides the builtin `PasswordResetForm.send_mail` method to use the `core.email.Email` tool. """ email = Email( to_email, html_template=email_template_name, subject_template=subject_template_name, extra_context=context ) email.send()
def send_mail(self, subject_template_name, email_template_name, context, from_email, to_email, **kwargs): """ Overrides the builtin `PasswordResetForm.send_mail` method to use the `core.email.Email` tool. """ email = Email(to_email, html_template=email_template_name, subject_template=subject_template_name, extra_context=context) email.send()
def send_notification_email(self, token): email = Email( [ token.email, ], html_template= 'emails/subscription/journal/new_subscription_content.html', subject_template= 'emails/subscription/journal/new_subscription_subject.html', extra_context={'token': token}) email.send()
def create_ticket(self, ticket_type, owner=None, **extra_fields): """Creates and saves a new ticket.""" if not ticket_type: raise ValueError('Enter a ticket type.') if ticket_type.tickets_remaining < 1: raise ValueError('Insufficient tickets remaining.') promoter = ticket_type.event.promoter if owner is not None: issuer = owner else: issuer = promoter if ticket_type.price > issuer.credit: raise ValueError('Insufficient credit.') ticket_type.tickets_remaining -= 1 issuer.credit = issuer.credit - ticket_type.price if owner is not None: promoter.credit = promoter.credit + ticket_type.price ticket = Ticket.objects.create(ticket_type=ticket_type, owner=issuer, **extra_fields) ticket_type.save(using=self._db) ticket.save(using=self._db) issuer.save(using=self._db) ticket.code = create_code(ticket.pk, 6) ticket.save(using=self._db) if owner is not None: promoter.save(using=self._db) if not owner.is_promoter: dynamic_template_data = {'code': ticket.code} Email('ticket', owner.email, dynamic_template_data).send() return ticket
def send_production_team_email(sender, issue_submission, transition_name, request, **kwargs): if not issue_submission.is_submitted: return production_team_group = get_production_team_group(issue_submission.journal) if production_team_group is None: return emails = list(production_team_group.user_set.values_list('email', flat=True)) if not emails: return email = Email( emails, html_template='emails/editor/new_issue_submission_content.html', subject_template='emails/editor/new_issue_submission_subject.html', extra_context={'issue': issue_submission}) email.send()
def send_production_team_email(sender, instance, name, source, target, **kwargs): if not instance.is_submitted: return production_team = get_production_team_group() if production_team is None: return emails = production_team.user_set.values_list('email', flat=True) if not emails: return email = Email( emails, html_template='userspace/journal/editor/emails/new_issue_submission_content.html', subject_template='userspace/journal/editor/emails/new_issue_submission_subject.html', extra_context={'issue': instance}) email.send()
def _handle_issuesubmission_files_removal(): now_dt = tz.now() # First, fetches the issue submissions whose files must be deleted. for issue in IssueSubmission.objects.archived_expired(): for fversion in issue.files_versions.all(): [rf.delete() for rf in fversion.submissions.all()] issue.archived = True issue.save() # Fetches the production team group production_team = get_production_team_group() if production_team is None: logger.error( """Cannot send issue submission removal notification email. There is NO production team """) return # Now fetches the issue submissions that will soon be deleted. The production team must be # informed that the deletion will occur in a few days. email_limit_dt = now_dt - dt.timedelta( days=editor_settings.ARCHIVE_DAY_OFFSET - 5) email_limit_dt_range = [ email_limit_dt.replace(hour=0, minute=0, second=0, microsecond=0), email_limit_dt.replace(hour=23, minute=59, second=59, microsecond=999999), ] issue_submissions_to_email = IssueSubmission.objects.filter( status=IssueSubmission.VALID, date_modified__range=email_limit_dt_range) if issue_submissions_to_email.exists(): emails = production_team.user_set.values_list('email', flat=True) if not emails: return email = Email( list(emails), html_template='emails/editor/issue_files_deletion_content.html', subject_template='emails/editor/issue_files_deletion_subject.html', extra_context={'issue_submissions': issue_submissions_to_email}) email.send()
def send_notification_email_after_issue_submission_refusal( sender, issue_submission, transition_name, request, **kwargs): if not issue_submission.is_draft: return extra_context = {'issue': issue_submission} emails = [issue_submission.contact.email, ] comment = issue_submission.status_tracks.last().comment if comment: extra_context['comment'] = comment email = Email( emails, from_email=settings.PUBLISHER_EMAIL, html_template='emails/editor/issue_submission_refused_content.html', subject_template='emails/editor/issue_submission_refused_subject.html', extra_context=extra_context) email.send()
def _handle_issuesubmission_files_removal(): now_dt = tz.now() # First, fetches the issue submissions whose files must be deleted. deletion_limit_dt = now_dt - dt.timedelta(days=editor_settings.ARCHIVE_DAY_OFFSET) deletion_limit_dt_range = [ deletion_limit_dt.replace(hour=0, minute=0, second=0, microsecond=0), deletion_limit_dt.replace(hour=23, minute=59, second=59, microsecond=999999), ] issue_submissions_to_remove = IssueSubmission.objects.filter( status=IssueSubmission.VALID, date_modified__range=deletion_limit_dt_range) for issue in issue_submissions_to_remove: for fversion in issue.files_versions.all(): [rf.delete() for rf in fversion.submissions.all()] issue.archived = True issue.save() # Fetches the production team group production_team = get_production_team_group() if production_team is None: return # Now fetches the issue submissions that will soon be deleted. The production team must be # informed that the deletion will occur in a few days. email_limit_dt = now_dt - dt.timedelta(days=editor_settings.ARCHIVE_DAY_OFFSET - 5) email_limit_dt_range = [ email_limit_dt.replace(hour=0, minute=0, second=0, microsecond=0), email_limit_dt.replace(hour=23, minute=59, second=59, microsecond=999999), ] issue_submissions_to_email = IssueSubmission.objects.filter( status=IssueSubmission.VALID, date_modified__range=email_limit_dt_range) if issue_submissions_to_email.exists(): emails = production_team.user_set.values_list('email', flat=True) if not emails: return email = Email( list(emails), html_template='emails/editor/issue_files_deletion_content.html', subject_template='emails/editor/issue_files_deletion_subject.html', extra_context={'issue_submissions': issue_submissions_to_email}) email.send()
def create_user(self, email, password, name, **extra_fields): """Creates and saves a new user.""" signup_check(email, name, password) user = self.model(email=self.normalize_email(email), name=name, **extra_fields) user.set_password(password) user.slug = slugify(name) user.save(using=self._db) Email('welcome_user', user.email).send() return user
def send_production_team_email(sender, issue_submission, transition_name, request, **kwargs): if not issue_submission.is_submitted: return production_team_group = get_production_team_group(issue_submission.journal) if production_team_group is None: return emails = list( production_team_group.user_set.values_list('email', flat=True)) if not emails: return email = Email( emails, html_template='emails/editor/new_issue_submission_content.html', subject_template='emails/editor/new_issue_submission_subject.html', extra_context={'issue': issue_submission}) email.send()
def create_artist(self, email, password, name, **extra_fields): """Creates and saves a new artist.""" signup_check(email, name, password) artist = Artist.objects.create(email=self.normalize_email(email), name=name, **extra_fields) artist.set_password(password) artist.is_artist = True artist.slug = slugify(name) artist.save(using=self._db) Email('welcome_artist', artist.email).send() return artist
def create_tally(self, artist, event, **extra_fields): """Creates and saves a new tally.""" if not artist: raise ValueError('Enter an artist.') if not event: raise ValueError('Enter an event.') tally = Tally.objects.get_or_create(artist=artist, event=event, **extra_fields) tally[0].slug = slugify(str(event.pk) + '-' + str(artist)) tally[0].save(using=self._db) Email('artist_added', artist.email).send() return tally[0]
def create_promoter(self, email, password, name, phone, **extra_fields): """Creates and saves a new promoter.""" signup_check(email, name, password) if not phone: raise ValueError('Enter a phone number.') promoter = Promoter.objects.create(email=self.normalize_email(email), name=name, phone=phone, **extra_fields) promoter.set_password(password) promoter.is_promoter = True promoter.slug = slugify(name) promoter.save(using=self._db) Email('welcome_promoter', promoter.email).send() return promoter
def create_secret(request): """ Create a secret and send it to the user's email address. A hash of the secret is returned to the client to be checked against the user's email link. """ secret_code = sha256(str(random.random())[2:].encode()).hexdigest() secret_hash = sha256(secret_code.encode()).hexdigest() try: get_user_model().objects.get(email=request.data['email']) dynamic_template_data = {'secret_code': secret_code} Email('password_reset', request.data['email'], dynamic_template_data).send() return Response({'secret_hash': secret_hash}) except get_user_model().DoesNotExist: return Response({'error': 'User does not exist.'})
def invite_artist(self, email, name, **extra_fields): """Invites an artist to join the league.""" if not email: raise ValueError('Enter an email address.') if not name: raise ValueError('Enter a name.') artist = Artist.objects.create(email=self.normalize_email(email), name=name, is_temporary=True, **extra_fields) password = create_code(randint(0, 1000000000000), 8) artist.set_password(password) artist.slug = slugify(name) artist.save(using=self._db) dynamic_template_data = {'password': password} Email('invite_artist', artist.email, dynamic_template_data).send() return artist
def create_temporary_user(self, email, **extra_fields): """Creates and saves a new temporary user.""" string = email.split('@')[0] firstpart, secondpart = \ string[:len(string)//2], string[len(string)//2:] name = firstpart.capitalize() + ' ' + secondpart.capitalize() user = self.model(email=self.normalize_email(email), name=name, is_temporary=True, **extra_fields) password = create_code(randint(0, 1000000000000), 8) user.set_password(password) user.slug = slugify(name) user.save(using=self._db) dynamic_template_data = {'password': password} Email('welcome_temporary_user', user.email, dynamic_template_data).send() temporary_user = { 'email': user.email, 'name': user.name, 'password': password } return temporary_user
def perform_update(self, serializer): instance = serializer.save(owner=self.request.user) owner = instance.owner if not owner.is_promoter: Email('vote', owner.email).send()
def perform_destroy(self, instance): artist = instance.artist instance.delete() Email('artist_removed', artist.email).send()
def verify(modeladmin, request, queryset): """Mark promoters as 'verified'.""" queryset.update(is_verified=True) email_addresses = list(queryset.values_list('email', flat=True)) Email('verified_promoter', email_addresses).send()