Skip to content

Commit 3f26e34

Browse files
committed
vercel config
1 parent 7a77c03 commit 3f26e34

File tree

199 files changed

+36636
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

199 files changed

+36636
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# http://editorconfig.org
2+
3+
root = true
4+
5+
[*]
6+
indent_style = space
7+
indent_size = 4
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
end_of_line = lf
11+
charset = utf-8
12+
13+
# Docstrings and comments use max_line_length = 79
14+
[*.py]
15+
max_line_length = 79
16+
17+
# Use 2 spaces for the HTML files
18+
[*.{html, js, css, yml, jinja2, json}]
19+
indent_size = 2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
Source: https://github.com/github/gitignore/blob/master/Python.gitignore
2+
3+
# User generated
4+
ENV/
5+
.vscode
6+
.idea
7+
.DS_Store
8+
.history
9+
10+
11+
# Byte-compiled / optimized / DLL files
12+
__pycache__/
13+
*.py[cod]
14+
*$py.class
15+
.pytest_cache/
16+
17+
# C extensions
18+
*.so
19+
20+
# Distribution / packaging
21+
.Python
22+
build/
23+
develop-eggs/
24+
dist/
25+
downloads/
26+
eggs/
27+
.eggs/
28+
lib/
29+
lib64/
30+
parts/
31+
sdist/
32+
var/
33+
wheels/
34+
*.egg-info/
35+
.installed.cfg
36+
*.egg
37+
MANIFEST
38+
39+
# PyInstaller
40+
# Usually these files are written by a python script from a template
41+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
42+
*.manifest
43+
*.spec
44+
45+
# Installer logs
46+
pip-log.txt
47+
pip-delete-this-directory.txt
48+
49+
# Unit test / coverage reports
50+
htmlcov/
51+
.tox/
52+
.coverage
53+
.coverage.*
54+
.cache
55+
nosetests.xml
56+
coverage.xml
57+
*.cover
58+
.hypothesis/
59+
60+
# Translations
61+
*.mo
62+
*.pot
63+
64+
# Django stuff:
65+
*.log
66+
.static_storage/
67+
.media/
68+
local_settings.py
69+
70+
# Flask stuff:
71+
instance/
72+
.webassets-cache
73+
74+
# Scrapy stuff:
75+
.scrapy
76+
77+
# Sphinx documentation
78+
docs/_build/
79+
80+
# PyBuilder
81+
target/
82+
83+
# Jupyter Notebook
84+
.ipynb_checkpoints
85+
86+
# pyenv
87+
.python-version
88+
89+
# celery beat schedule file
90+
celerybeat-schedule
91+
92+
# SageMath parsed files
93+
*.sage.py
94+
95+
# Environments
96+
.env
97+
.venv
98+
env/
99+
venv/
100+
ENV/
101+
env.bak/
102+
venv.bak/
103+
104+
# Spyder project settings
105+
.spyderproject
106+
.spyproject
107+
108+
# Rope project settings
109+
.ropeproject
110+
111+
# mkdocs documentation
112+
/site
113+
114+
# mypy
115+
.mypy_cache/
116+
117+
# js
118+
node_modules/
119+
.next/
120+
121+
# poetry
122+
poetry.lock
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Python version
2+
FROM python:3
3+
4+
# Set environment variables
5+
ENV PYTHONDONTWRITEBYTECODE 1
6+
ENV PYTHONUNBUFFERED 1
7+
8+
# Set work directory
9+
WORKDIR /code
10+
11+
# Install dependencies
12+
COPY requirements.txt /code/
13+
RUN pip install -r requirements.txt
14+
15+
# Copy project
16+
COPY . /code/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# api-quick-start
2+
3+
Template Project for starting up CRUD API with Django Rest Framework
4+
5+
## Customization Steps
6+
7+
- DO NOT migrate yet
8+
- add additional dependencies as needed
9+
- Re-export requirements.txt as needed
10+
- change `things` folder to the app name of your choice
11+
- Search through entire code base for `Thing`,`Things` and `things` to modify code to use your resource
12+
- `project/settings.py`
13+
- `project/urls.py`
14+
- App's files
15+
- `views.py`
16+
- `urls.py`
17+
- `admin.py`
18+
- `serializers.py`
19+
- `permissions.py`
20+
- Update ThingModel with fields you need
21+
- Make sure to update other modules that would be affected by Model customizations. E.g. serializers, tests, etc.
22+
- Rename `project/.env.sample` to `.env` and update as needed
23+
- Run makemigrations and migrate commands
24+
- Optional: Update `api_tester.py`

class-42/in-class-demo/cookie-stand-api/accounts/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from django.contrib import admin
2+
from django.contrib.auth.admin import UserAdmin
3+
4+
from .forms import CustomUserCreationForm, CustomUserChangeForm
5+
from .models import CustomUser
6+
7+
8+
class CustomUserAdmin(UserAdmin):
9+
add_form = CustomUserCreationForm
10+
form = CustomUserChangeForm
11+
model = CustomUser
12+
list_display = [
13+
"email",
14+
"username",
15+
]
16+
17+
18+
admin.site.register(CustomUser, CustomUserAdmin)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.apps import AppConfig
2+
3+
4+
class AccountsConfig(AppConfig):
5+
name = "accounts"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
2+
from .models import CustomUser
3+
4+
5+
class CustomUserCreationForm(UserCreationForm):
6+
class Meta:
7+
model = CustomUser
8+
fields = ("username", "email")
9+
10+
11+
class CustomUserChangeForm(UserChangeForm):
12+
class Meta:
13+
model = CustomUser
14+
fields = ("username", "email")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Generated by Django 3.1.7 on 2021-03-15 03:58
2+
3+
import django.contrib.auth.models
4+
import django.contrib.auth.validators
5+
from django.db import migrations, models
6+
import django.utils.timezone
7+
8+
9+
class Migration(migrations.Migration):
10+
11+
initial = True
12+
13+
dependencies = [
14+
('auth', '0012_alter_user_first_name_max_length'),
15+
]
16+
17+
operations = [
18+
migrations.CreateModel(
19+
name='CustomUser',
20+
fields=[
21+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
22+
('password', models.CharField(max_length=128, verbose_name='password')),
23+
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
24+
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
25+
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
26+
('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')),
27+
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
28+
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
29+
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
30+
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
31+
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
32+
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
33+
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')),
34+
],
35+
options={
36+
'verbose_name': 'user',
37+
'verbose_name_plural': 'users',
38+
'abstract': False,
39+
},
40+
managers=[
41+
('objects', django.contrib.auth.models.UserManager()),
42+
],
43+
),
44+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 4.0.1 on 2022-06-09 08:09
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('accounts', '0001_initial'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='customuser',
15+
name='id',
16+
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
17+
),
18+
]

class-42/in-class-demo/cookie-stand-api/accounts/migrations/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from django.contrib.auth.models import AbstractUser
2+
3+
4+
class CustomUser(AbstractUser):
5+
pass
6+
# add additional fields in here
7+
8+
def __str__(self):
9+
return self.username
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from rest_framework import serializers
2+
from .models import CustomUser
3+
4+
5+
class CustomUserSerializer(serializers.ModelSerializer):
6+
# be able to read json and save a new user
7+
# if we add functionality to view all users, we don't want the password
8+
# hash to be exposed
9+
10+
# the password field can be written to but not read from
11+
password = serializers.CharField(write_only=True)
12+
13+
def create(self, validated_data):
14+
password = validated_data.pop('password')
15+
user = CustomUser(**validated_data)
16+
user.set_password(password) # add in the encrypted password
17+
user.save()
18+
return user
19+
20+
class Meta:
21+
model = CustomUser
22+
fields = ('id', 'username', 'password', 'email') # can add more
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from rest_framework import status
2+
from rest_framework.response import Response
3+
from rest_framework.views import APIView
4+
from .serializers import CustomUserSerializer
5+
6+
7+
class CustomUserCreate(APIView):
8+
# Anyone can register!
9+
authentication_classes = ()
10+
permission_classes = ()
11+
12+
# this is the method that gets invoked when a user makes a POST
13+
# request to api/register
14+
def post(self, request):
15+
# use the serializer!
16+
serializer = CustomUserSerializer(data=request.data)
17+
if serializer.is_valid():
18+
user = serializer.save()
19+
# if this works, `user` will be truthy
20+
if user:
21+
json = serializer.data
22+
return Response(json, status=status.HTTP_201_CREATED)
23+
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

class-42/in-class-demo/cookie-stand-api/cookie_stands/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.contrib import admin
2+
from .models import CookieStand
3+
4+
# Register your models here.
5+
admin.site.register(CookieStand)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.apps import AppConfig
2+
3+
4+
class CookieStandsConfig(AppConfig):
5+
name = "cookie_stands"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Generated by Django 4.0.1 on 2022-06-09 08:08
2+
3+
from django.conf import settings
4+
from django.db import migrations, models
5+
import django.db.models.deletion
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
initial = True
11+
12+
dependencies = [
13+
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
14+
]
15+
16+
operations = [
17+
migrations.CreateModel(
18+
name='CookieStand',
19+
fields=[
20+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
21+
('location', models.CharField(max_length=256)),
22+
('description', models.TextField(blank=True)),
23+
('hourly_sales', models.JSONField(default=list, null=True)),
24+
('minimum_customers_per_hour', models.IntegerField(default=0)),
25+
('maximum_customers_per_hour', models.IntegerField(default=0)),
26+
('average_cookies_per_sale', models.FloatField(default=0)),
27+
('owner', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
28+
],
29+
),
30+
]

class-42/in-class-demo/cookie-stand-api/cookie_stands/migrations/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)