Commit be7f22ab authored by Pernille Nødtvedt Welle-Watne's avatar Pernille Nødtvedt Welle-Watne
Browse files

Merge branch 'uc2-suggested-workout-frontend' into 'master'

Uc2 suggested workout frontend og backend

See merge request !3
parents a526e5cb c4890bdc
Pipeline #113579 passed with stage
in 1 minute and 43 seconds
......@@ -4,4 +4,6 @@ backend/secfit/*/__pycache__/
backend/secfit/db.sqlite3
.idea/
venv/
\ No newline at end of file
venv/
.vscode/
.DS_store
\ No newline at end of file
variables:
HEROKU_APP_NAME: tdt4242-base
HEROKU_REGISTRY_IMAGE: registry.heroku.com/${HEROKU_APP_NAME}/web
HEROKU_APP_NAME_BACKEND: tdt4242-base
HEROKU_APP_NAME_FRONTEND: tdt4242-base-secfit
stages:
- test
# - test
- deploy
test:
image: python:3
stage: test
script:
#test:
# image: python:3
# stage: test
# script:
# this configures Django application to use attached postgres database that is run on `postgres` host
- cd backend/secfit
- apt-get update -qy
- pip install -r requirements.txt
- python manage.py test
# - cd backend/secfit
# - apt-get update -qy
# - pip install -r requirements.txt
# - python manage.py test
deploy:
image: ruby
stage: deploy
variables:
HEROKU_APP_NAME: tdt4242-base
type: deploy
script:
- apt-get update -qy
- apt-get install -y ruby-dev
- apt-get install -y ruby ruby-dev
- gem install dpl
- dpl --provider=heroku --app=$HEROKU_APP_NAME --api-key=$HEROKU_AUTH_TOKEN
- dpl --provider=heroku --app=$HEROKU_APP_NAME_BACKEND --api-key=$HEROKU_AUTH_TOKEN
- dpl --provider=heroku --app=$HEROKU_APP_NAME_FRONTEND --api-key=$HEROKU_AUTH_TOKEN
web: gunicorn --pythonpath 'backend/secfit' secfit.wsgi --log-file -
# Generated by Django 3.1 on 2021-03-04 22:41
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('comments', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='comment',
name='timestamp',
field=models.DateTimeField(default=django.utils.timezone.now),
),
migrations.AlterField(
model_name='like',
name='timestamp',
field=models.DateTimeField(default=django.utils.timezone.now),
),
]
......@@ -8,8 +8,10 @@ from django.urls import reverse
from django.db import models
from django.contrib.auth import get_user_model
from workouts.models import Workout
from django.utils import timezone
# Create your models here.
class Comment(models.Model):
"""Django model for a comment left on a workout.
......@@ -26,7 +28,7 @@ class Comment(models.Model):
Workout, on_delete=models.CASCADE, related_name="comments"
)
content = models.TextField()
timestamp = models.DateTimeField(auto_now_add=True)
timestamp = models.DateTimeField(default=timezone.now)
class Meta:
ordering = ["-timestamp"]
......@@ -44,5 +46,6 @@ class Like(models.Model):
owner = models.ForeignKey(
get_user_model(), on_delete=models.CASCADE, related_name="likes"
)
comment = models.ForeignKey(Comment, on_delete=models.CASCADE, related_name="likes")
timestamp = models.DateTimeField(auto_now_add=True)
comment = models.ForeignKey(
Comment, on_delete=models.CASCADE, related_name="likes")
timestamp = models.DateTimeField(default=timezone.now)
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
# import logging
import os
import dj_database_url
from django.test.runner import DiscoverRunner
MAX_CONN_AGE = 600
def settings(config, *, db_colors=False, databases=True, test_runner=True, staticfiles=True, allowed_hosts=True,
logging=True, secret_key=True):
# Database configuration.
# TODO: support other database (e.g. TEAL, AMBER, etc, automatically.)
if databases:
# Integrity check.
if 'DATABASES' not in config:
config['DATABASES'] = {'default': None}
conn_max_age = config.get('CONN_MAX_AGE', MAX_CONN_AGE)
if db_colors:
# Support all Heroku databases.
# TODO: This appears to break TestRunner.
for (env, url) in os.environ.items():
if env.startswith('HEROKU_POSTGRESQL'):
db_color = env[len('HEROKU_POSTGRESQL_'):].split('_')[0]
# logger.info('Adding ${} to DATABASES Django setting ({}).'.format(env, db_color))
config['DATABASES'][db_color] = dj_database_url.parse(url, conn_max_age=conn_max_age,
ssl_require=True)
if 'DATABASE_URL' in os.environ:
# logger.info('Adding $DATABASE_URL to default DATABASE Django setting.')
# Configure Django for DATABASE_URL environment variable.
config['DATABASES']['default'] = dj_database_url.config(conn_max_age=conn_max_age, ssl_require=True)
# logger.info('Adding $DATABASE_URL to TEST default DATABASE Django setting.')
# Enable test database if found in CI environment.
if 'CI' in os.environ:
config['DATABASES']['default']['TEST'] = config['DATABASES']['default']
# else:
# logger.info('$DATABASE_URL not found, falling back to previous settings!')
if test_runner:
# Enable test runner if found in CI environment.
if 'CI' in os.environ:
config['TEST_RUNNER'] = 'django_heroku.HerokuDiscoverRunner'
# Staticfiles configuration.
if staticfiles:
# logger.info('Applying Heroku Staticfiles configuration to Django settings.')
config['STATIC_ROOT'] = os.path.join(config['BASE_DIR'], 'staticfiles')
config['STATIC_URL'] = '/static/'
# Ensure STATIC_ROOT exists.
os.makedirs(config['STATIC_ROOT'], exist_ok=True)
# Insert Whitenoise Middleware.
try:
config['MIDDLEWARE_CLASSES'] = tuple(
['whitenoise.middleware.WhiteNoiseMiddleware'] + list(config['MIDDLEWARE_CLASSES']))
except KeyError:
config['MIDDLEWARE'] = tuple(['whitenoise.middleware.WhiteNoiseMiddleware'] + list(config['MIDDLEWARE']))
# Enable GZip.
config['STATICFILES_STORAGE'] = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
if allowed_hosts:
# logger.info('Applying Heroku ALLOWED_HOSTS configuration to Django settings.')
config['ALLOWED_HOSTS'] = ['*']
"""
if logging:
logger.info('Applying Heroku logging configuration to Django settings.')
config['LOGGING'] = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': ('%(asctime)s [%(process)d] [%(levelname)s] ' +
'pathname=%(pathname)s lineno=%(lineno)s ' +
'funcname=%(funcName)s %(message)s'),
'datefmt': '%Y-%m-%d %H:%M:%S'
},
'simple': {
'format': '%(levelname)s %(message)s'
}
},
'handlers': {
'null': {
'level': 'DEBUG',
'class': 'logging.NullHandler',
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'verbose'
}
},
'loggers': {
'testlogger': {
'handlers': ['console'],
'level': 'INFO',
}
}
}
"""
# SECRET_KEY configuration.
if secret_key:
if 'SECRET_KEY' in os.environ:
# logger.info('Adding $SECRET_KEY to SECRET_KEY Django setting.')
# Set the Django setting from the environment variable.
config['SECRET_KEY'] = os.environ['SECRET_KEY']
\ No newline at end of file
......@@ -15,6 +15,8 @@ import os
# Get the GROUPID variable to accept connections from the application server and NGINX
from .django_heroku import settings
groupid = os.environ.get("GROUPID", "0")
# Email configuration
......@@ -59,7 +61,9 @@ INSTALLED_APPS = [
"workouts.apps.WorkoutsConfig",
"users.apps.UsersConfig",
"comments.apps.CommentsConfig",
"suggested_workouts.apps.SuggestedWorkoutsConfig",
"corsheaders",
]
MIDDLEWARE = [
......@@ -139,9 +143,12 @@ REST_FRAMEWORK = {
"PAGE_SIZE": 10,
"DEFAULT_AUTHENTICATION_CLASSES": (
"rest_framework_simplejwt.authentication.JWTAuthentication",
'rest_framework.authentication.SessionAuthentication',
),
}
AUTH_USER_MODEL = "users.User"
DEBUG = True
settings(locals())
......@@ -21,6 +21,7 @@ from django.conf.urls.static import static
urlpatterns = [
path("admin/", admin.site.urls),
path("", include("workouts.urls")),
path("", include("suggested_workouts.urls")),
]
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
......
"""Module for registering models from workouts app to admin page so that they appear
"""
from django.contrib import admin
# Register your models here.
from .models import SuggestedWorkout
admin.site.register(SuggestedWorkout)
from django.apps import AppConfig
class SuggestedWorkoutsConfig(AppConfig):
name = 'suggested_workouts'
# Generated by Django 3.1 on 2021-02-23 21:11
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='WorkoutRequest',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('is_active', models.BooleanField(blank=True, default=True)),
('reciever', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='reciever', to=settings.AUTH_USER_MODEL)),
('sender', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='sender', to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='SuggestedWorkout',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('date', models.DateTimeField(blank=True, null=True)),
('notes', models.TextField()),
('visibility', models.CharField(choices=[('PU', 'Public'), ('CO', 'Coach'), ('PR', 'Private')], default='CO', max_length=2)),
('athlete', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='athlete', to=settings.AUTH_USER_MODEL)),
('coach', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='author', to=settings.AUTH_USER_MODEL)),
],
),
]
# Generated by Django 3.1 on 2020-09-10 00:22
# Generated by Django 3.1 on 2021-03-04 22:41
from django.conf import settings
from django.db import migrations, models
......@@ -9,17 +9,22 @@ class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("workouts", "0001_initial"),
('suggested_workouts', '0001_initial'),
]
operations = [
migrations.RemoveField(
model_name='suggestedworkout',
name='visibility',
),
migrations.AddField(
model_name='suggestedworkout',
name='status',
field=models.CharField(choices=[('a', 'Accepted'), ('p', 'Pending'), ('d', 'Declined')], default='p', max_length=8),
),
migrations.AlterField(
model_name="workoutfile",
name="owner",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="workout_files",
to=settings.AUTH_USER_MODEL,
),
model_name='suggestedworkout',
name='coach',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='owner', to=settings.AUTH_USER_MODEL),
),
]
# Generated by Django 3.1 on 2021-02-27 12:48
# Generated by Django 3.1 on 2021-03-04 22:59
from django.db import migrations, models
......@@ -6,13 +6,13 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('workouts', '0003_rememberme'),
('suggested_workouts', '0002_auto_20210304_2241'),
]
operations = [
migrations.AddField(
model_name='workout',
name='planned',
field=models.BooleanField(default=False),
model_name='suggestedworkout',
name='visibility',
field=models.CharField(default='PU', max_length=8),
),
]
# Generated by Django 3.1 on 2021-03-04 23:00
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('suggested_workouts', '0003_suggestedworkout_visibility'),
]
operations = [
migrations.RemoveField(
model_name='suggestedworkout',
name='visibility',
),
]
# Generated by Django 3.1 on 2021-03-04 23:12
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('suggested_workouts', '0004_remove_suggestedworkout_visibility'),
]
operations = [
migrations.AddField(
model_name='suggestedworkout',
name='visibility',
field=models.CharField(blank=True, default='', max_length=8, null=True),
),
]
# Generated by Django 3.1 on 2020-12-13 21:28
# Generated by Django 3.1 on 2021-03-05 09:29
from django.db import migrations
......@@ -6,16 +6,15 @@ from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('users', '0007_auto_20200910_0222'),
('suggested_workouts', '0005_suggestedworkout_visibility'),
]
operations = [
migrations.RemoveField(
model_name='offer',
name='offer_type',
model_name='suggestedworkout',
name='visibility',
),
migrations.RemoveField(
model_name='offer',
name='stale',
migrations.DeleteModel(
name='WorkoutRequest',
),
]
from django.db import models
from django.db import models
from django.contrib.auth import get_user_model
from django.utils import timezone
class SuggestedWorkout(models.Model):
# Visibility levels
ACCEPTED = "a"
PENDING = "p"
DECLINED = "d"
STATUS_CHOICES = (
(ACCEPTED, "Accepted"),
(PENDING, "Pending"),
(DECLINED, "Declined"),
)
name = models.CharField(max_length=100)
date = models.DateTimeField(null=True, blank=True)
notes = models.TextField()
coach = models.ForeignKey(
get_user_model(), on_delete=models.CASCADE, related_name="owner")
athlete = models.ForeignKey(
get_user_model(), on_delete=models.CASCADE, related_name="athlete")
status = models.CharField(
max_length=8, choices=STATUS_CHOICES, default=PENDING)
def __str__(self):
return self.name
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment