Skip to content

Commit

Permalink
Integrate AliExpress functionality, update models, views, and settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Robocoders committed Nov 24, 2024
1 parent 7ca841e commit 3b3f58b
Show file tree
Hide file tree
Showing 47 changed files with 484 additions and 135 deletions.
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use an official Python runtime as the base image
FROM python:3.9

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set the working directory in the container
WORKDIR /app

# Copy the project files into the container
COPY . /app/

# Install project dependencies
RUN pip install --upgrade pip
RUN pip install -r requirements.txt

# Run the setup script
RUN python setup.py

# Expose the port the app runs on
EXPOSE 8000

# Start the application
CMD ["python", "dropship_project/manage.py", "runserver", "0.0.0.0:8000"]
71 changes: 41 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,54 @@
# Dropship V2

Dropship V2 is a Django-based e-commerce platform for dropshipping. It includes features for product management, user authentication, shopping cart functionality, order processing, and integration with various third-party services.
Dropship V2 is an e-commerce application built with Django.

## Key Features
## Prerequisites

1. User authentication and registration (including social auth and two-factor authentication)
2. Product listing and management
3. Shopping cart functionality
4. Checkout process with payment integration
5. Order management for administrators
6. Inventory management with stock tracking
7. Email notifications for order updates
8. Responsive design using Bootstrap
9. API with OAuth2 authentication
- Docker
- Docker Compose

## Technology Stack
## Getting Started

- Backend: Django 5.1.3
- Database: PostgreSQL
- Frontend: HTML, CSS (Bootstrap), JavaScript
- Authentication: django-allauth 65.2.0, django-two-factor-auth
- API: Django REST framework 3.15.2
- Security: django-axes 7.0.0
- OAuth2: django-oauth-toolkit 3.0.1
1. Clone the repository:
```
git clone https://github.com/CrzyHAX91/dropshipv2.git
cd dropshipv2
```

## Setup
2. Run the start script:
```
./start.sh
```

1. Clone the repository
2. Install dependencies: `pip install -r requirements.txt`
3. Set up environment variables (see `.env.example`)
4. Run migrations: `python manage.py migrate`
5. Create a superuser: `python manage.py createsuperuser`
6. Start the development server: `python manage.py runserver`
3. Access the application at http://localhost:8000

## Contributing
## Features

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests.
- Product catalog
- Shopping cart
- User authentication
- Order management

## License
## Admin Access

This project is licensed under the MIT License - see the LICENSE file for details.
To access the admin panel:

1. Go to http://localhost:8000/admin
2. Login with the following credentials:
- Username: admin
- Password: adminpassword

## Running Tests

To run the tests, use the following command:
```
docker-compose exec web python dropship_project/manage.py test
```

## Stopping the Application

To stop the application, run:
```
docker-compose down
```

27 changes: 27 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: '3.8'

services:
web:
build: .
command: python dropship_project/manage.py runserver 0.0.0.0:8000
volumes:
- .:/app
ports:
- "8000:8000"
environment:
- DEBUG=1
- DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1]
depends_on:
- db

db:
image: postgres:13
volumes:
- postgres_data:/var/lib/postgresql/data/
environment:
- POSTGRES_DB=dropship_db
- POSTGRES_USER=dropship_user
- POSTGRES_PASSWORD=dropship_password

volumes:
postgres_data:
38 changes: 14 additions & 24 deletions dropship_project/admin.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .models import CustomUser, Order, CartItem, Product
from .models import CustomUser, Product, CartItem, Order

class CustomUserAdmin(UserAdmin):
model = CustomUser
list_display = ['email', 'username', 'is_staff', 'is_active']
list_filter = ['is_staff', 'is_active']
fieldsets = UserAdmin.fieldsets + (
('Additional Info', {'fields': ('phone_number', 'address', 'date_of_birth')}),
)
add_fieldsets = UserAdmin.add_fieldsets + (
('Additional Info', {'fields': ('phone_number', 'address', 'date_of_birth')}),
)
@admin.register(CustomUser)
class CustomUserAdmin(admin.ModelAdmin):
list_display = ('username', 'email', 'phone_number')

class OrderAdmin(admin.ModelAdmin):
list_display = ['id', 'user', 'created_at', 'total_price']
list_filter = ['created_at']
@admin.register(Product)
class ProductAdmin(admin.ModelAdmin):
list_display = ('name', 'cost_price', 'selling_price', 'stock')
list_filter = ('stock',)

@admin.register(CartItem)
class CartItemAdmin(admin.ModelAdmin):
list_display = ['user', 'product', 'quantity']
list_display = ('user', 'product', 'quantity')

class ProductAdmin(admin.ModelAdmin):
list_display = ['name', 'price', 'stock']
list_filter = ['price', 'stock']

admin.site.register(CustomUser, CustomUserAdmin)
admin.site.register(Order, OrderAdmin)
admin.site.register(CartItem, CartItemAdmin)
admin.site.register(Product, ProductAdmin)
@admin.register(Order)
class OrderAdmin(admin.ModelAdmin):
list_display = ('user', 'total_price', 'created_at', 'status')
list_filter = ('status',)

