-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
suyog ojha
committed
Jun 2, 2022
0 parents
commit cb53565
Showing
90 changed files
with
750 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2020-2022 Suyog Ojha | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
code: S4nUhruExwA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pytest_plugins = [ | ||
"ecommerce.tests.inventory_fixtures", | ||
"ecommerce.tests.api_client", | ||
"ecommerce.tests.c_client", | ||
] |
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
ASGI config for ecommerce project. | ||
It exposes the ASGI callable as a module-level variable named ``application``. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/4.0/howto/deployment/asgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.asgi import get_asgi_application | ||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ecommerce.settings') | ||
|
||
application = get_asgi_application() |
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class DemoConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "ecommerce.demo" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[ | ||
{ "model": "auth.user", | ||
"pk": 1, | ||
"fields":{ | ||
"username": "admin", | ||
"password": "pbkdf2_sha256$260000$KfZ2hspAeA8KhAAJ8mKpjw$60ajS7y4Fw72yg+DzZQADfUsUs4l3MJuhABupfjQ3z0=", | ||
"email": "[email protected]", | ||
"is_superuser": true, | ||
"is_staff": true, | ||
"is_active": true | ||
} | ||
} | ||
] |
Binary file added
BIN
+685 Bytes
ecommerce/demo/management/commands/__pycache__/demo-fixtures.cpython-39.pyc
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django.core.management import call_command | ||
from django.core.management.base import BaseCommand | ||
|
||
|
||
class Command(BaseCommand): | ||
def handle(self, *args, **kwargs): | ||
call_command("makemigrations") | ||
call_command("migrate") | ||
call_command("loaddata", "db_admin_fixture.json") |
Empty file.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.db import models | ||
|
||
# Create your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.shortcuts import render | ||
|
||
# Create your views here. |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from django.shortcuts import get_object_or_404 | ||
from ninja import NinjaAPI, Form, File | ||
from ninja.files import UploadedFile | ||
from .schema import CategorySchema, ProductSchema | ||
from ecommerce.inventory.models import Category, Product, Media | ||
from typing import List | ||
from django.shortcuts import get_object_or_404 | ||
|
||
api = NinjaAPI() | ||
|
||
@api.post("/inventory/category") | ||
def post_category(request, data: CategorySchema): | ||
qs = Category.objects.create(**data.dict()) | ||
return {"name":qs.name} | ||
|
||
@api.post("/inventory/product") | ||
def post_product(request, data: ProductSchema): | ||
qs = Product.objects.create(**data.dict()) | ||
return {"name": qs.name} | ||
|
||
@api.get("inventory/category/all/", response=List[CategorySchema]) | ||
def get_category_list(request): | ||
qs = Category.objects.all() | ||
return qs | ||
|
||
@api.get("/inventory/products/category/{category_slug}", response=List[ProductSchema]) | ||
def get_product_by_category(request, category_slug: str): | ||
qs = Product.objects.filter(category__slug=category_slug) | ||
return qs | ||
|
||
@api.put("/inventory/category/{category_id}") | ||
def update_category(request, category_id: int, payload: CategorySchema): | ||
category = get_object_or_404(Category, id=category_id) | ||
for attr, value in payload.dict().items(): | ||
if value: | ||
setattr(category, attr, value) | ||
category.save() | ||
return {"Success": True} | ||
|
||
@api.delete("/category/{cat_id}") | ||
def delete_cat(request, cat_id: int): | ||
category = get_object_or_404(Category, id=cat_id) | ||
category.delete() | ||
return {"Success": True} | ||
|
||
@api.post("inventory/category/form/") | ||
def post_category_form(request, form: CategorySchema = Form(...)): | ||
category = Category.objects.create(**form.dict()) | ||
return {"name": category.name} | ||
|
||
@api.post("inventory/category/form/params/") | ||
def post_category_form_params(request, name: str = Form(...), slug: str = Form(...)): | ||
category = Category.objects.create(name=name, slug=slug) | ||
return {"name": category.name} | ||
|
||
@api.post("/upload/media") | ||
def upload_media(request, prod_id: int = Form(...), file: UploadedFile = File(...)): | ||
product = get_object_or_404(Product, id=prod_id) | ||
media = Media.objects.create(product_inventory=product, img_url=file) | ||
return {"id": media.id} | ||
|
||
@api.post("/upload/media/multiple") | ||
def upload_media_multiple(request, prod_id: int = Form(...), files: List[UploadedFile] = File(...)): | ||
product = get_object_or_404(Product, id=prod_id) | ||
|
||
for img in files: | ||
Media.objects.create(product_inventory=product, img_url=img) | ||
|
||
return {"success": True} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from ninja import Schema, ModelSchema | ||
|
||
from ecommerce.inventory.models import Product | ||
|
||
class CategorySchema(Schema): | ||
name: str | ||
slug: str | ||
|
||
class ProductSchema(ModelSchema): | ||
class Config: | ||
model = Product | ||
model_fields = ["name", "web_id", "category"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.urls import path | ||
from ecommerce.dninja.api import api | ||
|
||
urlpatterns = [ | ||
path("", api.urls) | ||
] |
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.contrib import admin | ||
from . import models | ||
|
||
|
||
admin.site.register(models.Category) | ||
admin.site.register(models.Product) | ||
admin.site.register(models.Media) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class InventoryConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "ecommerce.inventory" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Generated by Django 4.0.3 on 2022-03-15 14:29 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import mptt.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Category', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=100)), | ||
('slug', models.SlugField(max_length=150, unique=True)), | ||
('is_active', models.BooleanField(default=False)), | ||
('lft', models.PositiveIntegerField(editable=False)), | ||
('rght', models.PositiveIntegerField(editable=False)), | ||
('tree_id', models.PositiveIntegerField(db_index=True, editable=False)), | ||
('level', models.PositiveIntegerField(editable=False)), | ||
('parent', mptt.fields.TreeForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='children', to='inventory.category')), | ||
], | ||
options={ | ||
'verbose_name_plural': 'categories', | ||
'ordering': ['name'], | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='Product', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('web_id', models.CharField(max_length=50, unique=True)), | ||
('slug', models.SlugField(max_length=255)), | ||
('name', models.CharField(max_length=255)), | ||
('description', models.TextField(blank=True)), | ||
('is_active', models.BooleanField(default=False)), | ||
('created_at', models.DateTimeField(auto_now_add=True)), | ||
('updated_at', models.DateTimeField(auto_now=True)), | ||
('category', models.ForeignKey(blank=True, default=1, null=True, on_delete=django.db.models.deletion.SET_DEFAULT, related_name='product', to='inventory.category')), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='Media', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('img_url', models.ImageField(upload_to='images/')), | ||
('alt_text', models.CharField(max_length=255)), | ||
('is_feature', models.BooleanField(default=False)), | ||
('created_at', models.DateTimeField(auto_now_add=True)), | ||
('updated_at', models.DateTimeField(auto_now=True)), | ||
('product_inventory', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='media', to='inventory.product')), | ||
], | ||
), | ||
] |
Empty file.
Binary file added
BIN
+1.91 KB
ecommerce/inventory/migrations/__pycache__/0001_initial.cpython-310.pyc
Binary file not shown.
Binary file added
BIN
+1.88 KB
ecommerce/inventory/migrations/__pycache__/0001_initial.cpython-39.pyc
Binary file not shown.
Binary file added
BIN
+878 Bytes
...ory/migrations/__pycache__/0002_alter_media_img_url_alter_product_category.cpython-39.pyc
Binary file not shown.
Binary file added
BIN
+198 Bytes
ecommerce/inventory/migrations/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
from django.db import models | ||
from django.utils.translation import gettext_lazy as _ | ||
from mptt.models import MPTTModel, TreeForeignKey | ||
|
||
|
||
class Category(MPTTModel): | ||
name = models.CharField( | ||
max_length=100, | ||
) | ||
slug = models.SlugField(max_length=150, unique=True) | ||
is_active = models.BooleanField( | ||
default=False, | ||
) | ||
parent = TreeForeignKey( | ||
"self", | ||
on_delete=models.PROTECT, | ||
related_name="children", | ||
null=True, | ||
blank=True, | ||
) | ||
|
||
class MPTTMeta: | ||
order_insertion_by = ["name"] | ||
|
||
class Meta: | ||
ordering = ["name"] | ||
verbose_name_plural = _("categories") | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
|
||
class Product(models.Model): | ||
web_id = models.CharField( | ||
max_length=50, | ||
unique=True, | ||
) | ||
slug = models.SlugField( | ||
max_length=255, | ||
) | ||
name = models.CharField( | ||
max_length=255, | ||
) | ||
description = models.TextField(blank=True) | ||
category = models.ForeignKey( | ||
Category, | ||
related_name="product", | ||
default=1, | ||
on_delete=models.SET_DEFAULT, | ||
null=True, | ||
blank=True, | ||
) | ||
is_active = models.BooleanField( | ||
default=False, | ||
) | ||
created_at = models.DateTimeField( | ||
auto_now_add=True, | ||
editable=False, | ||
) | ||
updated_at = models.DateTimeField( | ||
auto_now=True, | ||
) | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
|
||
class Media(models.Model): | ||
product_inventory = models.ForeignKey( | ||
Product, | ||
on_delete=models.PROTECT, | ||
related_name="media", | ||
) | ||
img_url = models.ImageField(upload_to='images/') | ||
alt_text = models.CharField( | ||
max_length=255, | ||
) | ||
is_feature = models.BooleanField( | ||
default=False, | ||
) | ||
created_at = models.DateTimeField( | ||
auto_now_add=True, | ||
editable=False, | ||
) | ||
updated_at = models.DateTimeField( | ||
auto_now=True, | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from ecommerce.inventory.models import Category | ||
|
||
|
||
def test_create_category(single_category): | ||
new_category = single_category | ||
get_category = Category.objects.all().first() | ||
assert new_category.id == get_category.id | ||
|
||
|
||
def test_create_category_with_child(category_with_child): | ||
new_sub_category = category_with_child | ||
get_category = Category.objects.all().first() | ||
assert get_category.children.first().id == new_sub_category.id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from ecommerce.inventory.models import Product | ||
|
||
|
||
def test_insert_single_product_with_sub_category(single_product): | ||
new_product = single_product | ||
get_product = Product.objects.all().first() | ||
assert new_product.id == get_product.id |
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class SearchConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "ecommerce.search" |
Oops, something went wrong.