diff --git a/core/__pycache__/forms.cpython-311.pyc b/core/__pycache__/forms.cpython-311.pyc new file mode 100644 index 0000000..4dda475 Binary files /dev/null and b/core/__pycache__/forms.cpython-311.pyc differ diff --git a/core/__pycache__/urls.cpython-311.pyc b/core/__pycache__/urls.cpython-311.pyc index 1f807fa..648bd09 100644 Binary files a/core/__pycache__/urls.cpython-311.pyc and b/core/__pycache__/urls.cpython-311.pyc differ diff --git a/core/__pycache__/views.cpython-311.pyc b/core/__pycache__/views.cpython-311.pyc index 6867ddf..b7c676a 100644 Binary files a/core/__pycache__/views.cpython-311.pyc and b/core/__pycache__/views.cpython-311.pyc differ diff --git a/core/forms.py b/core/forms.py new file mode 100644 index 0000000..23cd219 --- /dev/null +++ b/core/forms.py @@ -0,0 +1,17 @@ +from django import forms +from .models import MoodEntry, Activity + +class MoodEntryForm(forms.ModelForm): + activities = forms.ModelMultipleChoiceField( + queryset=Activity.objects.all(), + widget=forms.CheckboxSelectMultiple, + required=False + ) + + class Meta: + model = MoodEntry + fields = ['mood_score', 'note', 'activities'] + widgets = { + 'mood_score': forms.NumberInput(attrs={'min': 1, 'max': 5}), + 'note': forms.Textarea(attrs={'rows': 4}), + } diff --git a/core/templates/base.html b/core/templates/base.html index 98c16d8..9b2be9d 100644 --- a/core/templates/base.html +++ b/core/templates/base.html @@ -24,6 +24,9 @@ PixelMinds +{% endblock %} diff --git a/core/templates/core/mood_entry_form.html b/core/templates/core/mood_entry_form.html new file mode 100644 index 0000000..8893d25 --- /dev/null +++ b/core/templates/core/mood_entry_form.html @@ -0,0 +1,57 @@ +{% extends 'base.html' %} + +{% block content %} +
+
+
+
+

Track Your Mood

+
+
+ {% csrf_token %} + +
+ + {{ form.mood_score }} + {% if form.mood_score.errors %} +
+ {{ form.mood_score.errors|striptags }} +
+ {% endif %} +
+ +
+ + {{ form.note }} + {% if form.note.errors %} +
+ {{ form.note.errors|striptags }} +
+ {% endif %} +
+ +
+ +
+ {% for checkbox in form.activities %} +
+ {{ checkbox.tag }} + +
+ {% endfor %} +
+ {% if form.activities.errors %} +
+ {{ form.activities.errors|striptags }} +
+ {% endif %} +
+ + +
+
+
+
+
+
+{% endblock %} diff --git a/core/urls.py b/core/urls.py index 6299e3d..8b96229 100644 --- a/core/urls.py +++ b/core/urls.py @@ -1,7 +1,11 @@ from django.urls import path -from .views import home +from .views import home, create_mood_entry, dashboard + +app_name = 'core' urlpatterns = [ - path("", home, name="home"), -] + path("", home, name="index"), + path('mood/new/', create_mood_entry, name='create_mood_entry'), + path('dashboard/', dashboard, name='dashboard'), +] \ No newline at end of file diff --git a/core/views.py b/core/views.py index c9aed12..4108665 100644 --- a/core/views.py +++ b/core/views.py @@ -2,24 +2,61 @@ import os import platform from django import get_version as django_version -from django.shortcuts import render +from django.shortcuts import render, redirect from django.utils import timezone +from django.contrib.auth.decorators import login_required +from django.http import JsonResponse +from .forms import MoodEntryForm +from .models import MoodEntry +from django_pandas.io import read_frame def home(request): - """Render the landing screen with loader and environment details.""" - host_name = request.get_host().lower() - agent_brand = "AppWizzy" if host_name == "appwizzy.com" else "Flatlogic" - now = timezone.now() - + """Render the home page with mood entries.""" context = { - "project_name": "New Style", - "agent_brand": agent_brand, - "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", ""), + 'project_name': "PixelMinds", } + if request.user.is_authenticated: + mood_entries = MoodEntry.objects.filter(user=request.user).order_by('-date_time')[:7] + context['mood_entries'] = mood_entries + return render(request, "core/index.html", context) + + +@login_required +def dashboard(request): + mood_entries = MoodEntry.objects.filter(user=request.user).order_by('date_time') + df = read_frame(mood_entries, fieldnames=['date_time', 'mood_score']) + df['date_time'] = df['date_time'].dt.strftime('%Y-%m-%d') + chart_data = df.to_json(orient='records') + return render(request, 'core/dashboard.html', {'chart_data': chart_data}) + + +@login_required +def create_mood_entry(request): + if request.method == 'POST': + form = MoodEntryForm(request.POST) + if form.is_valid(): + mood_entry = form.save(commit=False) + mood_entry.user = request.user + + # Assign color based on mood score + mood_score = form.cleaned_data['mood_score'] + if mood_score == 1: + mood_entry.color_code = '#FF0000' # Red + elif mood_score == 2: + mood_entry.color_code = '#FFC107' # Amber + elif mood_score == 3: + mood_entry.color_code = '#FFFF00' # Yellow + elif mood_score == 4: + mood_entry.color_code = '#4CAF50' # Green + elif mood_score == 5: + mood_entry.color_code = '#2196F3' # Blue + + mood_entry.save() + form.save_m2m() # Save the many-to-many relationships + return redirect('core:index') + else: + form = MoodEntryForm() + + return render(request, 'core/mood_entry_form.html', {'form': form}) diff --git a/requirements.txt b/requirements.txt index e22994c..f3c9ec2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ Django==5.2.7 mysqlclient==2.2.7 python-dotenv==1.1.1 +django-pandas==0.6.7