def view(request):
    data = {'title': 'Sabadiaz Jewelry - WishList'}
    addUserData(request, data)
    data['option'] = 'wishlist'
    data['current_page'] = 'Wishlist'
    data['my_wishlist'] = WishList.objects.filter(user=data['user'])
    return render(request, 'site/wishlist.html', data)
Exemple #2
0
def details(request, product_id):
    data = {'title': 'Sabadiaz Jewelry - Product Details'}
    addUserData(request, data)

    data['option'] = 'product_details'
    data['current_page'] = 'Product Details'
    data['product'] = product = Product.objects.get(id=product_id)
    data['related_products'] = Product.objects.filter(
        Q(category=product.category) | Q(material=product.material)
        | Q(gender=product.gender)).exclude(id=product_id)[:6]
    return render(request, 'site/product_details.html', data)
def delete(request, item_id):
    data = {'title': 'Sabadiaz Jewelry - WishList - Delete Item'}
    addUserData(request, data)

    try:
        with transaction.atomic():
            wishlist = WishList.objects.get(id=item_id)
            wishlist.delete()
            return ok_json(data={'message': 'Product removed from your wishlist'})

    except Exception as ex:
        return bad_json(message=ex.__str__())
Exemple #4
0
def create_product(request):
    data = {'title': 'Sabadiaz Jewelry Admin - Create Product'}
    addUserData(request, data)

    if request.method == 'POST':
        try:
            with transaction.atomic():
                code = request.POST['code']
                description = request.POST['description']
                category_id = int(request.POST['category_id'])
                gender_id = int(request.POST['gender_id'])
                material_id = int(request.POST['material_id'])
                price = float(request.POST['price'])
                stock = int(request.POST['stock'])
                weight = float(request.POST['weight'])
                # is_new = True if request.POST['is_new'] == 'true' else False
                # is_featured = True if request.POST['is_featured'] == 'true' else False
                # is_bestseller = True if request.POST['is_bestseller'] == 'true' else False

                product = Product(code=code,
                                  description=description,
                                  category_id=category_id,
                                  material_id=material_id,
                                  gender_id=gender_id,
                                  price=price,
                                  weight=weight,
                                  stock=stock)
                product.save()

                # for index, key in enumerate(request.FILES):
                #     setattr(product, f'image{index+1}', request.FILES[key])
                #     setattr(product, f'image{index+1}_b', request.FILES[key])
                #     product.save()

                time.sleep(1)
                return ok_json(
                    data={
                        'message': 'Product has been succesfully created!',
                        'redirect_url': reverse('admin_products')
                    })

        except Exception as ex:
            return bad_json(message=ex.__str__())

    data['option'] = 'admin_create_product'
    data['categories'] = Category.objects.all()
    data['materials'] = Material.objects.all()
    data['genders'] = Gender.objects.all()
    data['product'] = None
    return render(request, 'administration/products/product.html', data)
def add(request, product_id):
    data = {'title': 'Sabadiaz Jewelry - WishList - Add Item'}
    addUserData(request, data)

    try:
        with transaction.atomic():
            wishlist, _ = WishList.objects.get_or_create(user=data['user'], product_id=product_id)
            wishlist.created_at = datetime.datetime.now()
            wishlist.save()
            wishlist_items = WishList.objects.filter(user=data['user']).count()
            return ok_json(data={'message': 'Product added to your wishlist',
                                 'wishlist_items': wishlist_items})

    except Exception as ex:
        return bad_json(message=ex.__str__())
Exemple #6
0
def reviews(request, product_id):
    data = {'title': 'Sabadiaz Jewelry - Product Reviews'}
    addUserData(request, data)

    try:
        review_obj, _ = Review.objects.get_or_create(
            product_id=product_id,
            user=data['user'],
            rating=int(request.POST['rating']))
        review_obj.review = request.POST['review']
        review_obj.save()
        time.sleep(1)
        return ok_json(data={'message': 'Review succesfully added!'})

    except Exception as ex:
        return bad_json(message=ex.__str__())
