added models

This commit is contained in:
Boyan 2021-09-12 17:26:57 +03:00
parent 152764ed33
commit 1df0c86050
22 changed files with 468 additions and 3 deletions

4
.gitignore vendored
View File

@ -1,6 +1,4 @@
__django __django
reValuate/db.sqlite3
*.sqlite3
*/media/* */media/*
*.pyc *.pyc
*.sqlite3 db.sqlite3

22
reWrite/manage.py Executable file
View File

@ -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', 'reWrite.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()

View File

View File

@ -0,0 +1,7 @@
from django.contrib import admin
from .models import Media, Profile, Transaction
admin.site.register(Media)
admin.site.register(Profile)
admin.site.register(Transaction)

View File

@ -0,0 +1,5 @@
from django.apps import AppConfig
class RevaluateConfig(AppConfig):
name = 'reValuate'

View File

@ -0,0 +1,53 @@
# Generated by Django 3.1.6 on 2021-09-12 14:14
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import reValuate.models
class Migration(migrations.Migration):
initial = True
dependencies = [
('auth', '0012_alter_user_first_name_max_length'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='Profile',
fields=[
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='auth.user')),
('is_banned', models.BooleanField(default=False)),
('balance', models.IntegerField(default=0)),
],
),
migrations.CreateModel(
name='Transaction',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('date', models.DateTimeField(auto_now=True)),
('item', models.CharField(blank=True, default=None, max_length=30, null=True)),
('cashier', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='cashier', to=settings.AUTH_USER_MODEL)),
('client', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='client', to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Media',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('image', models.FileField(blank=True, null=True, upload_to=reValuate.models.images_path)),
('is_video', models.BooleanField(default=False)),
('is_approved', models.BooleanField(blank=True, default=None, max_length=3, null=True)),
('date', models.DateTimeField(auto_now=True)),
('approved_by', models.CharField(blank=True, default=None, max_length=30, null=True)),
('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name': 'media',
'verbose_name_plural': 'media',
},
),
]

View File

View File

@ -0,0 +1,44 @@
from django.db import models
from django.contrib.auth.models import User
def images_path(instance, filename):
# file will be uploaded to MEDIA_ROOT/user_<id>/<filename>
return '{0}/{1}'.format(instance.user.id, filename)
class Media(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE, blank=True, null=True)
image = models.FileField(upload_to=images_path, blank=True, null=True,)
is_video = models.BooleanField(default=False)
is_approved = models.BooleanField(blank=True, null=True, default=None, max_length=3)
date = models.DateTimeField(auto_now=True)
approved_by = models.CharField(max_length=30, blank=True, null=True, default=None, )
@property
def is_rejected(self) -> bool:
p = Profile.objects.get(user=self.user)
if p.is_banned:
return True
if not self.is_approved:
return True
return False
class Meta:
verbose_name = 'media'
verbose_name_plural = 'media'
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True)
is_banned = models.BooleanField(default=False)
balance = models.IntegerField(default=0)
class Transaction(models.Model):
cashier = models.ForeignKey(User, on_delete=models.CASCADE, related_name="cashier")
client = models.ForeignKey(User, on_delete=models.CASCADE, related_name="client")
date = models.DateTimeField(auto_now=True)
item = models.CharField(max_length=30, blank=True, null=True, default=None, )

View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

View File

@ -0,0 +1,8 @@
from django.shortcuts import render
from .models import Media, Profile, Transaction
def home_page(request):
return render(request, "index.html")

View File

16
reWrite/reWrite/asgi.py Normal file
View File

@ -0,0 +1,16 @@
"""
ASGI config for reWrite 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.1/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'reWrite.settings')
application = get_asgi_application()

126
reWrite/reWrite/settings.py Normal file
View File

@ -0,0 +1,126 @@
"""
Django settings for reWrite project.
Generated by 'django-admin startproject' using Django 3.1.6.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
import os
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/3.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'z=mr)w@&x-qryc8*6ci0=jtst#bjwygod029(xjps$!5w%rp%5'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = [
'127.0.0.1',
]
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'reValuate'
]
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 = 'reWrite.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'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 = 'reWrite.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/3.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',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/
LANGUAGE_CODE = 'bg-BG'
TIME_ZONE = 'Europe/Sofia'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/
STATIC_URL = '/static/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

23
reWrite/reWrite/urls.py Normal file
View File

@ -0,0 +1,23 @@
"""reWrite URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.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 path
from reValuate.views import home_page
urlpatterns = [
path('', home_page),
path('admin/', admin.site.urls),
]

16
reWrite/reWrite/wsgi.py Normal file
View File

@ -0,0 +1,16 @@
"""
WSGI config for reWrite 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/3.1/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'reWrite.settings')
application = get_wsgi_application()

View File

@ -0,0 +1,12 @@
<!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">
<title>Hello!</title>
</head>
<body>
hi
</body>
</html>

View File

@ -0,0 +1,45 @@
{% extends 'base.html' %}
{% block title %}Login{% endblock %}
{% block optionalParams %}
<style>
html{
background: linear-gradient(180deg, rgba(70,147,48,1) 33%, rgba(109,126,107,1) 100%) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
font-family: Arial, Helvetica, sans-serif;
}
.buttons{
background-color: #469330;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
#page-wrap{
padding: 20vh;
}
</style>
{% endblock %}
{% block content %}
<div class="centered" id="page-wrap" style="text-align:center;">
<h2>Влез в акаунта си</h2><br>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit" class="buttons">Влез</button><br><br>
<a href="{% url 'signup' %}">Нямаш акаунт? Регистрирай се.</a>
</form>
</div>
{% endblock %}

View File

@ -0,0 +1,8 @@
{% extends 'base.html' %}
{% block title %}Password reset complete{% endblock %}
{% block content %}
<h1>Password reset complete</h1>
<p>Your new password has been set. You can log in now on the <a href="{% url 'login' %}">log in page</a>.</p>
{% endblock %}

View File

@ -0,0 +1,20 @@
{% extends 'base.html' %}
{% block title %}Enter new password{% endblock %}
{% block content %}
{% if validlink %}
<h1>Set a new password!</h1>
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Change my password">
</form>
{% else %}
<p>The password reset link was invalid, possibly because it has already been used. Please request a new password reset.</p>
{% endif %}

View File

@ -0,0 +1,8 @@
{% extends 'base.html' %}
{% block title %}Email Sent{% endblock %}
{% block content %}
<h1>Check your inbox.</h1>
<p>We've emailed you instructions for setting your password. You should receive the email shortly!</p>
{% endblock %}

View File

@ -0,0 +1,14 @@
{% extends 'base.html' %}
{% block title %}Forgot Your Password?{% endblock %}
{% block content %}
<h1>Forgot your password?</h1>
<p>Enter your email address below, and we'll email instructions for setting a new one.</p>
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Send me instructions!">
</form>
{% endblock %}

View File

@ -0,0 +1,37 @@
{% extends 'base.html' %}
{% block title %}Sign Up{% endblock %}
{% block optionalParams %}
<style>
html{
background: linear-gradient(180deg, rgba(70,147,48,1) 33%, rgba(109,126,107,1) 100%) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
font-family: Arial, Helvetica, sans-serif;
}
#page-wrap{
padding: 20vh;
}
</style>
{% endblock %}
{% block content %}
<div class="centered" id="page-wrap">
<h2>Регистрирай се</h2><br><br>
<form method="post">
{% csrf_token %}
{% for field in form %}
<div class="fieldWrapper">
{{ field.errors }}
{{ field.label_tag }}<br> {{ field }}
</div><br>
{% endfor %}
<button type="submit" class="buttons"">Регистрация</button>
</form>
</div>
{% endblock %}