Add incomplete CBT component
This commit is contained in:
parent
5b4b3058a5
commit
73aed44e83
9 changed files with 105 additions and 1 deletions
0
cbt/__init__.py
Normal file
0
cbt/__init__.py
Normal file
3
cbt/admin.py
Normal file
3
cbt/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
5
cbt/apps.py
Normal file
5
cbt/apps.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class CbtConfig(AppConfig):
|
||||
name = 'cbt'
|
8
cbt/forms.py
Normal file
8
cbt/forms.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
from django.forms import ModelForm
|
||||
|
||||
from .models import ThoughtRecord
|
||||
|
||||
class ThoughtRecordStepOneForm(ModelForm):
|
||||
class Meta:
|
||||
model = ThoughtRecord
|
||||
fields = ["title", "situation"]
|
22
cbt/models.py
Normal file
22
cbt/models.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
from django.db import models
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
from common.fields import PercentageField
|
||||
|
||||
class EmotionRecord(models.Model):
|
||||
emotion = models.CharField(max_length=128)
|
||||
percentage = PercentageField()
|
||||
description = models.TextField()
|
||||
|
||||
class ThoughtRecord(models.Model):
|
||||
user = models.ForeignKey(get_user_model(), models.CASCADE)
|
||||
title = models.CharField(blank=True, null=True, max_length=128)
|
||||
situation = models.TextField(blank=True, null=True)
|
||||
emotions = models.ManyToManyField(EmotionRecord)
|
||||
thoughts = models.TextField(blank=True, null=True)
|
||||
pro_facts = models.TextField(blank=True, null=True)
|
||||
con_facts = models.TextField(blank=True, null=True)
|
||||
realistic = models.TextField(blank=True, null=True)
|
||||
outcome = models.TextField(blank=True, null=True)
|
||||
emotions_now = models.ManyToManyField(EmotionRecord, related_name="emotions_now")
|
||||
complete = models.BooleanField(default=False)
|
40
cbt/templates/cbt/thoughtrecord1.html
Normal file
40
cbt/templates/cbt/thoughtrecord1.html
Normal file
|
@ -0,0 +1,40 @@
|
|||
{% extends "frontend/base.html" %}
|
||||
{% block "content" %}
|
||||
|
||||
{% if form.errors %}
|
||||
{% for field in form %}
|
||||
{% for error in field.errors %}
|
||||
<div class="alert alert-danger" role="alert">
|
||||
{{ field.name }}: {{ error }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
<div class="card shadow mb-4">
|
||||
<div class="card-header py-3">
|
||||
<h6 class="m-0 font-weight-bold text-primary">Edit {{ object.name }}</h6>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form action="" method="POST">
|
||||
{% csrf_token %}
|
||||
<div class="table-responsive">
|
||||
<table>
|
||||
<tr><th><label for="id_title">Title:</label></th><td><input type="text" name="name" value="{{ object.title }}" maxlength="64" required id="id_name"></td></tr>
|
||||
<tr><th><label for="id_icon">Icon:</label></th><td><input style="visibility: hidden;" class="icp icp-auto" type="text" name="icon" value="{{ object.icon }}" maxlength="64" required id="id_icon"></td></tr>
|
||||
<tr><th><label for="id_color">Color:</label></th><td><input type="text"
|
||||
id="id_color"
|
||||
class="form-control colorfield_field jscolor"
|
||||
name="color"
|
||||
value="{{ object.color }}"
|
||||
placeholder="{{ object.color }}"
|
||||
data-jscolor="{hash:true,width:225,height:150,required:true}"
|
||||
required /></td></tr>
|
||||
<tr><th><label for="id_value">Value:</label></th><td><input name="value" type="number" step="1" value="{{ object.value }}" required id="id_value"></td></tr>
|
||||
</table>
|
||||
</div>
|
||||
<button style="margin-top: 20px;" class="form-control btn-primary" type="submit">Save</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
3
cbt/tests.py
Normal file
3
cbt/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
22
cbt/views.py
Normal file
22
cbt/views.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
from django.views.generic import CreateView
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
|
||||
from .forms import ThoughtRecordStepOneForm
|
||||
from .models import ThoughtRecord
|
||||
|
||||
class ThoughtRecordStepOneView(LoginRequiredMixin, CreateView):
|
||||
form_class = ThoughtRecordStepOneForm
|
||||
template_name = "cbt/thoughtrecord1.html"
|
||||
model = ThoughtRecord
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["title"] = "Create Thought Record"
|
||||
return context
|
||||
|
||||
def form_valid(self, form):
|
||||
form.instance.user = self.request.user
|
||||
|
||||
ret = super().form_valid(form)
|
||||
|
||||
return ret
|
|
@ -21,6 +21,7 @@ INSTALLED_APPS = [
|
|||
'mood',
|
||||
'msgio',
|
||||
'cronhandler',
|
||||
'cbt',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
|
Loading…
Reference in a new issue