Exemple #7
0
def view(request):
    data = {'title': 'Sabadiaz Jewelry Admin - All Products'}
    addUserData(request, data)

    products = Product.objects.order_by('-id')
    page = request.GET.get('page', 1)

    paginator = Paginator(products, 5)
    try:
        products = paginator.page(page)
    except PageNotAnInteger:
        products = paginator.page(1)
    except EmptyPage:
        products = paginator.page(paginator.num_pages)

    data['products'] = products
    data['option'] = 'admin_all_products'
    return render(request, 'administration/products/view.html', data)
def views(request):
    data = {'title': 'Works and Tasks'}
    addUserData(request, data)

    if request.method == 'POST':
        if 'action' in request.POST:
            action = request.POST['action']

            if action == 'add':
                try:
                    with transaction.atomic():

                        if 'address' in request.POST and request.POST['address'] != '':
                            address = request.POST['address']
                        else:
                            return bad_json(message='Please enter a work address')

                        if 'sel_project' in request.POST and request.POST['sel_project'] != '':
                            project_id = int(request.POST['sel_project'])
                        else:
                            return bad_json(message='Please select a project')

                        if 'sel_supervisor' in request.POST and request.POST['sel_supervisor'] != '':
                            supervisor_id = int(request.POST['sel_supervisor'])
                        else:
                            return bad_json(message='Please select a supervisor')

                        notes = ''
                        if 'notes' in request.POST and request.POST['notes'] != '':
                            notes = request.POST['notes']

                        work = Work(project_id=project_id,
                                    supervisor_id=supervisor_id,
                                    address=address,
                                    notes=notes)
                        work.save()

                        return ok_json(data={'message': 'A work order has been successfully created!'})

                except Exception as ex:
                    return bad_json(error=1)

            if action == 'edit':
                try:
                    with transaction.atomic():

                        if 'eid' in request.POST and Work.objects.filter(pk=int(request.POST['eid'])).exists():
                            work = Work.objects.get(pk=int(request.POST['eid']))

                            if 'address' in request.POST and request.POST['address'] != '':
                                address = request.POST['address']
                            else:
                                return bad_json(message='Please enter a work address')

                            if 'sel_project' in request.POST and request.POST['sel_project'] != '':
                                project_id = int(request.POST['sel_project'])
                            else:
                                return bad_json(message='Please select a project')

                            if 'sel_supervisor' in request.POST and request.POST['sel_supervisor'] != '':
                                supervisor_id = int(request.POST['sel_supervisor'])
                            else:
                                return bad_json(message='Please select a supervisor')

                            notes = ''
                            if 'notes' in request.POST and request.POST['notes'] != '':
                                notes = request.POST['notes']

                            work.project_id = project_id
                            work.supervisor_id = supervisor_id
                            work.address = address
                            work.notes = notes
                            work.save()

                            return ok_json(data={'message': 'A work has been successfully edited!'})

                        return bad_json(message="Work does not exist")
                except Exception as ex:
                    return bad_json(error=1)

            if action == 'delete':
                try:
                    with transaction.atomic():

                        if 'eid' in request.POST and Work.objects.filter(pk=int(request.POST['eid'])).exists():
                            work = Work.objects.get(pk=int(request.POST['eid']))
                            work.delete()
                            return ok_json(data={'message': 'A work has been successfully deleted!'})

                        return bad_json(message="Work does not exist")
                except Exception as ex:
                    return bad_json(error=1)

            return bad_json(error=0)
    else:

        if 'action' in request.GET:
            action = request.GET['action']

            if action == 'get_work_data':
                try:
                    if 'eid' in request.GET and Work.objects.filter(pk=int(request.GET['eid'])).exists():
                        work = Work.objects.get(pk=int(request.GET['eid']))
                        return ok_json(data={'project_id': work.project_id,
                                             'supervisor_id': work.supervisor_id,
                                             'address': work.address,
                                             'notes': work.notes})

                    return bad_json(message='Work does not exist')
                except Exception:
                    return bad_json(error=2)

    data['works'] = Work.objects.filter(project__company=data['company'])
    data['projects'] = Project.objects.filter(company=data['company'])
    data['work_types'] = WorkType.objects.filter(company=data['company'])
    data['supervisors'] = Users.objects.filter(type=USERS_GROUP_EMPLOYEES, is_supervisor=True, usercompany__company=data['company'])
    return render(request, "works.html", data)
