Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fe4c03a06a | ||
|
|
fc0fcfb24f | ||
|
|
7cf53e9789 | ||
|
|
3ac9a74fa1 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,3 +1,8 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
from .models import UserProfile, Category, Product, Order, OrderItem
|
||||||
|
|
||||||
# Register your models here.
|
admin.site.register(UserProfile)
|
||||||
|
admin.site.register(Category)
|
||||||
|
admin.site.register(Product)
|
||||||
|
admin.site.register(Order)
|
||||||
|
admin.site.register(OrderItem)
|
||||||
67
core/migrations/0001_initial.py
Normal file
67
core/migrations/0001_initial.py
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
# Generated by Django 5.2.7 on 2026-03-13 07:23
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
]
|
||||||
|
|
||||||
|
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(unique=True)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Order',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('status', models.CharField(choices=[('pending', 'Pending'), ('shipped', 'Shipped'), ('delivered', 'Delivered')], default='pending', max_length=20)),
|
||||||
|
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||||
|
('buyer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='orders', to=settings.AUTH_USER_MODEL)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
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.IntegerField(default=0)),
|
||||||
|
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||||
|
('category', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='products', to='core.category')),
|
||||||
|
('seller', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='products', to=settings.AUTH_USER_MODEL)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='OrderItem',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('quantity', models.IntegerField()),
|
||||||
|
('price', models.DecimalField(decimal_places=2, max_digits=10)),
|
||||||
|
('order', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='items', to='core.order')),
|
||||||
|
('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.product')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='UserProfile',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('is_seller', models.BooleanField(default=False)),
|
||||||
|
('phone_number', models.CharField(blank=True, max_length=20)),
|
||||||
|
('address', models.TextField(blank=True)),
|
||||||
|
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
||||||
BIN
core/migrations/__pycache__/0001_initial.cpython-311.pyc
Normal file
BIN
core/migrations/__pycache__/0001_initial.cpython-311.pyc
Normal file
Binary file not shown.
@ -1,3 +1,47 @@
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
# Create your models here.
|
class UserProfile(models.Model):
|
||||||
|
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
||||||
|
is_seller = models.BooleanField(default=False)
|
||||||
|
phone_number = models.CharField(max_length=20, blank=True)
|
||||||
|
address = models.TextField(blank=True)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.user.username
|
||||||
|
|
||||||
|
class Category(models.Model):
|
||||||
|
name = models.CharField(max_length=100)
|
||||||
|
slug = models.SlugField(unique=True)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
class Product(models.Model):
|
||||||
|
seller = models.ForeignKey(User, on_delete=models.CASCADE, related_name='products')
|
||||||
|
category = models.ForeignKey(Category, on_delete=models.SET_NULL, null=True, related_name='products')
|
||||||
|
name = models.CharField(max_length=200)
|
||||||
|
description = models.TextField()
|
||||||
|
price = models.DecimalField(max_digits=10, decimal_places=2)
|
||||||
|
stock = models.IntegerField(default=0)
|
||||||
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
class Order(models.Model):
|
||||||
|
buyer = models.ForeignKey(User, on_delete=models.CASCADE, related_name='orders')
|
||||||
|
status = models.CharField(max_length=20, choices=[('pending', 'Pending'), ('shipped', 'Shipped'), ('delivered', 'Delivered')], default='pending')
|
||||||
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"Order {self.id} by {self.buyer.username}"
|
||||||
|
|
||||||
|
class OrderItem(models.Model):
|
||||||
|
order = models.ForeignKey(Order, on_delete=models.CASCADE, related_name='items')
|
||||||
|
product = models.ForeignKey(Product, on_delete=models.CASCADE)
|
||||||
|
quantity = models.IntegerField()
|
||||||
|
price = models.DecimalField(max_digits=10, decimal_places=2)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.quantity} x {self.product.name} in Order {self.order.id}"
|
||||||
38
core/templates/core/buyer_dashboard.html
Normal file
38
core/templates/core/buyer_dashboard.html
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
{% extends "core/dashboard_base.html" %}
|
||||||
|
|
||||||
|
{% block title %}Buyer Dashboard | Ethio-gebeya{% endblock %}
|
||||||
|
|
||||||
|
{% block dashboard_content %}
|
||||||
|
<section class="grid cards-3">
|
||||||
|
<article class="card">
|
||||||
|
<p class="label">Total Orders</p>
|
||||||
|
<p class="value">{{ total_orders }}</p>
|
||||||
|
</article>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="card" style="margin-top: 1rem;">
|
||||||
|
<h2 style="margin: 0 0 0.75rem;">Recent Orders</h2>
|
||||||
|
{% if recent_orders %}
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Order</th>
|
||||||
|
<th>Status</th>
|
||||||
|
<th>Date</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for order in recent_orders %}
|
||||||
|
<tr>
|
||||||
|
<td>#{{ order.id }}</td>
|
||||||
|
<td>{{ order.get_status_display }}</td>
|
||||||
|
<td>{{ order.created_at|date:"Y-m-d" }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{% else %}
|
||||||
|
<p>No orders yet.</p>
|
||||||
|
{% endif %}
|
||||||
|
</section>
|
||||||
|
{% endblock %}
|
||||||
47
core/templates/core/cart.html
Normal file
47
core/templates/core/cart.html
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}Shopping Cart | Ethio-gebeya{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<main class="container py-4">
|
||||||
|
<h1 class="mb-4">Shopping Cart</h1>
|
||||||
|
|
||||||
|
{% if items %}
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Product</th>
|
||||||
|
<th>Quantity</th>
|
||||||
|
<th>Price</th>
|
||||||
|
<th>Subtotal</th>
|
||||||
|
<th>Action</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for item in items %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ item.product.name }}</td>
|
||||||
|
<td>{{ item.quantity }}</td>
|
||||||
|
<td>{{ item.product.price }} ETB</td>
|
||||||
|
<td>{{ item.subtotal }} ETB</td>
|
||||||
|
<td><a href="{% url 'remove_from_cart' item.product.pk %}" class="btn btn-danger btn-sm">Remove</a></td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<div class="mt-3">
|
||||||
|
<h4>Total: {{ total_price }} ETB</h4>
|
||||||
|
<form method="post" action="{% url 'checkout' %}">
|
||||||
|
{% csrf_token %}
|
||||||
|
<button type="submit" class="btn btn-primary">Proceed to Checkout</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<p>Your cart is empty.</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<div class="mt-4">
|
||||||
|
<a href="{% url 'home' %}" class="btn btn-secondary">Continue Shopping</a>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
{% endblock %}
|
||||||
159
core/templates/core/dashboard_base.html
Normal file
159
core/templates/core/dashboard_base.html
Normal file
@ -0,0 +1,159 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block head %}
|
||||||
|
<style>
|
||||||
|
:root {
|
||||||
|
--bg: #f8fafc;
|
||||||
|
--text: #0f172a;
|
||||||
|
--muted: #64748b;
|
||||||
|
--surface: #ffffff;
|
||||||
|
--border: #e2e8f0;
|
||||||
|
--primary: #ea580c;
|
||||||
|
}
|
||||||
|
|
||||||
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
font-family: Inter, "Segoe UI", sans-serif;
|
||||||
|
background: var(--bg);
|
||||||
|
color: var(--text);
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout {
|
||||||
|
min-height: 100vh;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 250px 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar {
|
||||||
|
background: #0f172a;
|
||||||
|
color: #f8fafc;
|
||||||
|
padding: 1.25rem 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand {
|
||||||
|
font-size: 1.2rem;
|
||||||
|
font-weight: 700;
|
||||||
|
margin: 0 0 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu a {
|
||||||
|
display: block;
|
||||||
|
text-decoration: none;
|
||||||
|
color: #cbd5e1;
|
||||||
|
padding: 0.65rem 0.75rem;
|
||||||
|
border-radius: 10px;
|
||||||
|
margin-bottom: 0.4rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu a.active,
|
||||||
|
.menu a:hover {
|
||||||
|
color: #fff;
|
||||||
|
background: rgba(255, 255, 255, 0.12);
|
||||||
|
}
|
||||||
|
|
||||||
|
.content-wrap {
|
||||||
|
padding: 1.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topbar {
|
||||||
|
background: var(--surface);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 14px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: 0.85rem 1rem;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topbar h1 {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 1.2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.logout {
|
||||||
|
text-decoration: none;
|
||||||
|
background: #fff7ed;
|
||||||
|
color: var(--primary);
|
||||||
|
border: 1px solid #fdba74;
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 0.5rem 0.75rem;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid {
|
||||||
|
display: grid;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cards-3 {
|
||||||
|
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||||
|
}
|
||||||
|
|
||||||
|
.card {
|
||||||
|
background: var(--surface);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 14px;
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.label {
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: 0.9rem;
|
||||||
|
margin-bottom: 0.35rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.value {
|
||||||
|
font-size: 1.5rem;
|
||||||
|
font-weight: 700;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
width: 100%;
|
||||||
|
border-collapse: collapse;
|
||||||
|
}
|
||||||
|
|
||||||
|
th,
|
||||||
|
td {
|
||||||
|
text-align: left;
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
padding: 0.65rem 0.4rem;
|
||||||
|
font-size: 0.92rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 900px) {
|
||||||
|
.layout {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cards-3 {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="layout">
|
||||||
|
<aside class="sidebar">
|
||||||
|
<p class="brand">Ethio-gebeya</p>
|
||||||
|
<nav class="menu">
|
||||||
|
<a href="{% url 'buyer_dashboard' %}" class="{% if active_tab == 'buyer' %}active{% endif %}">Buyer Dashboard</a>
|
||||||
|
<a href="{% url 'seller_dashboard' %}" class="{% if active_tab == 'seller' %}active{% endif %}">Seller Dashboard</a>
|
||||||
|
<a href="{% url 'home' %}">Home</a>
|
||||||
|
</nav>
|
||||||
|
</aside>
|
||||||
|
<main class="content-wrap">
|
||||||
|
<header class="topbar">
|
||||||
|
<h1>{{ dashboard_title }}</h1>
|
||||||
|
<a class="logout" href="{% url 'logout' %}">Sign Out</a>
|
||||||
|
</header>
|
||||||
|
{% block dashboard_content %}{% endblock %}
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
@ -1,145 +1,34 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block title %}{{ project_name }}{% endblock %}
|
{% block title %}Ethio-gebeya | Marketplace{% endblock %}
|
||||||
|
|
||||||
{% block head %}
|
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
|
|
||||||
<style>
|
|
||||||
:root {
|
|
||||||
--bg-color-start: #6a11cb;
|
|
||||||
--bg-color-end: #2575fc;
|
|
||||||
--text-color: #ffffff;
|
|
||||||
--card-bg-color: rgba(255, 255, 255, 0.01);
|
|
||||||
--card-border-color: rgba(255, 255, 255, 0.1);
|
|
||||||
}
|
|
||||||
|
|
||||||
* {
|
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
|
||||||
margin: 0;
|
|
||||||
font-family: 'Inter', sans-serif;
|
|
||||||
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
|
|
||||||
color: var(--text-color);
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
min-height: 100vh;
|
|
||||||
text-align: center;
|
|
||||||
overflow: hidden;
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
|
|
||||||
body::before {
|
|
||||||
content: '';
|
|
||||||
position: absolute;
|
|
||||||
inset: 0;
|
|
||||||
background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' viewBox='0 0 100 100'><path d='M-10 10L110 10M10 -10L10 110' stroke-width='1' stroke='rgba(255,255,255,0.05)'/></svg>");
|
|
||||||
animation: bg-pan 20s linear infinite;
|
|
||||||
z-index: -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes bg-pan {
|
|
||||||
0% {
|
|
||||||
background-position: 0% 0%;
|
|
||||||
}
|
|
||||||
|
|
||||||
100% {
|
|
||||||
background-position: 100% 100%;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
main {
|
|
||||||
padding: 2rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.card {
|
|
||||||
background: var(--card-bg-color);
|
|
||||||
border: 1px solid var(--card-border-color);
|
|
||||||
border-radius: 16px;
|
|
||||||
padding: 2.5rem 2rem;
|
|
||||||
backdrop-filter: blur(20px);
|
|
||||||
-webkit-backdrop-filter: blur(20px);
|
|
||||||
box-shadow: 0 12px 36px rgba(0, 0, 0, 0.25);
|
|
||||||
}
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
font-size: clamp(2.2rem, 3vw + 1.2rem, 3.2rem);
|
|
||||||
font-weight: 700;
|
|
||||||
margin: 0 0 1.2rem;
|
|
||||||
letter-spacing: -0.02em;
|
|
||||||
}
|
|
||||||
|
|
||||||
p {
|
|
||||||
margin: 0.5rem 0;
|
|
||||||
font-size: 1.1rem;
|
|
||||||
opacity: 0.92;
|
|
||||||
}
|
|
||||||
|
|
||||||
.loader {
|
|
||||||
margin: 1.5rem auto;
|
|
||||||
width: 56px;
|
|
||||||
height: 56px;
|
|
||||||
border: 4px solid rgba(255, 255, 255, 0.25);
|
|
||||||
border-top-color: #fff;
|
|
||||||
border-radius: 50%;
|
|
||||||
animation: spin 1s linear infinite;
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes spin {
|
|
||||||
to {
|
|
||||||
transform: rotate(360deg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.runtime code {
|
|
||||||
background: rgba(0, 0, 0, 0.25);
|
|
||||||
padding: 0.15rem 0.45rem;
|
|
||||||
border-radius: 4px;
|
|
||||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
||||||
}
|
|
||||||
|
|
||||||
.sr-only {
|
|
||||||
position: absolute;
|
|
||||||
width: 1px;
|
|
||||||
height: 1px;
|
|
||||||
padding: 0;
|
|
||||||
margin: -1px;
|
|
||||||
overflow: hidden;
|
|
||||||
clip: rect(0, 0, 0, 0);
|
|
||||||
border: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
footer {
|
|
||||||
position: absolute;
|
|
||||||
bottom: 1rem;
|
|
||||||
width: 100%;
|
|
||||||
text-align: center;
|
|
||||||
font-size: 0.85rem;
|
|
||||||
opacity: 0.75;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<main>
|
<main class="container py-4">
|
||||||
<div class="card">
|
<h1 class="mb-4">Welcome to Ethio-gebeya</h1>
|
||||||
<h1>Analyzing your requirements and generating your app…</h1>
|
|
||||||
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
|
<div class="row">
|
||||||
<span class="sr-only">Loading…</span>
|
{% for product in products %}
|
||||||
|
<div class="col-md-4 mb-4">
|
||||||
|
<div class="card h-100">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">{{ product.name }}</h5>
|
||||||
|
<p class="card-text text-muted">{{ product.description|truncatewords:20 }}</p>
|
||||||
|
<p class="card-text fw-bold">Price: {{ product.price }} ETB</p>
|
||||||
|
<a href="{% url 'product_detail' product.pk %}" class="btn btn-primary">View Details</a>
|
||||||
|
<a href="{% url 'add_to_cart' product.pk %}" class="btn btn-success">Add to Cart</a>
|
||||||
</div>
|
</div>
|
||||||
<p class="hint">AppWizzy AI is collecting your requirements and applying the first changes.</p>
|
</div>
|
||||||
<p class="hint">This page will refresh automatically as the plan is implemented.</p>
|
</div>
|
||||||
<p class="runtime">
|
{% endfor %}
|
||||||
Runtime: Django <code>{{ django_version }}</code> · Python <code>{{ python_version }}</code>
|
</div>
|
||||||
— UTC <code>{{ current_time|date:"Y-m-d H:i:s" }}</code>
|
|
||||||
</p>
|
<div class="mt-4">
|
||||||
|
{% if user.is_authenticated %}
|
||||||
|
<a class="btn btn-secondary" href="{% url 'dashboard' %}">Open Dashboard</a>
|
||||||
|
{% else %}
|
||||||
|
<a class="btn btn-primary" href="{% url 'login' %}">Sign In</a>
|
||||||
|
{% endif %}
|
||||||
|
<a class="btn btn-info" href="{% url 'cart_view' %}">View Cart</a>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
<footer>
|
|
||||||
Page updated: {{ current_time|date:"Y-m-d H:i:s" }} (UTC)
|
|
||||||
</footer>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
67
core/templates/core/login.html
Normal file
67
core/templates/core/login.html
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}Sign In | Ethio-gebeya{% endblock %}
|
||||||
|
|
||||||
|
{% block head %}
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
font-family: Inter, "Segoe UI", sans-serif;
|
||||||
|
background: #f8fafc;
|
||||||
|
}
|
||||||
|
|
||||||
|
main {
|
||||||
|
min-height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 430px;
|
||||||
|
background: #fff;
|
||||||
|
border: 1px solid #e2e8f0;
|
||||||
|
border-radius: 16px;
|
||||||
|
padding: 1.4rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
input {
|
||||||
|
width: 100%;
|
||||||
|
border: 1px solid #cbd5e1;
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 0.6rem 0.7rem;
|
||||||
|
margin-bottom: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
width: 100%;
|
||||||
|
border: 0;
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 0.7rem;
|
||||||
|
background: #ea580c;
|
||||||
|
color: #fff;
|
||||||
|
font-weight: 700;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.errorlist {
|
||||||
|
color: #b91c1c;
|
||||||
|
margin: 0 0 0.5rem;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<main>
|
||||||
|
<section class="card">
|
||||||
|
<h1 style="margin-top: 0;">Sign in</h1>
|
||||||
|
<form method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form.as_p }}
|
||||||
|
<button type="submit">Continue</button>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
{% endblock %}
|
||||||
21
core/templates/core/product_detail.html
Normal file
21
core/templates/core/product_detail.html
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}{{ product.name }} | Ethio-gebeya{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<main class="container py-4">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-8">
|
||||||
|
<h1 class="mb-3">{{ product.name }}</h1>
|
||||||
|
<p class="text-muted">{{ product.description }}</p>
|
||||||
|
<p class="h4 text-primary">Price: {{ product.price }} ETB</p>
|
||||||
|
<p>Stock: {{ product.stock }}</p>
|
||||||
|
|
||||||
|
<a href="{% url 'add_to_cart' product.pk %}" class="btn btn-primary btn-lg">Add to Cart</a>
|
||||||
|
|
||||||
|
<a href="{% url 'home' %}" class="btn btn-link mt-3">Back to catalog</a>
|
||||||
|
<a href="{% url 'cart_view' %}" class="btn btn-info mt-3">View Cart</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
{% endblock %}
|
||||||
48
core/templates/core/seller_dashboard.html
Normal file
48
core/templates/core/seller_dashboard.html
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
{% extends "core/dashboard_base.html" %}
|
||||||
|
|
||||||
|
{% block title %}Seller Dashboard | Ethio-gebeya{% endblock %}
|
||||||
|
|
||||||
|
{% block dashboard_content %}
|
||||||
|
<section class="grid cards-3">
|
||||||
|
<article class="card">
|
||||||
|
<p class="label">Products</p>
|
||||||
|
<p class="value">{{ product_count }}</p>
|
||||||
|
</article>
|
||||||
|
<article class="card">
|
||||||
|
<p class="label">Orders</p>
|
||||||
|
<p class="value">{{ total_orders }}</p>
|
||||||
|
</article>
|
||||||
|
<article class="card">
|
||||||
|
<p class="label">Revenue</p>
|
||||||
|
<p class="value">${{ total_revenue }}</p>
|
||||||
|
</article>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="card" style="margin-top: 1rem;">
|
||||||
|
<h2 style="margin: 0 0 0.75rem;">Recent Sales</h2>
|
||||||
|
{% if recent_sales %}
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Buyer</th>
|
||||||
|
<th>Product</th>
|
||||||
|
<th>Qty</th>
|
||||||
|
<th>Total</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for sale in recent_sales %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ sale.order.buyer.username }}</td>
|
||||||
|
<td>{{ sale.product.name }}</td>
|
||||||
|
<td>{{ sale.quantity }}</td>
|
||||||
|
<td>${{ sale.price }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{% else %}
|
||||||
|
<p>No sales yet.</p>
|
||||||
|
{% endif %}
|
||||||
|
</section>
|
||||||
|
{% endblock %}
|
||||||
23
core/urls.py
23
core/urls.py
@ -1,7 +1,28 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
from django.contrib.auth.views import LoginView, LogoutView
|
||||||
|
|
||||||
from .views import home
|
from .views import (
|
||||||
|
add_to_cart,
|
||||||
|
buyer_dashboard,
|
||||||
|
cart_view,
|
||||||
|
checkout,
|
||||||
|
dashboard_redirect,
|
||||||
|
home,
|
||||||
|
product_detail,
|
||||||
|
remove_from_cart,
|
||||||
|
seller_dashboard,
|
||||||
|
)
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", home, name="home"),
|
path("", home, name="home"),
|
||||||
|
path("product/<int:pk>/", product_detail, name="product_detail"),
|
||||||
|
path("login/", LoginView.as_view(template_name="core/login.html"), name="login"),
|
||||||
|
path("logout/", LogoutView.as_view(next_page="home"), name="logout"),
|
||||||
|
path("dashboard/", dashboard_redirect, name="dashboard"),
|
||||||
|
path("dashboard/buyer/", buyer_dashboard, name="buyer_dashboard"),
|
||||||
|
path("dashboard/seller/", seller_dashboard, name="seller_dashboard"),
|
||||||
|
path("cart/", cart_view, name="cart_view"),
|
||||||
|
path("cart/add/<int:pk>/", add_to_cart, name="add_to_cart"),
|
||||||
|
path("cart/remove/<int:pk>/", remove_from_cart, name="remove_from_cart"),
|
||||||
|
path("checkout/", checkout, name="checkout"),
|
||||||
]
|
]
|
||||||
145
core/views.py
145
core/views.py
@ -2,24 +2,145 @@ import os
|
|||||||
import platform
|
import platform
|
||||||
|
|
||||||
from django import get_version as django_version
|
from django import get_version as django_version
|
||||||
from django.shortcuts import render
|
from django.contrib.auth.decorators import login_required
|
||||||
|
from django.db import transaction
|
||||||
|
from django.db.models import Count, DecimalField, ExpressionWrapper, F, Sum
|
||||||
|
from django.shortcuts import get_object_or_404, redirect, render
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
|
from .models import Order, OrderItem, Product
|
||||||
|
|
||||||
|
|
||||||
def home(request):
|
def home(request):
|
||||||
"""Render the landing screen with loader and environment details."""
|
"""Render the product catalog landing page."""
|
||||||
host_name = request.get_host().lower()
|
products = Product.objects.all().order_by('-created_at')
|
||||||
agent_brand = "AppWizzy" if host_name == "appwizzy.com" else "Flatlogic"
|
|
||||||
now = timezone.now()
|
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
"project_name": "New Style",
|
"products": products,
|
||||||
"agent_brand": agent_brand,
|
|
||||||
"django_version": django_version(),
|
"django_version": django_version(),
|
||||||
"python_version": platform.python_version(),
|
|
||||||
"current_time": now,
|
|
||||||
"host_name": host_name,
|
|
||||||
"project_description": os.getenv("PROJECT_DESCRIPTION", ""),
|
|
||||||
"project_image_url": os.getenv("PROJECT_IMAGE_URL", ""),
|
|
||||||
}
|
}
|
||||||
return render(request, "core/index.html", context)
|
return render(request, "core/index.html", context)
|
||||||
|
|
||||||
|
|
||||||
|
def product_detail(request, pk):
|
||||||
|
product = get_object_or_404(Product, pk=pk)
|
||||||
|
return render(request, "core/product_detail.html", {"product": product})
|
||||||
|
|
||||||
|
|
||||||
|
def _is_seller(user):
|
||||||
|
return hasattr(user, "userprofile") and user.userprofile.is_seller
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def dashboard_redirect(request):
|
||||||
|
if _is_seller(request.user):
|
||||||
|
return redirect("seller_dashboard")
|
||||||
|
return redirect("buyer_dashboard")
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def buyer_dashboard(request):
|
||||||
|
if _is_seller(request.user):
|
||||||
|
return redirect("seller_dashboard")
|
||||||
|
|
||||||
|
recent_orders = (
|
||||||
|
Order.objects.filter(buyer=request.user)
|
||||||
|
.prefetch_related("items__product")
|
||||||
|
.order_by("-created_at")[:5]
|
||||||
|
)
|
||||||
|
total_orders = Order.objects.filter(buyer=request.user).count()
|
||||||
|
|
||||||
|
context = {
|
||||||
|
"dashboard_title": "Buyer Dashboard",
|
||||||
|
"active_tab": "buyer",
|
||||||
|
"recent_orders": recent_orders,
|
||||||
|
"total_orders": total_orders,
|
||||||
|
}
|
||||||
|
return render(request, "core/buyer_dashboard.html", context)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def seller_dashboard(request):
|
||||||
|
if not _is_seller(request.user):
|
||||||
|
return redirect("buyer_dashboard")
|
||||||
|
|
||||||
|
seller_products = Product.objects.filter(seller=request.user)
|
||||||
|
sales_expression = ExpressionWrapper(
|
||||||
|
F("quantity") * F("price"), output_field=DecimalField(max_digits=12, decimal_places=2)
|
||||||
|
)
|
||||||
|
sales_summary = OrderItem.objects.filter(product__seller=request.user).aggregate(
|
||||||
|
total_items=Sum("quantity"),
|
||||||
|
total_revenue=Sum(sales_expression),
|
||||||
|
total_orders=Count("order", distinct=True),
|
||||||
|
)
|
||||||
|
recent_sales = (
|
||||||
|
OrderItem.objects.filter(product__seller=request.user)
|
||||||
|
.select_related("product", "order__buyer")
|
||||||
|
.order_by("-order__created_at")[:8]
|
||||||
|
)
|
||||||
|
|
||||||
|
context = {
|
||||||
|
"dashboard_title": "Seller Dashboard",
|
||||||
|
"active_tab": "seller",
|
||||||
|
"product_count": seller_products.count(),
|
||||||
|
"total_orders": sales_summary["total_orders"] or 0,
|
||||||
|
"total_items": sales_summary["total_items"] or 0,
|
||||||
|
"total_revenue": sales_summary["total_revenue"] or 0,
|
||||||
|
"recent_sales": recent_sales,
|
||||||
|
}
|
||||||
|
return render(request, "core/seller_dashboard.html", context)
|
||||||
|
|
||||||
|
|
||||||
|
def add_to_cart(request, pk):
|
||||||
|
product = get_object_or_404(Product, pk=pk)
|
||||||
|
cart = request.session.get("cart", {})
|
||||||
|
product_id = str(pk)
|
||||||
|
cart[product_id] = cart.get(product_id, 0) + 1
|
||||||
|
request.session["cart"] = cart
|
||||||
|
return redirect("home")
|
||||||
|
|
||||||
|
|
||||||
|
def remove_from_cart(request, pk):
|
||||||
|
cart = request.session.get("cart", {})
|
||||||
|
product_id = str(pk)
|
||||||
|
if product_id in cart:
|
||||||
|
del cart[product_id]
|
||||||
|
request.session["cart"] = cart
|
||||||
|
return redirect("cart_view")
|
||||||
|
|
||||||
|
|
||||||
|
def cart_view(request):
|
||||||
|
cart = request.session.get("cart", {})
|
||||||
|
items = []
|
||||||
|
total_price = 0
|
||||||
|
for product_id, quantity in cart.items():
|
||||||
|
try:
|
||||||
|
product = Product.objects.get(pk=product_id)
|
||||||
|
items.append({"product": product, "quantity": quantity, "subtotal": product.price * quantity})
|
||||||
|
total_price += product.price * quantity
|
||||||
|
except Product.DoesNotExist:
|
||||||
|
continue
|
||||||
|
context = {"items": items, "total_price": total_price}
|
||||||
|
return render(request, "core/cart.html", context)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@transaction.atomic
|
||||||
|
def checkout(request):
|
||||||
|
cart = request.session.get("cart", {})
|
||||||
|
if not cart:
|
||||||
|
return redirect("cart_view")
|
||||||
|
|
||||||
|
order = Order.objects.create(buyer=request.user)
|
||||||
|
|
||||||
|
for product_id, quantity in cart.items():
|
||||||
|
product = get_object_or_404(Product, pk=product_id)
|
||||||
|
OrderItem.objects.create(
|
||||||
|
order=order,
|
||||||
|
product=product,
|
||||||
|
quantity=quantity,
|
||||||
|
price=product.price
|
||||||
|
)
|
||||||
|
|
||||||
|
request.session["cart"] = {}
|
||||||
|
return redirect("buyer_dashboard")
|
||||||
Loading…
x
Reference in New Issue
Block a user