from slugify import slugify

from django.contrib.auth.models import User


def product_main_img_path(instance, filename):
    return 'products/{}/{}'.format(instance.slug, filename)


def product_img_path(instance, filename):
    return 'products/{}/{}'.format(instance.product.slug, filename)


def category_img_path(instance, filename):
    return 'categories/{}/{}'.format(instance.slug, filename)


def manufacturer_img_path(instance, filename):
    return 'manufacturers/{}/{}'.format(instance.slug, filename)


def cat_choices(categories):
    CHOICES = [[0, '---------']]
    main_cats = [cat for cat in categories if not cat.has_parent_category()]

    for cat in main_cats:
        CHOICES.append([int(cat.id), cat.name])
        if cat.subcategories() is None:
            continue
        for subcat in cat.subcategories():
            CHOICES.append([subcat.id, "___  {}".format(subcat.name)])
            if subcat.subcategories() is None:
                continue
            for subcat_ in subcat.subcategories():
                choice = [subcat_.id, "______ {}".format(subcat_.name)]
                CHOICES.append(choice)

    return CHOICES


def base_for_product_slug(instance):
    return '{}-{}'.format(instance.name, instance.model_name)


def slugify_(some_string):
    """
    Convert 'some_string' to correct slug.

    Note: slugify() converts some symbols to "'" (apostrophe),
    and SlugField does not accept apostrophes.
    So this fixed by replacement of all apostrophes.
    """
    return slugify(some_string, only_ascii=True).replace("'", "")


# Helpers for tests ----------------------------------------------------------
def get_staff_member():
    """Create staff member """
    admin, _ = User.objects.get_or_create(username='admin12345',
                                          password="password12345")
    admin.is_staff = True
    admin.save()
    return admin


def get_regular_user():
    """Create regular user """
    user, _ = User.objects.get_or_create(username='username',
                                         password="password12345")
    return user

@@ -1991,32 +1991,41 @@
 s.get_or_create(
+%0A        
 username='userna
@@ -2041,33 +2041,89 @@
     
-                         
+first_name='First',%0A        last_name='Last',%0A        email='sometest@email.ts',%0A
     
@@ -2146,24 +2146,30 @@
 ssword12345%22
+,%0A    
 )%0A    return

Update user creation for tests