diff --git a/pushup/management/commands/generate_stock.py b/pushup/management/commands/generate_stock.py new file mode 100644 index 0000000..9c78895 --- /dev/null +++ b/pushup/management/commands/generate_stock.py @@ -0,0 +1,21 @@ +from django.core.management.base import BaseCommand, CommandError +from pushup.models import StockValue +import random + +def get_current_stock_value(): + return float(StockValue.objects.order_by('-time').first().value) + +class Command(BaseCommand): + help = 'Generate a new stock value' + + def handle(self, *args, **options): + current_val = get_current_stock_value() + if current_val <= 0.5: + new_value = StockValue(value=round(current_val + round(random.uniform(0.0, 0.5), 3), 3)) + if current_val >= 2: + new_value = StockValue(value=round(current_val + round(random.uniform(-0.15, 0.10), 3), 3)) + else: + new_value = StockValue(value=round(current_val + round(random.uniform(-0.09, 0.10), 3), 3)) + + + new_value.save() \ No newline at end of file diff --git a/pushup/templates/pushup/index.html b/pushup/templates/pushup/index.html index 8befc7f..647c912 100644 --- a/pushup/templates/pushup/index.html +++ b/pushup/templates/pushup/index.html @@ -4,6 +4,7 @@
+

Current Value:

{{current_value}}

@@ -43,9 +44,8 @@ data: { labels: {{times|safe}}, datasets: [{ - label: 'My First dataset', - backgroundColor: 'rgb(255, 99, 132)', - borderColor: 'rgb(255, 99, 132)', + label: 'Pushup Value', + borderColor: '#21CE99', data: {{values|safe}} }] }, diff --git a/pushup/views.py b/pushup/views.py index 3944f69..a523843 100644 --- a/pushup/views.py +++ b/pushup/views.py @@ -10,6 +10,8 @@ import datetime def home(request): times = [] values = [] + current_value = get_current_stock_value() + users = Profile.objects.order_by('-pushups') print(users) @@ -23,6 +25,10 @@ def home(request): 'times': times, 'values': values, 'users': users, + 'current_value': current_value } - return render(request, 'pushup/index.html', context=context) \ No newline at end of file + return render(request, 'pushup/index.html', context=context) + +def get_current_stock_value(): + return float(StockValue.objects.order_by('-time').first().value) \ No newline at end of file diff --git a/users/migrations/0003_auto_20201019_0252.py b/users/migrations/0003_auto_20201019_0252.py new file mode 100644 index 0000000..89edd79 --- /dev/null +++ b/users/migrations/0003_auto_20201019_0252.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.2 on 2020-10-19 06:52 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0002_auto_20201019_0157'), + ] + + operations = [ + migrations.AlterField( + model_name='profile', + name='pushups', + field=models.DecimalField(decimal_places=3, max_digits=5), + ), + ] diff --git a/users/views.py b/users/views.py index a5c8aac..8c4d4dd 100644 --- a/users/views.py +++ b/users/views.py @@ -1,5 +1,11 @@ from django.shortcuts import render +from django.contrib.auth import authenticate +from django.contrib.auth import login as auth_login +from django.contrib.auth import logout as auth_logout +from django.contrib.auth.models import User +from django.contrib.auth.decorators import login_required + # Create your views here. def login(request): return None @@ -7,5 +13,7 @@ def login(request): def signup(request): return None +@login_required def logout(request): - return None \ No newline at end of file + auth_logout(request) + return render(request, 'users/logout.html') \ No newline at end of file