def views(request):
    data = {'title': 'Employees'}
    addUserData(request, data)

    if request.method == 'POST':
        if 'action' in request.POST:
            action = request.POST['action']

            if action == 'add':
                try:
                    with transaction.atomic():

                        if 'first_name' in request.POST and request.POST[
                                'first_name'] != '':
                            first_name = request.POST['first_name'].capitalize(
                            )
                        else:
                            return bad_json(
                                message='Please enter a first name')

                        if 'last_name' in request.POST and request.POST[
                                'last_name'] != '':
                            last_name = request.POST['last_name'].capitalize()
                        else:
                            return bad_json(message='Please enter a last name')

                        if 'email' in request.POST and request.POST[
                                'email'] != '':
                            email = request.POST['email']
                        else:
                            return bad_json(
                                message='Please enter a valid email')

                        if 'phone' in request.POST and request.POST[
                                'phone'] != '':
                            phone = request.POST['phone']
                        else:
                            return bad_json(
                                message='Please enter a phone number')

                        gender = None
                        if 'genders' in request.POST and request.POST[
                                'genders'] != '':
                            gender = int(request.POST['genders'])

                        is_supervisor = None
                        if 'supervisors' in request.POST and request.POST[
                                'supervisors'] != '':
                            is_supervisor = True if int(
                                request.POST['supervisors']) == 1 else False

                        if Users.objects.filter(type=USERS_GROUP_EMPLOYEES,
                                                phone=phone).exists():
                            return bad_json(
                                message=
                                'An employee already exist with this phone number'
                            )

                        if Users.objects.filter(type=USERS_GROUP_EMPLOYEES,
                                                user__email=email).exists():
                            return bad_json(
                                message=
                                'An employee already exist with this email')

                        django_user = User(username=email,
                                           first_name=first_name,
                                           last_name=last_name,
                                           email=email)
                        django_user.save()

                        employee = Users(user=django_user,
                                         type=USERS_GROUP_EMPLOYEES,
                                         phone=phone,
                                         gender=gender,
                                         is_supervisor=is_supervisor)
                        employee.save()

                        employee_company = UserCompany(user=employee,
                                                       company=data['company'])
                        employee_company.save()

                        return ok_json(
                            data={
                                'message':
                                'An employee has been successfully created!'
                            })

                except Exception as ex:
                    return bad_json(error=1)

            if action == 'edit':
                try:
                    with transaction.atomic():

                        if 'eid' in request.POST and Users.objects.filter(
                                pk=int(request.POST['eid'])).exists():
                            employee = Users.objects.get(
                                pk=int(request.POST['eid']))

                            if 'first_name' in request.POST and request.POST[
                                    'first_name'] != '':
                                first_name = request.POST[
                                    'first_name'].capitalize()
                            else:
                                return bad_json(
                                    message='Please enter a first name')

                            if 'last_name' in request.POST and request.POST[
                                    'last_name'] != '':
                                last_name = request.POST[
                                    'last_name'].capitalize()
                            else:
                                return bad_json(
                                    message='Please enter a last name')

                            if 'email' in request.POST and request.POST[
                                    'email'] != '':
                                email = request.POST['email']
                            else:
                                return bad_json(
                                    message='Please enter a valid email')

                            if 'phone' in request.POST and request.POST[
                                    'phone'] != '':
                                phone = request.POST['phone']
                            else:
                                return bad_json(
                                    message='Please enter a phone number')

                            gender = None
                            if 'genders' in request.POST and request.POST[
                                    'genders'] != '':
                                gender = int(request.POST['genders'])

                            is_supervisor = None
                            if 'supervisors' in request.POST and request.POST[
                                    'supervisors'] != '':
                                is_supervisor = True if int(
                                    request.POST['supervisors']
                                ) == 1 else False

                            if Users.objects.filter(
                                    type=USERS_GROUP_EMPLOYEES,
                                    phone=phone).exclude(
                                        id=employee.id).exists():
                                return bad_json(
                                    message=
                                    'An employee already exist with this phone number'
                                )

                            if Users.objects.filter(
                                    type=USERS_GROUP_EMPLOYEES,
                                    user__email=email).exclude(
                                        id=employee.id).exists():
                                return bad_json(
                                    message=
                                    'An employee already exist with this email'
                                )

                            django_user = employee.user
                            django_user.first_name = first_name
                            django_user.last_name = last_name
                            django_user.email = email
                            django_user.username = email
                            django_user.save()

                            employee.phone = phone
                            employee.gender = gender
                            employee.is_supervisor = is_supervisor
                            employee.save()

                            return ok_json(
                                data={
                                    'message':
                                    'An employee has been successfully edited!'
                                })

                        return bad_json(message="Employee does not exist")
                except Exception as ex:
                    return bad_json(error=1)

            if action == 'delete':
                try:
                    with transaction.atomic():

                        if 'eid' in request.POST and Users.objects.filter(
                                pk=int(request.POST['eid'])).exists():
                            employee = Users.objects.get(
                                pk=int(request.POST['eid']))
                            django_user = employee.user
                            employee.delete()
                            django_user.delete()
                            return ok_json(
                                data={
                                    'message':
                                    'Am employee has been successfully deleted!'
                                })

                        return bad_json(message="Employee does not exist")
                except Exception as ex:
                    return bad_json(error=1)

            return bad_json(error=0)
    else:

        if 'action' in request.GET:
            action = request.GET['action']

            if action == 'get_employee_data':
                try:
                    if 'eid' in request.GET and Users.objects.filter(
                            pk=int(request.GET['eid'])).exists():
                        employee = Users.objects.get(
                            pk=int(request.GET['eid']))
                        return ok_json(
                            data={
                                'first_name':
                                employee.user.first_name,
                                'last_name':
                                employee.user.last_name,
                                'email':
                                employee.user.email,
                                'phone':
                                employee.phone,
                                'gender':
                                employee.gender,
                                'supervisor':
                                "1" if employee.is_supervisor else "2"
                            })

                    return bad_json(message="Employee does not exist")
                except Exception as ex:
                    return bad_json(message=ex.__str__())

    data['employees'] = Users.objects.filter(
        type=USERS_GROUP_EMPLOYEES, usercompany__company=data['company'])
    return render(request, "employees.html", data)
