Skip to content

Commit

Permalink
bare-bones of web app
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Prikhno committed Mar 25, 2023
1 parent 7149d74 commit a99f0ab
Show file tree
Hide file tree
Showing 26 changed files with 1,205 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
db.sqlite3
.DS_store
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Pekoe Web repo
⚠️ **WIP**

A web app for 🌿**PEKOE**🌿, crypto safe tips service. Written in Python3 x Django.

### 🔧 Development guide
#### Setup development environment
```
python3 -m venv ~/.virtualenvs/djangodev
source ~/.virtualenvs/djangodev/bin/activate
python3 -m pip install Django django-bulma django-widget-tweaks
python3 -m django --version
```
#### Migrations and admin creation
```
python3 manage.py makemigrations tips
python3 manage.py migrate
python3 manage.py createsuperuser
```
#### Startup
```
python3 manage.py runserver 0.0.0.0:8000
```
Access server on:
- [127.0.0.1:8000/admin]() -- administration app
- [127.0.0.1:8000/tips]() -- web app

## ⚠️ License
[![License: MIT](https://img.shields.io/badge/license-MIT-blue)](https://www.tldrlegal.com/license/mit-license)
22 changes: 22 additions & 0 deletions 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', 'pekoe_web.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 added pekoe_web/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions pekoe_web/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for pekoe_web 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/4.1/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

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

application = get_asgi_application()
124 changes: 124 additions & 0 deletions pekoe_web/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
"""
Django settings for pekoe_web project.
Generated by 'django-admin startproject' using Django 4.1.7.
For more information on this file, see
https://docs.djangoproject.com/en/4.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.1/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-+)sos$oerfmq)y3rti*$g(zg*8=^1rw^sbrv02l-=y7gaa-_5f'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

# Application definition

INSTALLED_APPS = [
'tips.apps.TipsConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'bulma',
'widget_tweaks',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'pekoe_web.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'pekoe_web.wsgi.application'


# Database
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}


# Password validation
# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
AUTH_USER_MODEL = "tips.User"


# Internationalization
# https://docs.djangoproject.com/en/4.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Europe/Moscow'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.1/howto/static-files/

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
22 changes: 22 additions & 0 deletions pekoe_web/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""pekoe_web URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import include, path

urlpatterns = [
path('tips/', include('tips.urls')),
path('admin/', admin.site.urls),
]
16 changes: 16 additions & 0 deletions pekoe_web/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for pekoe_web project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.1/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

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

application = get_wsgi_application()
Empty file added tips/__init__.py
Empty file.
9 changes: 9 additions & 0 deletions tips/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.contrib import admin
from .models import Cafe, User, Customer, Waiter, CafeAdmin
# Register your models here.

admin.site.register(Cafe)
admin.site.register(User)
admin.site.register(Customer)
admin.site.register(Waiter)
admin.site.register(CafeAdmin)
6 changes: 6 additions & 0 deletions tips/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class TipsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'tips'
23 changes: 23 additions & 0 deletions tips/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from django import forms
from django.contrib.auth.forms import UserCreationForm
from .models import User

class NewUserForm(UserCreationForm):
username = forms.CharField(max_length=20, required=True)
first_name = forms.CharField(max_length=20)
last_name = forms.CharField(max_length=20)
email = forms.EmailField(required=True, widget=forms.EmailInput)

class Meta:
model = User
fields = ("username", "first_name", "last_name", "email", "password1", "password2")

def save(self, commit=True):
user = super(NewUserForm, self).save(commit=False)
user.username = self.cleaned_data["username"]
user.first_name = self.cleaned_data["first_name"]
user.last_name = self.cleaned_data["last_name"]
user.email = self.cleaned_data["email"]
if commit:
user.save()
return user
87 changes: 87 additions & 0 deletions tips/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Generated by Django 4.1.7 on 2023-03-19 16:12

from django.conf import settings
import django.contrib.auth.models
from django.db import migrations, models
import django.db.models.deletion
import uuid


class Migration(migrations.Migration):

initial = True

dependencies = [
('auth', '0012_alter_user_first_name_max_length'),
]

operations = [
migrations.CreateModel(
name='User',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')),
('username', models.CharField(default='379642975d764d0c', max_length=20, unique=True)),
('first_name', models.CharField(max_length=20)),
('last_name', models.CharField(max_length=20)),
('email', models.CharField(max_length=50)),
('is_active', models.BooleanField(default=True)),
('is_staff', models.BooleanField(default=False)),
('is_superuser', models.BooleanField(default=False)),
('last_login', models.DateTimeField(blank=True, null=True)),
('date_joined', models.DateTimeField(auto_now_add=True)),
('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')),
('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')),
],
options={
'abstract': False,
},
managers=[
('objects', django.contrib.auth.models.UserManager()),
],
),
migrations.CreateModel(
name='Cafe',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('slug', models.CharField(default='1a273adb5f234540', max_length=20, unique=True)),
('title', models.CharField(max_length=50)),
('location', models.CharField(max_length=100)),
],
),
migrations.CreateModel(
name='Customer',
fields=[
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to=settings.AUTH_USER_MODEL)),
('customer_wallet', models.CharField(max_length=50)),
],
),
migrations.CreateModel(
name='Waiter',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('waiter_wallet', models.CharField(max_length=50)),
('cafe', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='tips.cafe')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='CafeAdmin',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('cafe', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='tips.cafe')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Transaction',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('datetime', models.DateTimeField(auto_now=True)),
('amount', models.PositiveBigIntegerField()),
('comment', models.CharField(max_length=200)),
('waiter', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='tips.waiter')),
('customer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='tips.customer')),
],
),
]
Empty file added tips/migrations/__init__.py
Empty file.
Loading

0 comments on commit a99f0ab

Please sign in to comment.