Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added log #215

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/capstone/capstone/settings_env_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
}
}

DOMAIN = "http://127.0.0.1:8000"
DOMAIN = "http://127.0.0.1:8000"
27 changes: 17 additions & 10 deletions app/capstone/transformer/migrations/0014_product_delete_products.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,31 @@


class Migration(migrations.Migration):

dependencies = [
('transformer', '0013_auto_20231130_1121'),
("transformer", "0013_auto_20231130_1121"),
]

operations = [
migrations.CreateModel(
name='Product',
name="Product",
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.TextField()),
('get_display_number', models.IntegerField()),
('get_display_price', models.IntegerField()),
('description', models.TextField()),
('phrase', models.TextField()),
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.TextField()),
("get_display_number", models.IntegerField()),
("get_display_price", models.IntegerField()),
("description", models.TextField()),
("phrase", models.TextField()),
],
),
migrations.DeleteModel(
name='Products',
name="Products",
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@


class Migration(migrations.Migration):

dependencies = [
('transformer', '0014_product_delete_products'),
("transformer", "0014_product_delete_products"),
]

operations = [
migrations.AddField(
model_name='product',
name='get_display_price_cents',
model_name="product",
name="get_display_price_cents",
field=models.IntegerField(default=0),
),
migrations.AlterField(
model_name='product',
name='get_display_price',
model_name="product",
name="get_display_price",
field=models.DecimalField(decimal_places=2, default=0.0, max_digits=6),
),
]
5 changes: 3 additions & 2 deletions app/capstone/transformer/migrations/0016_add_products.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django.db import migrations


def import_products(app, schema_editor):
Product = app.get_model("transformer", "Product")
daily = Product.objects.create(
Expand Down Expand Up @@ -29,10 +30,10 @@ def import_products(app, schema_editor):
phrase="Best Value!",
)

class Migration(migrations.Migration):

class Migration(migrations.Migration):
dependencies = [
('transformer', '0015_product_get_display_price_cents_and_more'),
("transformer", "0015_product_get_display_price_cents_and_more"),
]

operations = [
Expand Down
31 changes: 22 additions & 9 deletions app/capstone/transformer/migrations/0017_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,35 @@


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('transformer', '0016_add_products'),
("transformer", "0016_add_products"),
]

operations = [
migrations.CreateModel(
name='Subscription',
name="Subscription",
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('has_subscription', models.BooleanField(default=False)),
('start_date', models.DateField(blank=True, null=True)),
('end_date', models.DateField(blank=True, null=True)),
('name', models.TextField()),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("has_subscription", models.BooleanField(default=False)),
("start_date", models.DateField(blank=True, null=True)),
("end_date", models.DateField(blank=True, null=True)),
("name", models.TextField()),
(
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL,
),
),
],
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,27 @@


class Migration(migrations.Migration):

dependencies = [
('transformer', '0017_subscription'),
("transformer", "0017_subscription"),
]

operations = [
migrations.RemoveField(
model_name='product',
name='get_display_number',
model_name="product",
name="get_display_number",
),
migrations.RemoveField(
model_name='subscription',
name='name',
model_name="subscription",
name="name",
),
migrations.AddField(
model_name='product',
name='length_days',
model_name="product",
name="length_days",
field=models.IntegerField(default=0),
),
migrations.AddField(
model_name='subscription',
name='is_premium',
model_name="subscription",
name="is_premium",
field=models.BooleanField(default=False),
),
]
10 changes: 5 additions & 5 deletions app/capstone/transformer/migrations/0019_auto_20240202_1351.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django.db import migrations


def update_products(app, schema_editor):
Product = app.get_model("transformer", "Product")
Product.objects.all().delete()
Expand All @@ -11,24 +12,23 @@ def update_products(app, schema_editor):
get_display_price=0.99,
description="Get access to Platonix for 1 day",
phrase="Most Flexible!",
length_days=1
length_days=1,
)
monthly = Product.objects.create(
name="Monthly Subscription",
get_display_price_cents=499,
get_display_price=4.99,
description="Get access to Platonix for 1 month",
phrase="Most Popular!",
length_days=30
length_days=30,
)


class Migration(migrations.Migration):

dependencies = [
('transformer', '0018_remove_product_get_display_number_and_more'),
("transformer", "0018_remove_product_get_display_number_and_more"),
]

operations = [
migrations.RunPython(update_products),
migrations.RunPython(update_products),
]
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@


class Migration(migrations.Migration):

dependencies = [
('transformer', '0015_alter_conversion_date_alter_file_date_and_more'),
('transformer', '0019_auto_20240202_1351'),
("transformer", "0015_alter_conversion_date_alter_file_date_and_more"),
("transformer", "0019_auto_20240202_1351"),
]

operations = [
]
operations = []
11 changes: 8 additions & 3 deletions app/capstone/transformer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,25 @@ class Transaction(models.Model):

