# Path: payments/utils.py
# def email_unpaid_orders(verbose=0):
#     """
#     Send email to all users who has unpaid orders.
#     """
#     email_overdue_orders(verbose=verbose)
# 
#     # notify the rest
#     orders = Order.get_unpaid_orders()
#     template_name = 'unpaid_order_notification'
# 
#     for order in orders:
#         subject = 'Your order for {event} haven\'t been paid yet.'.format(event=order.event.title)
#         order_url = get_full_order_url(order)
# 
#         for ticket in order.ticket_set.all():
#             content_data = {
#                 'first_name': ticket.first_name,
#                 'last_name': ticket.last_name,
#                 'event': order.event.title,
#                 'order_url': order_url,
#             }
#             addresses = {'to': [ticket.email], 'bcc': EMAIL_NOTIFY_BCC}
#             send_email(addresses, subject, template_name, content_data)
#             msg = 'Email template unpaid_order_notification has been send to: %s' % ticket.email
# 
#             if verbose > 2:
#                 print(msg)
#             logger.debug(msg)
# 
#             order.unpaid_notification_sent_at = timezone.now()
#             order.unpaid_notification_sent_amount += 1
# 
#         order.save()


from django.core.management.base import BaseCommand
from payments.utils import email_unpaid_orders



class Command(BaseCommand):
    help = 'Send email notifications for unpaid order.'

    def handle(self, *args, **options):
        email_unpaid_orders(verbose=options['verbosity'])

        if options['verbosity'] > 0:

# Path: payments/utils.py
# def email_unpaid_orders(verbose=0):
#     """
#     Send email to all users who has unpaid orders.
#     """
#     email_overdue_orders(verbose=verbose)
# 
#     # notify the rest
#     orders = Order.get_unpaid_orders()
#     template_name = 'unpaid_order_notification'
# 
#     for order in orders:
#         subject = 'Your order for {event} haven\'t been paid yet.'.format(event=order.event.title)
#         order_url = get_full_order_url(order)
# 
#         for ticket in order.ticket_set.all():
#             content_data = {
#                 'first_name': ticket.first_name,
#                 'last_name': ticket.last_name,
#                 'event': order.event.title,
#                 'order_url': order_url,
#             }
#             addresses = {'to': [ticket.email], 'bcc': EMAIL_NOTIFY_BCC}
#             send_email(addresses, subject, template_name, content_data)
#             msg = 'Email template unpaid_order_notification has been send to: %s' % ticket.email
# 
#             if verbose > 2:
#                 print(msg)
#             logger.debug(msg)
# 
#             order.unpaid_notification_sent_at = timezone.now()
#             order.unpaid_notification_sent_amount += 1
# 
#         order.save()


# Path: payments/management/commands/email_unpaid_notifications.py
from django.core.management.base import BaseCommand
from payments.utils import email_unpaid_orders




class Command(BaseCommand):
    help = 'Send email notifications for unpaid order.'

    def handle(self, *args, **options):
        email_unpaid_orders(verbose=options['verbosity'])

        if options['verbosity'] > 0:

            self.stdout.write(self.style.SUCCESS('Successfully sent email notifications for unpaid orders.'))