Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions code/Ronnie/docker_django_vue/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*/node_modules
2 changes: 2 additions & 0 deletions code/Ronnie/docker_django_vue/backend/api/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from django.contrib import admin
from .models import ToDo

# Register your models here.
admin.site.register(ToDo)
Empty file.
6 changes: 6 additions & 0 deletions code/Ronnie/docker_django_vue/backend/api/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
from django.db import models

# Create your models here.
class ToDo(models.Model):
title = models.CharField(max_length=200)
status = models.BooleanField(default=False)

def __str__(self):
return self.title
7 changes: 7 additions & 0 deletions code/Ronnie/docker_django_vue/backend/api/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from rest_framework import serializers
from .models import ToDo

class ToDoSerializer(serializers.ModelSerializer):
class Meta:
fields = ('title', 'status')
model = ToDo
10 changes: 10 additions & 0 deletions code/Ronnie/docker_django_vue/backend/api/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from rest_framework.routers import DefaultRouter
from django.urls import path
from .views import ToDoViewSet

router = DefaultRouter()
router.register('todo', ToDoViewSet, basename='ToDo')

urlpatterns = router.urls + [

]
10 changes: 8 additions & 2 deletions code/Ronnie/docker_django_vue/backend/api/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
from django.shortcuts import render

from rest_framework import viewsets
from .models import ToDo
from .serializers import ToDoSerializer
# Create your views here.
class ToDoViewSet(viewsets.ModelViewSet):
queryset = ToDo.objects.all()
serializer_class = ToDoSerializer
# Api methods
http_method_names = ["get", "post", "head", "delete", "put"]
14 changes: 12 additions & 2 deletions code/Ronnie/docker_django_vue/backend/project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.1/ref/settings/
"""

import os
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
Expand Down Expand Up @@ -37,9 +37,13 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
# 'corsheaders',
'api',
]

MIDDLEWARE = [
'django.middleware.common.CommonMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
Expand All @@ -54,7 +58,7 @@
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
Expand Down Expand Up @@ -121,3 +125,9 @@
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.AllowAny',
]
}
5 changes: 4 additions & 1 deletion code/Ronnie/docker_django_vue/backend/project/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import path, include
from django.views.generic import TemplateView

urlpatterns = [
path('admin/', admin.site.urls),
path('api/', include('api.urls')),
path('', TemplateView.as_view(template_name='index.html'), name='index'),
]
8 changes: 8 additions & 0 deletions code/Ronnie/docker_django_vue/backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
asgiref==3.5.2
certifi==2022.9.14
charset-normalizer==2.1.1
Django==4.1
django-cors-headers==3.13.0
djangorestframework==3.14.0
idna==3.4
Pillow==9.2.0
pytz==2022.2.1
requests==2.28.1
sqlparse==0.4.2
urllib3==1.26.12
70 changes: 70 additions & 0 deletions code/Ronnie/docker_django_vue/backend/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<title>ToDo Items</title>
</head>
<body>
<div id="app">
<form>

</form>
<ul>
<li v-for="task in tasks">
${ task.title }
</li>
</ul>
</div>
<script>
let form = document.getElementById('form'); // selecting the form

form.addEventListener('submit', function(event) { // 1
event.preventDefault()

let data = new FormData(); // 2

data.append("title", document.getElementById('title').value)
data.append("status", document.getElementById('status').value)
data.append("csrfmiddlewaretoken", '{{csrf_token}}') // 3

axios.post('create_item/', data) // 4
.then(res => alert("Form Submitted")) // 5
.catch(errors => console.log(errors)) // 6

})

</script>
<script>
const app = new Vue({
el: '#app',
delimiters: ['${', '}'],
data: {
tasks: [],
},
methods: {
loadTask: function() {
axios({
methods: 'get',
url: 'api/todo',
}).then(response => {
this.tasks = response.data
console.log(this.tasks)
})
},
newTask: function() {

}
},
mounted: function(){
console.log('mounting')
this.loadTask()
}
})

</script>
</body>
</html>
16 changes: 8 additions & 8 deletions code/Ronnie/docker_django_vue/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ version: '3.9'

services:
# Dockerfile
frontend:
build: .
volumes:
- './frontend/:/usr/src/app'
- '/app/node_modules'
ports:
- '8081:8080'
command: "sh -c 'yarn serve'"
# frontend:
# build: .
# volumes:
# - './frontend/:/usr/src/app'
# - '/app/node_modules'
# ports:
# - '8081:8080'
# command: "sh -c 'yarn serve'"

# Official Image
db:
Expand Down
1 change: 1 addition & 0 deletions code/Ronnie/heroku
Submodule heroku added at e82d3d