class Product(models.Model):
name = models.TextField()
get_display_price_cents = models.IntegerField(default=0) #stored in cents for stripe
get_display_price = models.DecimalField(max_digits=6, decimal_places=2, default=0.00)
get_display_price_cents = models.IntegerField(
default=0
) # stored in cents for stripe
get_display_price = models.DecimalField(
max_digits=6, decimal_places=2, default=0.00
)
description = models.TextField()
phrase = models.TextField()
length_days = models.IntegerField(default=0)


class Subscription(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
has_subscription = models.BooleanField(default=False)
start_date = models.DateField(null=True, blank=True)
end_date = models.DateField(null=True, blank=True)
is_premium = models.BooleanField(default=False)


class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
image = models.ImageField(default="default_pfp.jpg", upload_to="profile_pics")
Expand Down
15 changes: 9 additions & 6 deletions app/capstone/transformer/subscriptionManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,33 @@
from datetime import date
from django.contrib.auth.models import User


def has_valid_subscription(user_id: int) -> bool:
try:
subscription = Subscription.objects.get(user=user_id)
return (
subscription.has_subscription and
subscription.start_date is not None and
subscription.end_date is not None and
subscription.start_date <= date.today() and
subscription.end_date >= date.today()
subscription.has_subscription
and subscription.start_date is not None
and subscription.end_date is not None
and subscription.start_date <= date.today()
and subscription.end_date >= date.today()
)
except Subscription.DoesNotExist:
return False


def give_subscription_to_user(user: User, start_date: date, end_date: date) -> None:
subscription, created = Subscription.objects.get_or_create(user=user)
subscription.has_subscription = True
subscription.start_date = start_date
subscription.end_date = end_date
subscription.save()


def delete_subscription(user: User) -> None:
try:
subscription = Subscription.objects.get(user=user)
subscription.delete()
print(f"Subscription deleted for user {user}")
except Subscription.DoesNotExist:
print(f"No subscription found for user {user}")
print(f"No subscription found for user {user}")
2 changes: 1 addition & 1 deletion app/capstone/transformer/templates/cancel.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ <h2 class="text-center title h2 mt-3">Looking for a different product?</h2>
</div>
</div>
</div>
{% endblock %}
{% endblock %}
32 changes: 12 additions & 20 deletions app/capstone/transformer/templates/profile.html
Original file line number Diff line number Diff line change
@@ -1,78 +1,70 @@
{% extends 'base.html' %}
{% load static %}
{% block content %}
<div class="container d-flex justify-content-center" style="padding-top: 100px">
<div class="container d-flex justify-content-center"
style="padding-top: 100px">
<div class="content-section rounded p-4" style="background-color: #1c1c1c">
{% for message in messages %}
<div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert">
<div class="alert alert-{{ message.tags }} alert-dismissible fade show"
role="alert">
<strong>Message:</strong> {{ message }}
<button type="button" class="close" data-bs-dismiss="alert" aria-label="Close">
<button type="button"
class="close"
data-bs-dismiss="alert"
aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
{% endfor %}

<div class="media">
<img class="rounded-circle account-img" src="{{ user.profile.image.url }}" />
<div class="media-body">
<h2 class="account-heading">{{ user.username }}</h2>
<p class="text-secondary">{{ user.email }}</p>
</div>
</div>

<!-- Email Update Form -->
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
<fieldset class="form-group">
<legend class="border-bottom mb-4">Email</legend>
<div class="form-group">
{{ e_form }}
</div>
<div class="form-group">{{ e_form }}</div>
<div class="form-group mt-3">
<button class="btn btn-outline-info" type="submit">Update Email</button>
</div>
</fieldset>
</form>
<br>

<!-- Password Update Form -->
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
<fieldset class="form-group">
<legend class="border-bottom mb-4">Password</legend>
<div class="form-group">
{{ p_form }}
</div>
<div class="form-group">{{ p_form }}</div>
<div class="form-group mt-3">
<button class="btn btn-outline-info" type="submit">Update Password</button>
</div>
</fieldset>
</form>
<br>

<!-- Profile Picture Update Form -->
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
<fieldset class="form-group">
<legend class="border-bottom mb-4">Profile Picture</legend>
<div class="form-group">
{{ pic_form }}
</div>
<div class="form-group">{{ pic_form }}</div>
<div class="form-group mt-3">
<button class="btn btn-outline-info" type="submit">Update Profile Picture</button>
</div>
</fieldset>
</form>
<br>

<!-- Account Deletion Form -->
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
<fieldset class="form-group">
<legend class="border-bottom mb-4">Account Deletion</legend>
<div class="form-group">
{{ delete_form.as_p }}
</div>
<div class="form-group">{{ delete_form.as_p }}</div>
<div class="form-group mt-3">
<button class="btn btn-danger" type="submit">Delete Account</button>
</div>
Expand Down
Loading
Loading