From f5ce10ef9354e7bccafa465d0dcc5b1da1ecbea0 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Thu, 31 Dec 2020 22:18:39 +0100 Subject: [PATCH] Add incomplete CBT component --- cbt/__init__.py | 0 cbt/admin.py | 3 ++ cbt/apps.py | 5 ++++ cbt/forms.py | 8 ++++++ cbt/models.py | 22 +++++++++++++++ cbt/templates/cbt/thoughtrecord1.html | 40 +++++++++++++++++++++++++++ cbt/tests.py | 3 ++ cbt/views.py | 22 +++++++++++++++ kumify/settings.py | 3 +- 9 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 cbt/__init__.py create mode 100644 cbt/admin.py create mode 100644 cbt/apps.py create mode 100644 cbt/forms.py create mode 100644 cbt/models.py create mode 100644 cbt/templates/cbt/thoughtrecord1.html create mode 100644 cbt/tests.py create mode 100644 cbt/views.py diff --git a/cbt/__init__.py b/cbt/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/cbt/admin.py b/cbt/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/cbt/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/cbt/apps.py b/cbt/apps.py new file mode 100644 index 0000000..9cac0ad --- /dev/null +++ b/cbt/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class CbtConfig(AppConfig): + name = 'cbt' diff --git a/cbt/forms.py b/cbt/forms.py new file mode 100644 index 0000000..653d1a2 --- /dev/null +++ b/cbt/forms.py @@ -0,0 +1,8 @@ +from django.forms import ModelForm + +from .models import ThoughtRecord + +class ThoughtRecordStepOneForm(ModelForm): + class Meta: + model = ThoughtRecord + fields = ["title", "situation"] diff --git a/cbt/models.py b/cbt/models.py new file mode 100644 index 0000000..983cea3 --- /dev/null +++ b/cbt/models.py @@ -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) \ No newline at end of file diff --git a/cbt/templates/cbt/thoughtrecord1.html b/cbt/templates/cbt/thoughtrecord1.html new file mode 100644 index 0000000..9845f54 --- /dev/null +++ b/cbt/templates/cbt/thoughtrecord1.html @@ -0,0 +1,40 @@ +{% extends "frontend/base.html" %} +{% block "content" %} + +{% if form.errors %} +{% for field in form %} +{% for error in field.errors %} + +{% endfor %} +{% endfor %} +{% endif %} +
+
+
Edit {{ object.name }}
+
+
+
+ {% csrf_token %} +
+ + + + + +
+
+ +
+
+
+ +{% endblock %} \ No newline at end of file diff --git a/cbt/tests.py b/cbt/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/cbt/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/cbt/views.py b/cbt/views.py new file mode 100644 index 0000000..274fbb0 --- /dev/null +++ b/cbt/views.py @@ -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 \ No newline at end of file diff --git a/kumify/settings.py b/kumify/settings.py index f058a9e..e0d7758 100644 --- a/kumify/settings.py +++ b/kumify/settings.py @@ -21,6 +21,7 @@ INSTALLED_APPS = [ 'mood', 'msgio', 'cronhandler', + 'cbt', ] MIDDLEWARE = [ @@ -124,4 +125,4 @@ LOGIN_REDIRECT_URL = '/' LOGOUT_REDIRECT_URL = "/" DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage' if not AWS_ACCESS_KEY_ID else 'storages.backends.s3boto3.S3Boto3Storage' -STATICFILES_STORAGE = 'storages.backends.s3boto3.S3StaticStorage' if AWS_ACCESS_KEY_ID else 'django.contrib.staticfiles.storage.StaticFilesStorage' \ No newline at end of file +STATICFILES_STORAGE = 'storages.backends.s3boto3.S3StaticStorage' if AWS_ACCESS_KEY_ID else 'django.contrib.staticfiles.storage.StaticFilesStorage'