Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lab05 pokedex! #73

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
129 changes: 129 additions & 0 deletions code/liam/django/pokedex-main/pokedex-main/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# 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

# 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/
12 changes: 12 additions & 0 deletions code/liam/django/pokedex-main/pokedex-main/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
django = "==3.2"

[requires]
python_version = "3.8"
52 changes: 52 additions & 0 deletions code/liam/django/pokedex-main/pokedex-main/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions code/liam/django/pokedex-main/pokedex-main/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Pokedex Starter

## Installation

Make sure you have Python and Pipenv installed on your computer.

Download the repo and save it to your code folder in the class repo. *make sure you download it, don't clone it or it won't upload to the class repo correctly*

If you are not running Python 3.8, edit the last line of the `Pipfile` to refer to your version instead.

Navigate to the pokedex folder in the terminal and do the following:

- `pipenv install` Create the virtual enviroment and install dependencies.
- `pipenv shell` Enter the new virtual enviroment.
- `python manage.py migrate users` Migrate the user model. *this django project uses a custom user model, you MUST migrate the users app before migrating the rest!*
- `python manage.py migrate` Migrate all other models.
- `python manage.py createsuperuser` Create yourself a super user.
- `python manage.py load_pokemon` Load Pokemon into the database.

You're good to go! This Django project comes with a database full of Pokemon, login/logout/registration pages, and a `home.html` template for you to create your Vue app.
Empty file.
3 changes: 3 additions & 0 deletions code/liam/django/pokedex-main/pokedex-main/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 code/liam/django/pokedex-main/pokedex-main/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.
3 changes: 3 additions & 0 deletions code/liam/django/pokedex-main/pokedex-main/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.
26 changes: 26 additions & 0 deletions code/liam/django/pokedex-main/pokedex-main/api/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from rest_framework import serializers
from pokemon.models import Pokemon, Type
from users.models import CustomUser

class TypeSerializer(serializers.ModelSerializer):
class Meta:
model = Type
fields = ['id', 'type']

class PokemonSerializer(serializers.ModelSerializer):

types = TypeSerializer(
many=True,
read_only=True,
)

class Meta:
model = Pokemon
fields = ['id', 'number', 'name', 'height', 'weight',
'image_front', 'image_back', 'caught_by',
'types']

class UserSerializer(serializers.ModelSerializer):
class Meta:
model = CustomUser
fields = ['username', 'id', 'caught']
3 changes: 3 additions & 0 deletions code/liam/django/pokedex-main/pokedex-main/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.
10 changes: 10 additions & 0 deletions code/liam/django/pokedex-main/pokedex-main/api/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.urls import path
from .views import *
from . import views

urlpatterns = [
path('', PokemonAPIView.as_view()),
path('users/', UserView.as_view()),
path('user/<int:pk>/', UserDetail.as_view()),
path('current/', views.current_user, name='current_user'),
]
29 changes: 29 additions & 0 deletions code/liam/django/pokedex-main/pokedex-main/api/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from rest_framework import generics
from pokemon.models import Pokemon, Type
from users.models import CustomUser
from .serializers import PokemonSerializer, TypeSerializer, UserSerializer
from rest_framework import permissions
from rest_framework.decorators import api_view
from rest_framework.response import Response

# Create your views here.

class PokemonAPIView(generics.ListAPIView):
permission_class = permissions.IsAuthenticated
serializer_class = PokemonSerializer
queryset = Pokemon.objects.all()

class UserView(generics.ListAPIView):
permission_class = permissions.IsAuthenticated
serializer_class = UserSerializer
queryset = CustomUser.objects.all()

class UserDetail(generics.RetrieveUpdateDestroyAPIView):
permission_class = permissions.IsAuthenticated
queryset = CustomUser.objects.all()
serializer_class = UserSerializer

@api_view(['GET'])
def current_user(request):
serializer = UserSerializer(request.user)
return Response(serializer.data)
22 changes: 22 additions & 0 deletions code/liam/django/pokedex-main/pokedex-main/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pokedex_project.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == '__main__':
main()
Empty file.
16 changes: 16 additions & 0 deletions code/liam/django/pokedex-main/pokedex-main/pokedex_project/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for pokedex_project project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pokedex_project.settings')

application = get_asgi_application()
Loading