Auto commit: 2025-12-02T16:01:28.239Z
This commit is contained in:
parent
82cd023d5e
commit
4647314b9d
BIN
ai/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
ai/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
ai/__pycache__/local_ai_api.cpython-311.pyc
Normal file
BIN
ai/__pycache__/local_ai_api.cpython-311.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,5 +1,7 @@
|
||||
from django.contrib.auth.forms import UserCreationForm
|
||||
from django import forms
|
||||
from django.contrib.auth.forms import UserCreationForm
|
||||
from .models import Article, Reflection
|
||||
|
||||
|
||||
class SignUpForm(UserCreationForm):
|
||||
class Meta(UserCreationForm.Meta):
|
||||
@ -8,3 +10,14 @@ class SignUpForm(UserCreationForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(SignUpForm, self).__init__(*args, **kwargs)
|
||||
self.fields['email'].required = True
|
||||
|
||||
|
||||
class ArticleForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Article
|
||||
fields = ('title', 'content')
|
||||
|
||||
class ReflectionForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Reflection
|
||||
fields = ('answer',)
|
||||
|
||||
27
core/migrations/0001_initial.py
Normal file
27
core/migrations/0001_initial.py
Normal file
@ -0,0 +1,27 @@
|
||||
# Generated by Django 5.2.7 on 2025-12-02 15:53
|
||||
|
||||
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='Article',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('title', models.CharField(max_length=200)),
|
||||
('content', models.TextField()),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
]
|
||||
26
core/migrations/0002_reflection.py
Normal file
26
core/migrations/0002_reflection.py
Normal file
@ -0,0 +1,26 @@
|
||||
# Generated by Django 5.2.7 on 2025-12-02 15:59
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('core', '0001_initial'),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Reflection',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('question', models.TextField()),
|
||||
('answer', models.TextField(blank=True, null=True)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('user', models.ForeignKey(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.
BIN
core/migrations/__pycache__/0002_reflection.cpython-311.pyc
Normal file
BIN
core/migrations/__pycache__/0002_reflection.cpython-311.pyc
Normal file
Binary file not shown.
@ -1,3 +1,20 @@
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
# Create your models here.
|
||||
class Article(models.Model):
|
||||
title = models.CharField(max_length=200)
|
||||
content = models.TextField()
|
||||
author = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
class Reflection(models.Model):
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
question = models.TextField()
|
||||
answer = models.TextField(blank=True, null=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return f"Reflection for {self.user.username} at {self.created_at}"
|
||||
|
||||
11
core/templates/core/article_list.html
Normal file
11
core/templates/core/article_list.html
Normal file
@ -0,0 +1,11 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<h2>Articles</h2>
|
||||
<ul>
|
||||
{% for article in articles %}
|
||||
<li><a href="{% url 'article_detail' pk=article.pk %}">{{ article.title }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<a href="{% url 'article_create' %}">New Article</a>
|
||||
{% endblock %}
|
||||
38
core/templates/core/reflection.html
Normal file
38
core/templates/core/reflection.html
Normal file
@ -0,0 +1,38 @@
|
||||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<h1 class="my-4">AI Reflection</h1>
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">This week's question:</h5>
|
||||
<p class="card-text">{{ question }}</p>
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="question" value="{{ question }}">
|
||||
{{ form.as_p }}
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Previous Reflections</h5>
|
||||
<ul class="list-group list-group-flush">
|
||||
{% for reflection in reflections %}
|
||||
<li class="list-group-item">
|
||||
<strong>{{ reflection.question }}</strong><br>
|
||||
{{ reflection.answer }}<br>
|
||||
<small class="text-muted">{{ reflection.created_at|date:"F d, Y" }}</small>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@ -5,4 +5,5 @@ from . import views
|
||||
urlpatterns = [
|
||||
path("", views.home, name="home"),
|
||||
path('signup/', views.signup, name='signup'),
|
||||
path('reflection/', views.reflection_view, name='reflection'),
|
||||
]
|
||||
|
||||
@ -1,12 +1,16 @@
|
||||
import os
|
||||
import platform
|
||||
import json
|
||||
|
||||
from django import get_version as django_version
|
||||
from django.contrib.auth import login
|
||||
from django.shortcuts import redirect, render
|
||||
from django.shortcuts import redirect, render, get_object_or_404
|
||||
from django.utils import timezone
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
||||
from core.forms import SignUpForm
|
||||
from .models import Article, Reflection
|
||||
from .forms import SignUpForm, ArticleForm, ReflectionForm
|
||||
from ai.local_ai_api import LocalAIApi
|
||||
|
||||
def home(request):
|
||||
"""Render the landing screen with loader and environment details."""
|
||||
@ -36,3 +40,56 @@ def signup(request):
|
||||
else:
|
||||
form = SignUpForm()
|
||||
return render(request, 'registration/signup.html', {'form': form})
|
||||
|
||||
@login_required
|
||||
def article_list(request):
|
||||
articles = Article.objects.filter(author=request.user)
|
||||
return render(request, 'core/article_list.html', {'articles': articles})
|
||||
|
||||
@login_required
|
||||
def article_detail(request, pk):
|
||||
article = get_object_or_404(Article, pk=pk, author=request.user)
|
||||
return render(request, 'core/article_detail.html', {'article': article})
|
||||
|
||||
@login_required
|
||||
def article_create(request):
|
||||
if request.method == 'POST':
|
||||
form = ArticleForm(request.POST)
|
||||
if form.is_valid():
|
||||
article = form.save(commit=False)
|
||||
article.author = request.user
|
||||
article.save()
|
||||
return redirect('article_detail', pk=article.pk)
|
||||
else:
|
||||
form = ArticleForm()
|
||||
return render(request, 'core/article_form.html', {'form': form})
|
||||
|
||||
|
||||
@login_required
|
||||
def reflection_view(request):
|
||||
# AI-generated question
|
||||
response = LocalAIApi.create_response({
|
||||
"input": [
|
||||
{"role": "system", "content": "You are a helpful assistant. Your task is to ask a single, short, thought-provoking question to help a user reflect on their week. The question should be suitable for a professional in the tech industry. The question should be no more than 20 words."},
|
||||
{"role": "user", "content": "Ask me a question."},
|
||||
],
|
||||
})
|
||||
|
||||
if response.get("success"):
|
||||
question = LocalAIApi.extract_text(response)
|
||||
else:
|
||||
question = "What is your biggest challenge this week?" # Fallback question
|
||||
|
||||
if request.method == 'POST':
|
||||
form = ReflectionForm(request.POST)
|
||||
if form.is_valid():
|
||||
reflection = form.save(commit=False)
|
||||
reflection.user = request.user
|
||||
reflection.question = request.POST.get('question') # Get question from hidden input
|
||||
reflection.save()
|
||||
return redirect('reflection')
|
||||
else:
|
||||
form = ReflectionForm()
|
||||
|
||||
reflections = Reflection.objects.filter(user=request.user).order_by('-created_at')
|
||||
return render(request, 'core/reflection.html', {'form': form, 'question': question, 'reflections': reflections})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user