This commit is contained in:
Flatlogic Bot 2025-12-22 18:50:12 +00:00
parent 05303880c9
commit 4c0ed8bcd5
11 changed files with 235 additions and 157 deletions

Binary file not shown.

17
core/forms.py Normal file
View File

@ -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}),
}

View File

@ -24,6 +24,9 @@
<a class="navbar-brand" href="/">PixelMinds</a> <a class="navbar-brand" href="/">PixelMinds</a>
<div class="collapse navbar-collapse" id="navbarNav"> <div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav"> <ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="{% url 'core:dashboard' %}">Dashboard</a>
</li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="/admin">Admin</a> <a class="nav-link" href="/admin">Admin</a>
</li> </li>

View File

@ -0,0 +1,49 @@
{% extends 'base.html' %}
{% block head %}
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
{% endblock %}
{% block content %}
<div class="container">
<h1>Mood Dashboard</h1>
<canvas id="moodChart" width="400" height="200"></canvas>
</div>
<script>
document.addEventListener("DOMContentLoaded", function() {
var ctx = document.getElementById('moodChart').getContext('2d');
var chartData = JSON.parse('{{ chart_data|safe }}');
var dates = chartData.map(function(d) { return d.date_time; });
var scores = chartData.map(function(d) { return d.mood_score; });
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: dates,
datasets: [{
label: 'Mood Score',
data: scores,
borderColor: 'rgba(75, 192, 192, 1)',
borderWidth: 1,
fill: false
}]
},
options: {
scales: {
x: {
type: 'time',
time: {
unit: 'day'
}
},
y: {
beginAtZero: true
}
}
}
});
});
</script>
{% endblock %}

View File

@ -1,145 +1,55 @@
{% extends "base.html" %} {% extends 'base.html' %}
{% block title %}{{ project_name }}{% endblock %} {% block title %}{{ project_name }}{% 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> <div class="container mt-5">
<div class="card"> <div class="row mb-4">
<h1>Analyzing your requirements and generating your app…</h1> <div class="col-md-6">
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes"> <h1>Welcome to {{ project_name }}</h1>
<span class="sr-only">Loading…</span> <p>Your personal space to reflect and grow.</p>
</div>
<div class="col-md-6 text-md-end">
{% if user.is_authenticated %}
<a href="{% url 'core:create_mood_entry' %}" class="btn btn-primary">+ Log New Mood</a>
{% else %}
<a href="{% url 'admin:login' %}" class="btn btn-primary">Log In</a>
{% endif %}
</div>
</div> </div>
<p class="hint">AppWizzy AI is collecting your requirements and applying the first changes.</p>
<p class="hint">This page will refresh automatically as the plan is implemented.</p> {% if user.is_authenticated %}
<p class="runtime"> <h2>Your Recent Moods</h2>
Runtime: Django <code>{{ django_version }}</code> · Python <code>{{ python_version }}</code> {% if mood_entries %}
— UTC <code>{{ current_time|date:"Y-m-d H:i:s" }}</code> <div class="list-group">
</p> {% for entry in mood_entries %}
</div> <div class="list-group-item list-group-item-action flex-column align-items-start">
</main> <div class="d-flex w-100 justify-content-between">
<footer> <h5 class="mb-1">Mood Score: {{ entry.mood_score }}/5</h5>
Page updated: {{ current_time|date:"Y-m-d H:i:s" }} (UTC) <small>{{ entry.date_time|date:"Y-m-d H:i" }}</small>
</footer> </div>
{% endblock %} <p class="mb-1">{{ entry.note|truncatewords:30 }}</p>
{% if entry.activities.all %}
<small>Activities:
{% for activity in entry.activities.all %}
<span class="badge bg-secondary">{{ activity.name }}</span>
{% endfor %}
</small>
{% endif %}
</div>
{% endfor %}
</div>
{% else %}
<p>You haven't logged any moods yet. <a href="{% url 'core:create_mood_entry' %}">Get started!</a></p>
{% endif %}
{% else %}
<div class="p-5 mb-4 bg-light rounded-3">
<div class="container-fluid py-5">
<h1 class="display-5 fw-bold">Track Your Mental Wellness</h1>
<p class="col-md-8 fs-4">Gain insights into your moods and activities to better understand your mental health. Log in to begin your journey.</p>
<a href="{% url 'admin:login' %}" class="btn btn-primary btn-lg">Log In & Get Started</a>
</div>
</div>
{% endif %}
</div>
{% endblock %}

View File

@ -0,0 +1,57 @@
{% extends 'base.html' %}
{% block content %}
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header"><h2>Track Your Mood</h2></div>
<div class="card-body">
<form method="post" novalidate>
{% csrf_token %}
<div class="mb-3">
<label for="id_mood_score" class="form-label">Mood Score (1-5)</label>
{{ form.mood_score }}
{% if form.mood_score.errors %}
<div class="invalid-feedback d-block">
{{ form.mood_score.errors|striptags }}
</div>
{% endif %}
</div>
<div class="mb-3">
<label for="id_note" class="form-label">Notes</label>
{{ form.note }}
{% if form.note.errors %}
<div class="invalid-feedback d-block">
{{ form.note.errors|striptags }}
</div>
{% endif %}
</div>
<div class="mb-3">
<label class="form-label">Activities</label>
<div id="id_activities">
{% for checkbox in form.activities %}
<div class="form-check">
{{ checkbox.tag }}
<label class="form-check-label" for="{{ checkbox.id_for_label }}">{{ checkbox.choice_label }}</label>
</div>
{% endfor %}
</div>
{% if form.activities.errors %}
<div class="invalid-feedback d-block">
{{ form.activities.errors|striptags }}
</div>
{% endif %}
</div>
<button type="submit" class="btn btn-primary">Save Mood</button>
</form>
</div>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@ -1,7 +1,11 @@
from django.urls import path from django.urls import path
from .views import home from .views import home, create_mood_entry, dashboard
app_name = 'core'
urlpatterns = [ urlpatterns = [
path("", home, name="home"), path("", home, name="index"),
] path('mood/new/', create_mood_entry, name='create_mood_entry'),
path('dashboard/', dashboard, name='dashboard'),
]

View File

@ -2,24 +2,61 @@ 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.shortcuts import render, redirect
from django.utils import timezone 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): def home(request):
"""Render the landing screen with loader and environment details.""" """Render the home page with mood entries."""
host_name = request.get_host().lower()
agent_brand = "AppWizzy" if host_name == "appwizzy.com" else "Flatlogic"
now = timezone.now()
context = { context = {
"project_name": "New Style", 'project_name': "PixelMinds",
"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", ""),
} }
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) 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})

View File

@ -1,3 +1,4 @@
Django==5.2.7 Django==5.2.7
mysqlclient==2.2.7 mysqlclient==2.2.7
python-dotenv==1.1.1 python-dotenv==1.1.1
django-pandas==0.6.7