47 changes: 47 additions & 0 deletions dropship_project/management/commands/add_sample_products.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from django.core.management.base import BaseCommand
from dropship_project.models import Product
from django.core.files import File
from django.conf import settings
import os

class Command(BaseCommand):
help = 'Adds sample products to the database'

def handle(self, *args, **kwargs):
products = [
{
'name': 'Laptop',
'description': 'High-performance laptop with 16GB RAM and 512GB SSD',
'price': 999.99,
'stock': 50,
'image': 'laptop.jpg'
},
{
'name': 'Smartphone',
'description': '5G-enabled smartphone with 128GB storage',
'price': 699.99,
'stock': 100,
'image': 'smartphone.jpg'
},
{
'name': 'Wireless Headphones',
'description': 'Noise-cancelling wireless headphones with 30-hour battery life',
'price': 199.99,
'stock': 200,
'image': 'headphones.jpg'
}
]

for product_data in products:
product = Product.objects.create(
name=product_data['name'],
description=product_data['description'],
price=product_data['price'],
stock=product_data['stock']
)
image_path = os.path.join(settings.BASE_DIR, 'sample_images', product_data['image'])
if os.path.exists(image_path):
with open(image_path, 'rb') as f:
product.image.save(product_data['image'], File(f), save=True)
self.stdout.write(self.style.SUCCESS(f'Successfully added product: {product.name}'))

57 changes: 57 additions & 0 deletions dropship_project/management/commands/populate_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from django.core.management.base import BaseCommand
from django.contrib.auth import get_user_model
from dropship_project.models import Product, Order, CartItem
import random

User = get_user_model()

class Command(BaseCommand):
help = 'Populate the database with sample data'

def handle(self, *args, **kwargs):
self.stdout.write('Populating database...')

# Create users
for i in range(5):
username = f'user{i}'
email = f'user{i}@example.com'
password = 'password123'
User.objects.create_user(username=username, email=email, password=password)

# Create products
products = [
{'name': 'Laptop', 'description': 'High-performance laptop', 'price': 999.99, 'stock': 50},
{'name': 'Smartphone', 'description': '5G-enabled smartphone', 'price': 699.99, 'stock': 100},
{'name': 'Headphones', 'description': 'Noise-cancelling headphones', 'price': 199.99, 'stock': 200},
{'name': 'Tablet', 'description': '10-inch tablet', 'price': 299.99, 'stock': 75},
{'name': 'Smartwatch', 'description': 'Fitness tracking smartwatch', 'price': 149.99, 'stock': 150},
]
for product in products:
Product.objects.create(**product)

# Create orders and cart items
users = User.objects.all()
products = Product.objects.all()

for user in users:
# Create an order
order = Order.objects.create(user=user, total_price=0)
total_price = 0

# Add random products to the order
for _ in range(random.randint(1, 3)):
product = random.choice(products)
quantity = random.randint(1, 3)
CartItem.objects.create(user=user, product=product, quantity=quantity, order=order)
total_price += product.price * quantity

order.total_price = total_price
order.save()

# Add random products to the cart
for _ in range(random.randint(0, 2)):
product = random.choice(products)
quantity = random.randint(1, 2)
CartItem.objects.create(user=user, product=product, quantity=quantity)

self.stdout.write(self.style.SUCCESS('Database populated successfully!'))
35 changes: 23 additions & 12 deletions dropship_project/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 3.2.10 on 2024-11-24 14:00
# Generated by Django 3.2.10 on 2024-11-24 14:37

from django.conf import settings
import django.contrib.auth.models
Expand Down Expand Up @@ -34,8 +34,8 @@ class Migration(migrations.Migration):
('phone_number', models.CharField(blank=True, max_length=15, null=True)),
('address', models.TextField(blank=True, null=True)),
('date_of_birth', models.DateField(blank=True, null=True)),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='customuser_set', related_query_name='customuser', to='auth.Group', verbose_name='groups')),
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='customuser_set', related_query_name='customuser', to='auth.Permission', verbose_name='user permissions')),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')),
],
options={
'verbose_name': 'user',
Expand All @@ -46,31 +46,42 @@ class Migration(migrations.Migration):
('objects', django.contrib.auth.models.UserManager()),
],
),
migrations.CreateModel(
name='CartItem',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('quantity', models.PositiveIntegerField(default=1)),
],
),
migrations.CreateModel(
name='Product',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200)),
('description', models.TextField()),
('price', models.DecimalField(decimal_places=2, max_digits=10)),
('stock', models.PositiveIntegerField()),
('image', models.ImageField(blank=True, null=True, upload_to='products/')),
],
),
migrations.CreateModel(
name='Order',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('total_price', models.DecimalField(decimal_places=2, max_digits=10)),
('created_at', models.DateTimeField(auto_now_add=True)),
('items', models.ManyToManyField(to='dropship_project.CartItem')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='CartItem',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('quantity', models.PositiveIntegerField(default=1)),
('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dropship_project.product')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
migrations.AddField(
model_name='cartitem',
name='product',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dropship_project.product'),
),
migrations.AddField(
model_name='cartitem',
name='user',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
]
Loading

0 comments on commit 3b3f58b

Please sign in to comment.