diff --git a/.gitignore b/.gitignore index 03a92de2..1ec9b4a7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ __django -reValuate/db.sqlite3 -*.sqlite3 */media/* *.pyc -*.sqlite3 +db.sqlite3 diff --git a/reWrite/manage.py b/reWrite/manage.py new file mode 100755 index 00000000..b5e70cab --- /dev/null +++ b/reWrite/manage.py @@ -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() diff --git a/reWrite/reValuate/__init__.py b/reWrite/reValuate/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/reWrite/reValuate/admin.py b/reWrite/reValuate/admin.py new file mode 100644 index 00000000..04a68bb6 --- /dev/null +++ b/reWrite/reValuate/admin.py @@ -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) \ No newline at end of file diff --git a/reWrite/reValuate/apps.py b/reWrite/reValuate/apps.py new file mode 100644 index 00000000..2b9a8d66 --- /dev/null +++ b/reWrite/reValuate/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class RevaluateConfig(AppConfig): + name = 'reValuate' diff --git a/reWrite/reValuate/migrations/0001_initial.py b/reWrite/reValuate/migrations/0001_initial.py new file mode 100644 index 00000000..8bc45492 --- /dev/null +++ b/reWrite/reValuate/migrations/0001_initial.py @@ -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', + }, + ), + ] diff --git a/reWrite/reValuate/migrations/__init__.py b/reWrite/reValuate/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/reWrite/reValuate/models.py b/reWrite/reValuate/models.py new file mode 100644 index 00000000..d3c044ae --- /dev/null +++ b/reWrite/reValuate/models.py @@ -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_/ + 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, ) + diff --git a/reWrite/reValuate/tests.py b/reWrite/reValuate/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/reWrite/reValuate/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/reWrite/reValuate/views.py b/reWrite/reValuate/views.py new file mode 100644 index 00000000..4fe947d7 --- /dev/null +++ b/reWrite/reValuate/views.py @@ -0,0 +1,8 @@ +from django.shortcuts import render +from .models import Media, Profile, Transaction + + +def home_page(request): + + return render(request, "index.html") + diff --git a/reWrite/reWrite/__init__.py b/reWrite/reWrite/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/reWrite/reWrite/asgi.py b/reWrite/reWrite/asgi.py new file mode 100644 index 00000000..72a047ca --- /dev/null +++ b/reWrite/reWrite/asgi.py @@ -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() diff --git a/reWrite/reWrite/settings.py b/reWrite/reWrite/settings.py new file mode 100644 index 00000000..38de665f --- /dev/null +++ b/reWrite/reWrite/settings.py @@ -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') + diff --git a/reWrite/reWrite/urls.py b/reWrite/reWrite/urls.py new file mode 100644 index 00000000..e6e75eb5 --- /dev/null +++ b/reWrite/reWrite/urls.py @@ -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), +] diff --git a/reWrite/reWrite/wsgi.py b/reWrite/reWrite/wsgi.py new file mode 100644 index 00000000..8d4da285 --- /dev/null +++ b/reWrite/reWrite/wsgi.py @@ -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() diff --git a/reWrite/templates/index.html b/reWrite/templates/index.html new file mode 100644 index 00000000..07bed6e2 --- /dev/null +++ b/reWrite/templates/index.html @@ -0,0 +1,12 @@ + + + + + + + Hello! + + + hi + + \ No newline at end of file diff --git a/reWrite/templates/registration/login.html b/reWrite/templates/registration/login.html new file mode 100644 index 00000000..bf318dfc --- /dev/null +++ b/reWrite/templates/registration/login.html @@ -0,0 +1,45 @@ +{% extends 'base.html' %} + +{% block title %}Login{% endblock %} +{% block optionalParams %} + +{% endblock %} + +{% block content %} +
+

Влез в акаунта си


+ +
+ {% csrf_token %} + {{ form.as_p }} +

+ Нямаш акаунт? Регистрирай се. +
+
+{% endblock %} diff --git a/reWrite/templates/registration/password_reset_complete.html b/reWrite/templates/registration/password_reset_complete.html new file mode 100644 index 00000000..ab769f65 --- /dev/null +++ b/reWrite/templates/registration/password_reset_complete.html @@ -0,0 +1,8 @@ +{% extends 'base.html' %} + +{% block title %}Password reset complete{% endblock %} + +{% block content %} +

Password reset complete

+

Your new password has been set. You can log in now on the log in page.

+{% endblock %} diff --git a/reWrite/templates/registration/password_reset_confirm.html b/reWrite/templates/registration/password_reset_confirm.html new file mode 100644 index 00000000..2f343fd3 --- /dev/null +++ b/reWrite/templates/registration/password_reset_confirm.html @@ -0,0 +1,20 @@ +{% extends 'base.html' %} + +{% block title %}Enter new password{% endblock %} + +{% block content %} + +{% if validlink %} + +

Set a new password!

+
+ {% csrf_token %} + {{ form.as_p }} + +
+ +{% else %} + +

The password reset link was invalid, possibly because it has already been used. Please request a new password reset.

+ +{% endif %} diff --git a/reWrite/templates/registration/password_reset_done.html b/reWrite/templates/registration/password_reset_done.html new file mode 100644 index 00000000..8a47de55 --- /dev/null +++ b/reWrite/templates/registration/password_reset_done.html @@ -0,0 +1,8 @@ +{% extends 'base.html' %} + +{% block title %}Email Sent{% endblock %} + +{% block content %} +

Check your inbox.

+

We've emailed you instructions for setting your password. You should receive the email shortly!

+{% endblock %} diff --git a/reWrite/templates/registration/password_reset_form.html b/reWrite/templates/registration/password_reset_form.html new file mode 100644 index 00000000..1d39fc3a --- /dev/null +++ b/reWrite/templates/registration/password_reset_form.html @@ -0,0 +1,14 @@ +{% extends 'base.html' %} + +{% block title %}Forgot Your Password?{% endblock %} + +{% block content %} +

Forgot your password?

+

Enter your email address below, and we'll email instructions for setting a new one.

+ +
+ {% csrf_token %} + {{ form.as_p }} + +
+{% endblock %} diff --git a/reWrite/templates/registration/signup.html b/reWrite/templates/registration/signup.html new file mode 100644 index 00000000..3a70f12d --- /dev/null +++ b/reWrite/templates/registration/signup.html @@ -0,0 +1,37 @@ +{% extends 'base.html' %} + +{% block title %}Sign Up{% endblock %} +{% block optionalParams %} + +{% endblock %} +{% block content %} +
+ +

Регистрирай се



+
+ {% csrf_token %} + {% for field in form %} +
+ {{ field.errors }} + {{ field.label_tag }}
{{ field }} +

+{% endfor %} + +
+
+{% endblock %} +