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
21 changes: 21 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Description

Please include a summary of the change and which issue is fixed.
List any dependencies that are required for this change.


## Type of change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)


# Checklist:

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] My changes generate no new warnings
- [ ] Appropriate test has been written for this branch
- [ ] My coding pattern follows the PEP8 pattern and as such has passed the Flake8 Test

30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Django CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: [3.8, 3.9]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run Tests
run: |
python manage.py test
131 changes: 131 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
.DS_Store
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
.idea/
# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
Pipfile

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Michael Jamie

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# django-zapit
A Reddit API built from a tutorial
Empty file added api/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions api/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions api/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class ApiConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'api'
Empty file added api/migrations/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions api/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
18 changes: 18 additions & 0 deletions api/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from rest_framework import serializers

from todo.models import Todo

class TodoSerializer(serializers.ModelSerializer):
created = serializers.ReadOnlyField()
datecompleted = serializers.ReadOnlyField()

class Meta:
model = Todo
exclude = ['user']


class TodoCompleteSerializer(serializers.ModelSerializer):
class Meta:
model = Todo
fields = ['id']
read_only_fields = ['__all__']
3 changes: 3 additions & 0 deletions api/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
32 changes: 32 additions & 0 deletions api/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from django.urls import path
from rest_framework import permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi

from . import views

schema_view = get_schema_view(
openapi.Info(
title="ToDo Woo API",
default_version='v1',
description="Connecting API to a todo app",
terms_of_service="https://www.google.com/policies/terms/",
contact=openapi.Contact(email="[email protected]"),
license=openapi.License(name="MIT License"),
),
public=True,
permission_classes=(permissions.AllowAny,),
)


urlpatterns = [
path('todos/', views.TodoCreate.as_view(), name='todo-create'),
path('todos/<int:pk>', views.TodoUpdate.as_view(), name='todo-create'),
path('todos/<int:pk>/ok', views.TodoOk.as_view(), name='todo-ok'),
path('completed/', views.TodoCompletedList.as_view(), name='todo-completed'),

# API DOCUMENTATION
path('json/', schema_view.without_ui(cache_timeout=0), name='schema-json'),
path('', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
]
49 changes: 49 additions & 0 deletions api/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from django.utils import timezone
from rest_framework import generics, permissions, response

from . import serializers
from todo.models import Todo


class TodoCompletedList(generics.ListAPIView):
serializer_class = serializers.TodoSerializer
permission_classes = [permissions.IsAuthenticated]

def get_queryset(self):
user = self.request.user
todos = Todo.objects.filter(user=user, datecompleted__isnull=False).order_by('-datecompleted')
return todos


class TodoCreate(generics.ListCreateAPIView):
serializer_class = serializers.TodoSerializer
permission_classes = [permissions.IsAuthenticated]

def get_queryset(self):
user = self.request.user
todos = Todo.objects.filter(user=user, datecompleted__isnull=True)
return todos

def perform_create(self, serializer):
serializer.save(user=self.request.user)

class TodoUpdate(generics.RetrieveUpdateDestroyAPIView):
serializer_class = serializers.TodoSerializer
permission_classes = [permissions.IsAuthenticated]

def get_queryset(self):
return Todo.objects.filter(user=self.request.user)


class TodoOk(generics.UpdateAPIView):
serializer_class = serializers.TodoCompleteSerializer
permission_classes = [permissions.IsAuthenticated]

def get_queryset(self):
return Todo.objects.filter(user=self.request.user)

def perform_update(self, serializer):
serializer.instance.datecompleted = timezone.now()
serializer.save()


Binary file removed db.sqlite3
Binary file not shown.
27 changes: 27 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
asgiref==3.5.0
certifi==2021.10.8
charset-normalizer==2.0.12
coreapi==2.3.3
coreschema==0.0.4
Django==4.0.4
django-shortcuts==1.6
djangorestframework==3.13.1
drf-yasg==1.20.0
flake8==4.0.1
idna==3.3
inflection==0.5.1
itypes==1.2.0
Jinja2==3.1.2
MarkupSafe==2.1.1
mccabe==0.6.1
packaging==21.3
pycodestyle==2.8.0
pyflakes==2.4.0
pyparsing==3.0.8
pytz==2022.1
requests==2.27.1
ruamel.yaml==0.17.21
ruamel.yaml.clib==0.2.6
sqlparse==0.4.2
uritemplate==4.1.1
urllib3==1.26.9
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
exclude = .git,*migrations*,env
max-line-length = 130
8 changes: 8 additions & 0 deletions todowoo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,15 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',

# APPS
'todo',
'api',


# PIP INSTALLS
'rest_framework',
'drf_yasg',
]

MIDDLEWARE = [
Expand Down
5 changes: 4 additions & 1 deletion todowoo/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
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 todo import views

urlpatterns = [
Expand All @@ -33,4 +33,7 @@
path('todo/<int:todo_pk>', views.viewtodo, name='viewtodo'),
path('todo/<int:todo_pk>/complete', views.completetodo, name='completetodo'),
path('todo/<int:todo_pk>/delete', views.deletetodo, name='deletetodo'),

# Api
path('api/v1/', include('api.urls')),
]