Exemple #10
0
def views(request):
    data = {'title': 'Customers'}
    addUserData(request, data)

    if request.method == 'POST':
        if 'action' in request.POST:
            action = request.POST['action']

            if action == 'add':
                try:
                    with transaction.atomic():

                        if 'first_name' in request.POST and request.POST[
                                'first_name'] != '':
                            first_name = request.POST['first_name'].capitalize(
                            )
                        else:
                            return bad_json(
                                message='Please enter a first name')

                        if 'last_name' in request.POST and request.POST[
                                'last_name'] != '':
                            last_name = request.POST['last_name'].capitalize()
                        else:
                            return bad_json(message='Please enter a last name')

                        if 'email' in request.POST and request.POST[
                                'email'] != '':
                            email = request.POST['email']
                        else:
                            return bad_json(
                                message='Please enter a valid email')

                        if 'phone' in request.POST and request.POST[
                                'phone'] != '':
                            phone = request.POST['phone']
                        else:
                            return bad_json(
                                message='Please enter a phone number')

                        gender = None
                        if 'genders' in request.POST and request.POST[
                                'genders'] != '':
                            gender = int(request.POST['genders'])

                        if Users.objects.filter(type=USERS_GROUP_CUSTOMERS,
                                                phone=phone).exists():
                            return bad_json(
                                message=
                                'A customer already exist with that phone number'
                            )

                        if Users.objects.filter(type=USERS_GROUP_CUSTOMERS,
                                                user__email=email).exists():
                            return bad_json(
                                message=
                                'A customer already exist with that email')

                        django_user = User(username=email,
                                           first_name=first_name,
                                           last_name=last_name,
                                           email=email)
                        django_user.save()

                        customer = Users(user=django_user,
                                         type=USERS_GROUP_CUSTOMERS,
                                         phone=phone,
                                         gender=gender)
                        customer.save()

                        customer_company = UserCompany(user=customer,
                                                       company=data['company'])
                        customer_company.save()

                        return ok_json(data={
                            'message':
                            'A customer has been successfully created!'
                        })

                except Exception as ex:
                    return bad_json(error=1)

            if action == 'edit':
                try:
                    with transaction.atomic():

                        if 'eid' in request.POST and Users.objects.filter(
                                pk=int(request.POST['eid'])).exists():
                            customer = Users.objects.get(
                                pk=int(request.POST['eid']))

                            if 'first_name' in request.POST and request.POST[
                                    'first_name'] != '':
                                first_name = request.POST[
                                    'first_name'].capitalize()
                            else:
                                return bad_json(
                                    message='Please enter a first name')

                            if 'last_name' in request.POST and request.POST[
                                    'last_name'] != '':
                                last_name = request.POST[
                                    'last_name'].capitalize()
                            else:
                                return bad_json(
                                    message='Please enter a last name')

                            if 'email' in request.POST and request.POST[
                                    'email'] != '':
                                email = request.POST['email']
                            else:
                                return bad_json(
                                    message='Please enter a valid email')

                            if 'phone' in request.POST and request.POST[
                                    'phone'] != '':
                                phone = request.POST['phone']
                            else:
                                return bad_json(
                                    message='Please enter a phone number')

                            gender = None
                            if 'genders' in request.POST and request.POST[
                                    'genders'] != '':
                                gender = int(request.POST['genders'])

                            if Users.objects.filter(
                                    type=USERS_GROUP_CUSTOMERS,
                                    phone=phone).exclude(
                                        id=customer.id).exists():
                                return bad_json(
                                    message=
                                    'A customer already exist with that phone number'
                                )

                            if Users.objects.filter(
                                    type=USERS_GROUP_CUSTOMERS,
                                    user__email=email).exclude(
                                        id=customer.id).exists():
                                return bad_json(
                                    message=
                                    'A customer already exist with that email')

                            django_user = customer.user
                            django_user.first_name = first_name
                            django_user.last_name = last_name
                            django_user.email = email
                            django_user.username = email
                            django_user.save()

                            customer.phone = phone
                            customer.gender = gender
                            customer.save()

                            return ok_json(
                                data={
                                    'message':
                                    'A customer has been successfully edited!'
                                })

                        return bad_json(message="Customer does not exist")
                except Exception as ex:
                    return bad_json(error=1)

            if action == 'delete':
                try:
                    with transaction.atomic():

                        if 'eid' in request.POST and Users.objects.filter(
                                pk=int(request.POST['eid'])).exists():
                            customer = Users.objects.get(
                                pk=int(request.POST['eid']))
                            django_user = customer.user
                            customer.delete()
                            django_user.delete()
                            return ok_json(
                                data={
                                    'message':
                                    'A customer has been successfully deleted!'
                                })

                        return bad_json(message="Customer does not exist")
                except Exception as ex:
                    return bad_json(error=1)

            return bad_json(error=0)
    else:

        if 'action' in request.GET:
            action = request.GET['action']

            if action == 'get_customer_data':
                try:
                    if 'eid' in request.GET and Users.objects.filter(
                            pk=int(request.GET['eid'])).exists():
                        customer = Users.objects.get(
                            pk=int(request.GET['eid']))
                        return ok_json(
                            data={
                                'first_name': customer.user.first_name,
                                'last_name': customer.user.last_name,
                                'email': customer.user.email,
                                'phone': customer.phone,
                                'gender': customer.gender
                            })

                    return bad_json(message="Customer does not exist")
                except Exception as ex:
                    return bad_json(message=ex.__str__())

    data['customers'] = Users.objects.filter(
        type=USERS_GROUP_CUSTOMERS, usercompany__company=data['company'])
    return render(request, "customers.html", data)
