Commit 0f69fcc9 authored by Birin Sanchez's avatar Birin Sanchez
Browse files

Add 2 new commands:


* populate_billing_email
* non_unique_emails
Signed-off-by: Birin Sanchez's avatarBirin Sanchez <birin.sanchez@puri.sm>
parent 26dff5cb
Pipeline #12691 passed with stage
in 38 seconds
from django.core.management.base import BaseCommand
from purist.models import User
class Command(BaseCommand):
help = 'Shows what recovery emails are used in more than one account.'
def handle(self, *args, **options):
sql_query = 'SELECT id,email,COUNT(email) AS count from purist_user \
GROUP BY email HAVING COUNT(email) > 1'
query = User.objects.raw(sql_query)
msg1 = "\nRecovery email '{}' is used {} times by the following users:"
msg2 = ' {}'
for item in query:
print(msg1.format(item.email, item.count))
users = User.objects.filter(email=item.email)
for user in users:
print(msg2.format(user.username))
from django.core.management.base import BaseCommand
from purist.models import User
import time
class Command(BaseCommand):
help = "Populate billing_email value for users that don't have it set. If \
the user has a WooCommerce email this value will be used. \
Otherwise the User.get_identity() identity will be used."
def add_arguments(self, parser):
parser.add_argument('--wait',
type=int,
help='Number of seconds to wait between users. \
Default is 0.',
default=0)
def handle(self, *args, **options):
wait_time = options['wait']
# Get all users with billing_email = ''
usr_empty = User.objects.filter(billing_email='')
self.stdout.write('Processing users with no billing_email')
for user in usr_empty:
wc_email = user.get_woocommerce_billing_email()
if wc_email is None or wc_email == '':
user.billing_email = user.get_identity()
else:
user.billing_email = wc_email
user.save()
self.stdout.write(' User {}:'.format(user.username))
self.stdout.write(' New billing_email: {}'.format(
user.billing_email))
time.sleep(wait_time)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment