def send_email_download_all_personal_data(user_id): # Entity database objects (necessary from template & email) user = User.objects.filter(pk=user_id).first() artist_or_customer = get_artist_or_customer_by_user(user) language = "" pdf_html = None if isinstance(artist_or_customer, Artist): language = artist_or_customer.language context_pdf = { "artist": artist_or_customer, "artist_unavailable_days": ", ".join(list(artist_or_customer.portfolio.calendar.days)), "artist_genders": ",".join( list( artist_or_customer.portfolio.artisticGender. values_list("name", flat=True))), "artist_portfoliomodules": PortfolioModule.objects.filter( portfolio__artist__id=artist_or_customer.id).distinct(), "artist_zones": ",".join( list( artist_or_customer.portfolio.zone.values_list( "name", flat=True))), "artist_offers": Offer.objects.filter( paymentPackage__portfolio__artist__id=artist_or_customer.id ).distinct() } # print(Offer.objects.filter(paymentPackage__portfolio__artist__id=artist_or_customer.id)) pdf_html = translate_render(language, "PDF_DOWNLOAD_DATA_ARTIST", context_pdf) elif isinstance(artist_or_customer, Customer): language = artist_or_customer.language context_pdf = { "customer": artist_or_customer, } pdf_html = translate_render(language, "PDF_DOWNLOAD_DATA_CUSTOMER", context_pdf) pdf_file = HTML(string=pdf_html).write_pdf() # Email from_email = "Grooving <*****@*****.**>" to = [user.email] subject = translate(language, "SUBJECT_DOWNLOAD_DATA_USER") body = translate( language, "BODY_DOWNLOAD_DATA_USER") + Notifications.footer(language) body_content_type = "html" list_attachments = [('data.pdf', pdf_file, 'application/pdf')] EmailMessageThread.send_mail_with_attachments(from_email, to, body, subject, body_content_type, list_attachments, True)
def footer(languages): return translate_render(languages, 'FOOTER')
def send_email_contract_made_to_cancelled_customer(offer_id): # Entity database objects (necessary from template & email) offer = Offer.objects.filter(pk=offer_id).first() system_configuration = SystemConfiguration.objects.filter(pk=1).first() language_artist = get_language( offer.paymentPackage.portfolio.artist.user) language_customer = get_language(offer.eventLocation.customer.user) # Data to generate pdf artist_benefit = round( offer.price - offer.price * (system_configuration.profit / 100), 2) context_pdf = { 'customer_name': offer.eventLocation.customer.user.get_full_name(), 'artist_artisticName': offer.paymentPackage.portfolio.artisticName, 'artist_name': offer.paymentPackage.portfolio.artist.user.get_full_name(), 'event_name': offer.eventLocation.name, 'event_address': offer.eventLocation.address, 'event_corporate_email': system_configuration.corporateEmail, 'event_date_now': datetime.now().strftime('%Y-%m-%d %H:%M'), 'event_duration': offer.hours, 'event_total': offer.price, 'event_currency': offer.currency, 'system_configuration_profit': system_configuration.profit.normalize(), 'invoice_grooving_benefit': round(offer.price * (system_configuration.profit / 100), 2), 'invoice_customer_benefit': artist_benefit, } if language_customer == 'es': context_pdf[ 'system_configuration_terms_and_conditions'] = system_configuration.termsText_es elif language_customer == 'en': context_pdf[ 'system_configuration_terms_and_conditions'] = system_configuration.termsText_en pdf_html = translate_render(language_customer, "PDF_CONTRACT_MADE_TO_CANCELLED_CUSTOMER", context_pdf) # Email from_email = "Grooving <*****@*****.**>" body_content_type = "html" # Artist mail to = [offer.paymentPackage.portfolio.artist.user.email] body = "" subject = "" if language_artist == "en": subject = "The performance has been cancelled by " + offer.eventLocation.customer.user.get_full_name( ) body = "<p>We are sorry that the performance has been cancelled.</p>" \ "<p>See you soon!</p>" + Notifications.footer(language_artist) elif language_artist == "es": subject = "El espectáculo ha sido cancelado por " + offer.eventLocation.customer.user.get_full_name( ) body = "<p>Sentimos que la actuación haya sido cancelada.</p>" \ "<p>¡Nos vemos pronto!</p>" + Notifications.footer(language_artist) EmailMessageThread.send_mail(from_email, to, body, subject, body_content_type, True) # Customer mail to = [offer.eventLocation.customer.user.email] if language_customer == "en": subject = 'You cancelled the performance' body = '<p>We are sorry that this decision. We proceed to return the money to your account.</p>' + \ Notifications.footer(language_customer) elif language_customer == "es": subject = 'Has cancelado la actuación' body = '<p>Sentimos que hayas tomado esta decisión. Procederemos a devolver el dinero a su cuenta.</p>' + \ Notifications.footer(language_customer) pdf_file = HTML(string=pdf_html).write_pdf() list_attachments = [('invoice.pdf', pdf_file, 'application/pdf')] EmailMessageThread.send_mail_with_attachments(from_email, to, body, subject, body_content_type, list_attachments, True) @staticmethod def send_notification_for_breach_security(subject, breach_explanation): # Get all system emails email_system_configuration_list = [ '', SystemConfiguration.corporateEmail, SystemConfiguration.reportEmail ] artist_list = Artist.objects.all().distinct('user__email'). \ exclude(user__email__in=email_system_configuration_list) customer_list = Customer.objects.all().distinct('user__email'). \ exclude(user__email__in=email_system_configuration_list) for artist in artist_list: from_email = "Grooving <*****@*****.**>" to = [artist.user.email] body_content_type = "html" custom_body = translate(artist.language, "BREACH_NOTIFICATION_BODY") + "<p>" + breach_explanation + "</p>" + \ Notifications.footer(artist.language) EmailMessageThread.send_mail(from_email, to, custom_body, subject, body_content_type, True) for customer in customer_list: from_email = "Grooving <*****@*****.**>" to = [customer.user.email] body_content_type = "html" custom_body = translate(customer.language, "BREACH_NOTIFICATION_BODY") + "<p>" + breach_explanation + "</p>" + \ Notifications.footer(customer.language) EmailMessageThread.send_mail(from_email, to, custom_body, subject, body_content_type, True)
def send_email_contract_made_to_cancelled_artist(offer_id): # Entity database objects (necessary from template & email) offer = Offer.objects.filter(pk=offer_id).first() system_configuration = SystemConfiguration.objects.filter(pk=1).first() language_artist = get_language( offer.paymentPackage.portfolio.artist.user) language_customer = get_language(offer.eventLocation.customer.user) # Data to generate pdf artist_benefit = round( offer.price - offer.price * (system_configuration.profit / 100), 2) context_pdf = { 'customer_name': offer.eventLocation.customer.user.get_full_name(), 'artist_artisticName': offer.paymentPackage.portfolio.artisticName, 'artist_name': offer.paymentPackage.portfolio.artist.user.get_full_name(), 'event_name': offer.eventLocation.name, 'event_address': offer.eventLocation.address, 'event_corporate_email': system_configuration.corporateEmail, 'event_date_now': datetime.now().strftime('%Y-%m-%d %H:%M'), 'event_duration': offer.hours, 'event_total': offer.price, 'event_currency': offer.currency, 'system_configuration_profit': system_configuration.profit.normalize(), 'invoice_grooving_benefit': round(offer.price * (system_configuration.profit / 100), 2), 'invoice_customer_benefit': artist_benefit, } if language_customer == 'es': context_pdf[ 'system_configuration_terms_and_conditions'] = system_configuration.termsText_es elif language_customer == 'en': context_pdf[ 'system_configuration_terms_and_conditions'] = system_configuration.termsText_en pdf_html = translate_render(language_customer, "PDF_CONTRACT_MADE_TO_CANCELLED_ARTIST", context_pdf) # Email from_email = "Grooving <*****@*****.**>" body_content_type = "html" # Artist mail to = [offer.paymentPackage.portfolio.artist.user.email] subject = "" body = "" if language_artist == "en": subject = "The performance has been cancelled by you" body = "<p>We are sorry that this decision.</p><p>See you soon!<p>" + Notifications.footer( language_artist) elif language_artist == "es": subject = "Has cancelado la actuación" body = "<p>Sentimos que hayas tomado esta decisión.</p><p>¡Nos vemos pronto!<p>" + \ Notifications.footer(language_artist) EmailMessageThread.send_mail(from_email, to, body, subject, body_content_type, True) # Customer mail to = [offer.eventLocation.customer.user.email] if language_customer == "en": subject = "The artist has cancelled the performance" body = "<p>We are sorry that the performance has been cancelled. We proceed to return the money to your" \ " account.</p>" + Notifications.footer(language_customer) elif language_customer == "es": subject = "El artista ha cancelado la actuación" body = "<p>Sentimos que la actuación haya sido cancelada. Procedemos a devolver el pago a su cuenta.</p>" + \ Notifications.footer(language_customer) pdf_file = HTML(string=pdf_html).write_pdf() list_attachments = [('invoice.pdf', pdf_file, 'application/pdf')] EmailMessageThread.send_mail_with_attachments(from_email, to, body, subject, body_content_type, list_attachments, True)
def send_email_contract_made_to_payment_made(offer_id): # Entity database objects (necessary from template & email) offer = Offer.objects.filter(pk=offer_id).first() system_configuration = SystemConfiguration.objects.filter(pk=1).first() language_artist = get_language( offer.paymentPackage.portfolio.artist.user) language_customer = get_language(offer.eventLocation.customer.user) # Data to generate email body & pdf artist_benefit = round( offer.price - offer.price * (system_configuration.profit / 100), 2) context_pdf = { 'customer_name': offer.eventLocation.customer.user.get_full_name(), 'artist_artisticName': offer.paymentPackage.portfolio.artisticName, 'artist_name': offer.paymentPackage.portfolio.artist.user.get_full_name(), 'event_name': offer.eventLocation.name, 'event_address': offer.eventLocation.address, 'event_corporate_email': system_configuration.corporateEmail, 'event_date_now': datetime.now().strftime('%Y-%m-%d %H:%M'), 'event_duration': offer.hours, 'event_total': offer.price, 'event_currency': offer.currency, 'system_configuration_profit': system_configuration.profit.normalize(), 'invoice_grooving_benefit': round(offer.price * (system_configuration.profit / 100), 2), 'invoice_artist_benefit': artist_benefit, } if language_artist == 'es': context_pdf[ 'system_configuration_terms_and_conditions'] = system_configuration.termsText_es elif language_artist == 'en': context_pdf[ 'system_configuration_terms_and_conditions'] = system_configuration.termsText_en # Common email content from_email = "Grooving <*****@*****.**>" body_content_type = "html" # Customer mail to = [offer.eventLocation.customer.user.email] subject = "" body = "" if language_customer == "en": subject = offer.paymentPackage.portfolio.artisticName + " performance is over" body = "<p>We hope you enjoyed to " + offer.paymentPackage.portfolio.artisticName + " performance.<p>" \ + Notifications.footer(language_customer) elif language_customer == "es": subject = "¡" + offer.paymentPackage.portfolio.artisticName + " ha finalizado su actuación!" body = "<p>Esperamos que haya disfrutado del espectáculo de " \ + offer.paymentPackage.portfolio.artisticName + ".<p>" \ + Notifications.footer(language_customer) EmailMessageThread.send_mail(from_email, to, body, subject, body_content_type, True) # Artist mail to = [offer.paymentPackage.portfolio.artist.user.email] subject = "" body = "" if language_artist == "en": subject = "The payment has been realized" body = "<h1>You have received the payment in your account </h1>" \ "<p>You can see the details on pdf attachment.<p>" + Notifications.footer(language_artist) elif language_artist == "es": subject = "El pago ha sido realizado" body = "<h1>Has recibido el pago en tu cuenta</h1>" \ "<p>Puedes ver los detalles en el pdf adjunto.<p>" + Notifications.footer(language_artist) # Email - PDF generator to artist pdf_html = translate_render(language_artist, "PDF_CONTRACT_MADE_TO_PAYMENT_MADE", context_pdf) pdf_file = HTML(string=pdf_html).write_pdf() list_attachments = [('contract.pdf', pdf_file, 'application/pdf')] EmailMessageThread.send_mail_with_attachments(from_email, to, body, subject, body_content_type, list_attachments, True)
def send_email_pending_to_contract_made(offer_id): # Entity database objects (necessary from template & email) offer = Offer.objects.filter(pk=offer_id).first() system_configuration = SystemConfiguration.objects.filter(pk=1).first() language_artist = get_language( offer.paymentPackage.portfolio.artist.user) language_customer = get_language(offer.eventLocation.customer.user) # Data to generate email body & pdf context_body = { 'customer_name': offer.eventLocation.customer.user.get_full_name(), 'event_name': offer.eventLocation.name, 'event_address': offer.eventLocation.address, 'event_description': offer.eventLocation.description, 'event_date': offer.date.strftime('%Y-%m-%d'), 'event_duration': offer.hours, 'event_hour': offer.date.strftime('%H:%M'), 'event_price': offer.price, 'event_currency': offer.currency, 'event_equipment': offer.eventLocation.equipment, } context_pdf = { 'customer_name': offer.eventLocation.customer.user.get_full_name(), 'artist_artisticName': offer.paymentPackage.portfolio.artisticName, 'artist_name': offer.paymentPackage.portfolio.artist.user.get_full_name(), 'event_name': offer.eventLocation.name, 'event_address': offer.eventLocation.address, 'event_description': offer.eventLocation.description, 'event_date': offer.date.strftime('%Y-%m-%d'), 'event_duration': offer.hours, 'event_hour': offer.date.strftime('%H:%M'), 'event_price': offer.price, 'event_currency': offer.currency, 'event_equipment': offer.eventLocation.equipment, 'system_configuration_profit': system_configuration.profit, } # Check package type (necessary for generate pdf & body information) if offer.paymentPackage.performance is not None: context_pdf[ 'event_payment_package'] = 'Performance' # Informaremos el precio total y la duración context_body['event_payment_package'] = 'Performance' elif offer.paymentPackage.fare is not None: context_pdf[ 'event_payment_package'] = 'Fare' # Informaremos del precio multiplicado por la hora context_pdf[ 'event_payment_package_price_per_hour'] = offer.paymentPackage.fare.priceHour context_body['event_payment_package'] = 'Fare' else: context_pdf[ 'event_payment_package'] = 'Custom' # Informaremos del precio total y la duración context_body['event_payment_package'] = 'Custom' # Email - PDF generator if language_artist == 'es': context_pdf[ 'system_configuration_terms_and_conditions'] = system_configuration.termsText_es elif language_artist == 'en': context_pdf[ 'system_configuration_terms_and_conditions'] = system_configuration.termsText_en pdf_html_artist = translate_render(language_artist, "PDF_PENDING_TO_CONTRACT_MADE", context_pdf) if language_customer == 'es': context_pdf[ 'system_configuration_terms_and_conditions'] = system_configuration.termsText_es elif language_customer == 'en': context_pdf[ 'system_configuration_terms_and_conditions'] = system_configuration.termsText_en pdf_html_customer = translate_render(language_customer, "PDF_PENDING_TO_CONTRACT_MADE", context_pdf) # Email - Body generator for artist if language_artist == "en": context_body[ 'system_configuration_terms_and_conditions'] = system_configuration.termsText_en context_body['title'] = 'Congratulations! You have been hired by ' + \ offer.eventLocation.customer.user.get_full_name() elif language_artist == "es": context_body[ 'system_configuration_terms_and_conditions'] = system_configuration.termsText_es context_body['title'] = '¡Felicidades! Has sido contratado por ' + \ offer.eventLocation.customer.user.get_full_name() body_artist_html = translate_render(language_artist, "BODY_PENDING_TO_CONTRACT_MADE", context_body) + \ Notifications.footer(language_artist) # Email - Body generator for customer if language_customer == "en": context_body[ 'title'] = 'Done! You have hired ' + offer.paymentPackage.portfolio.artisticName elif language_customer == "es": context_body[ 'title'] = '¡Hecho! Has contratado a ' + offer.paymentPackage.portfolio.artisticName context_body['event_payment_code'] = offer.paymentCode if language_customer == 'es': context_body[ 'system_configuration_terms_and_conditions'] = system_configuration.termsText_es elif language_customer == 'en': context_body[ 'system_configuration_terms_and_conditions'] = system_configuration.termsText_en body_customer_html = translate_render(language_customer, "BODY_PENDING_TO_CONTRACT_MADE", context_body) + \ Notifications.footer(language_customer) # Common email content from_email = "Grooving <*****@*****.**>" body_content_type = "html" # Artist mail to = [offer.paymentPackage.portfolio.artist.user.email] subject = "" if language_artist == 'en': subject = "Offer accepted" elif language_artist == 'es': subject = "Oferta aceptada" pdf_file_artist = HTML( string=pdf_html_artist).write_pdf() # Generating PDF list_attachments = [('contract.pdf', pdf_file_artist, 'application/pdf')] EmailMessageThread.send_mail_with_attachments(from_email, to, body_artist_html, subject, body_content_type, list_attachments, True) # Customer mail subject = "" if language_customer == 'en': subject = "Offer accepted" elif language_customer == 'es': subject = "Oferta aceptada" to = [offer.eventLocation.customer.user.email] pdf_file_customer = HTML( string=pdf_html_customer).write_pdf() # Generating PDF list_attachments = [('contract.pdf', pdf_file_customer, 'application/pdf')] EmailMessageThread.send_mail_with_attachments(from_email, to, body_customer_html, subject, body_content_type, list_attachments, True)