Exemple #11
0
def view(request):
    data = {'title': 'Sabadiaz Jewelry - Our Products'}
    addUserData(request, data)

    products = Product.objects.filter(stock__gt=0)

    category_ids = None
    if 'c' in request.GET and request.GET['c']:
        category_ids = [int(x) for x in request.GET['c'].split(',')]

    material_ids = None
    if 'm' in request.GET and request.GET['m']:
        material_ids = [int(x) for x in request.GET['m'].split(',')]

    gender_ids = None
    if 'g' in request.GET and request.GET['g']:
        gender_ids = [int(x) for x in request.GET['g'].split(',')]

    is_new = False
    if 'cn' in request.GET and request.GET['cn'] == 'true':
        is_new = True

    is_featured = False
    if 'cf' in request.GET and request.GET['cf'] == 'true':
        is_featured = True

    is_bestseller = False
    if 'cb' in request.GET and request.GET['cb'] == 'true':
        is_bestseller = True

    price_range = None
    if 'p' in request.GET and request.GET['p']:
        price_range = request.GET['p'].strip().replace('$', '').split(',')

    if category_ids:
        products = products.filter(category_id__in=category_ids)

    if material_ids:
        products = products.filter(material_id__in=material_ids)

    if gender_ids:
        products = products.filter(gender_id__in=gender_ids)

    if is_new:
        products = products.filter(is_new=True)

    if is_featured:
        products = products.filter(is_featured=True)

    if is_bestseller:
        products = products.filter(is_bestseller=True)

    if price_range:
        products = products.filter(price__gte=float(price_range[0]),
                                   price__lte=float(price_range[1]))

    page = request.GET.get('page', 1)

    paginator = Paginator(products, 12)
    try:
        products = paginator.page(page)
    except PageNotAnInteger:
        products = paginator.page(1)
    except EmptyPage:
        products = paginator.page(paginator.num_pages)

    data['products'] = products

    data['option'] = 'products'
    data['current_page'] = 'Our Products'
    data['categories'] = Category.objects.filter(
        product__stock__gt=0).distinct().order_by('id')
    data['materials'] = Material.objects.filter(
        product__stock__gt=0).distinct().order_by('id')
    data['genders'] = Gender.objects.filter(
        product__stock__gt=0).distinct().order_by('id')
    data['category_ids'] = category_ids
    data['gender_ids'] = gender_ids
    data['material_ids'] = material_ids
    data['is_new'] = is_new
    data['is_featured'] = is_featured
    data['is_bestseller'] = is_bestseller
    data['products'] = products
    return render(request, 'site/products.html', data)
def views(request):
    data = {'title': 'Work Types'}
    addUserData(request, data)

    if request.method == 'POST':
        if 'action' in request.POST:
            action = request.POST['action']

            if action == 'add':
                try:
                    with transaction.atomic():

                        if 'worktype_name' in request.POST and request.POST[
                                'worktype_name'] != '':
                            name = request.POST['worktype_name']
                        else:
                            return bad_json(message='Please enter a work type')

                        work_type = WorkType(company=data['company'],
                                             name=name)
                        work_type.save()

                        return ok_json(
                            data={
                                'message':
                                'A work type has been successfully created!'
                            })

                except Exception as ex:
                    return bad_json(error=1)

            if action == 'edit':
                try:
                    with transaction.atomic():

                        if 'eid' in request.POST and WorkType.objects.filter(
                                pk=int(request.POST['eid'])).exists():
                            work_type = WorkType.objects.get(
                                pk=int(request.POST['eid']))

                            if 'worktype_name' in request.POST and request.POST[
                                    'worktype_name'] != '':
                                name = request.POST['worktype_name']
                            else:
                                return bad_json(
                                    message='Please enter a work type')

                            if WorkType.objects.filter(
                                    name=name,
                                    company=data['company']).exclude(
                                        id=work_type.id).exists():
                                return bad_json(
                                    message=
                                    'A work type already exist with that name')

                            work_type.name = name
                            work_type.save()

                            return ok_json(
                                data={
                                    'message':
                                    'A project has been successfully edited!'
                                })

                        return bad_json(message="Project does not exist")
                except Exception as ex:
                    return bad_json(error=1)

            if action == 'delete':
                try:
                    with transaction.atomic():

                        if 'eid' in request.POST and WorkType.objects.filter(
                                pk=int(request.POST['eid'])).exists():
                            work_type = WorkType.objects.get(
                                pk=int(request.POST['eid']))
                            work_type.delete()
                            return ok_json(
                                data={
                                    'message':
                                    'A work type has been successfully deleted!'
                                })

                        return bad_json(message="Project does not exist")
                except Exception as ex:
                    return bad_json(error=1)

            return bad_json(error=0)
    else:

        if 'action' in request.GET:
            action = request.GET['action']

            if action == 'get_work_type_data':
                try:
                    if 'eid' in request.GET and WorkType.objects.filter(
                            pk=int(request.GET['eid'])).exists():
                        work_type = WorkType.objects.get(
                            pk=int(request.GET['eid']))
                        return ok_json(data={'worktype_name': work_type.name})

                    return bad_json(message="Work Type does not exist")
                except Exception as ex:
                    return bad_json(message=ex.__str__())

    data['work_types'] = WorkType.objects.filter(company=data['company'])
    return render(request, "work_types.html", data)