└── blog ├── .DS_Store ├── blog ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-38.pyc │ ├── settings.cpython-38.pyc │ ├── urls.cpython-38.pyc │ └── wsgi.cpython-38.pyc ├── asgi.py ├── settings.py ├── urls.py └── wsgi.py ├── bookstore ├── .DS_Store ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-38.pyc │ ├── admin.cpython-38.pyc │ ├── apps.cpython-38.pyc │ ├── decorators.cpython-38.pyc │ ├── filters.cpython-38.pyc │ ├── forms.cpython-38.pyc │ ├── models.cpython-38.pyc │ ├── signals.cpython-38.pyc │ ├── urls.cpython-38.pyc │ └── views.cpython-38.pyc ├── admin.py ├── apps.py ├── decorators.py ├── filters.py ├── forms.py ├── migrations │ ├── 0001_initial.py │ ├── 0002_book_order.py │ ├── 0003_auto_20200920_2106.py │ ├── 0004_book_tags.py │ ├── 0005_customer_user.py │ ├── 0006_customer_avatar.py │ ├── 0007_auto_20200926_1542.py │ ├── __init__.py │ └── __pycache__ │ │ ├── 0001_initial.cpython-38.pyc │ │ ├── 0002_book_order.cpython-38.pyc │ │ ├── 0003_auto_20200920_2106.cpython-38.pyc │ │ ├── 0004_book_tags.cpython-38.pyc │ │ ├── 0005_customer_user.cpython-38.pyc │ │ ├── 0006_customer_avatar.cpython-38.pyc │ │ ├── 0007_auto_20200926_1542.cpython-38.pyc │ │ └── __init__.cpython-38.pyc ├── models.py ├── signals.py ├── templates │ ├── .DS_Store │ └── bookstore │ │ ├── books.html │ │ ├── customer.html │ │ ├── dashboard.html │ │ ├── delete_form.html │ │ ├── login.html │ │ ├── main.html │ │ ├── my_order_form.html │ │ ├── navbar.html │ │ ├── password_reset.html │ │ ├── password_reset_done.html │ │ ├── password_reset_form.html │ │ ├── password_reset_sent.html │ │ ├── profile.html │ │ ├── profile_info.html │ │ └── register.html ├── tests.py ├── urls.py └── views.py ├── db.sqlite3 ├── manage.py └── static ├── .DS_Store ├── css └── style.css └── images ├── .DS_Store ├── 1.jpg ├── 1_KGyfYbC.jpg ├── bP7gDPl1.jpg ├── bP7gDPl1_2aEMZQQ.jpg ├── book.png └── preson.png /blog/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/.DS_Store -------------------------------------------------------------------------------- /blog/blog/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/blog/__init__.py -------------------------------------------------------------------------------- /blog/blog/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/blog/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /blog/blog/__pycache__/settings.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/blog/__pycache__/settings.cpython-38.pyc -------------------------------------------------------------------------------- /blog/blog/__pycache__/urls.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/blog/__pycache__/urls.cpython-38.pyc -------------------------------------------------------------------------------- /blog/blog/__pycache__/wsgi.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/blog/__pycache__/wsgi.cpython-38.pyc -------------------------------------------------------------------------------- /blog/blog/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for blog project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'blog.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /blog/blog/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for blog project. 3 | 4 | Generated by 'django-admin startproject' using Django 3.1.1. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.1/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/3.1/ref/settings/ 11 | """ 12 | 13 | from pathlib import Path 14 | 15 | # Build paths inside the project like this: BASE_DIR / 'subdir'. 16 | BASE_DIR = Path(__file__).resolve().parent.parent 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'v!u)j1=c$$lise*g-s=5rrxdhzs)&h*l7z7mvgbp(c--y*z_4p' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = [] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = [ 34 | 'django.contrib.admin', 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'django.contrib.messages', 39 | 'django.contrib.staticfiles', 40 | 'bookstore', 41 | 'django_filters', 42 | # 'bookstore.apps.BookstoreConfig' 43 | 44 | ] 45 | 46 | MIDDLEWARE = [ 47 | 'django.middleware.security.SecurityMiddleware', 48 | 'django.contrib.sessions.middleware.SessionMiddleware', 49 | 'django.middleware.common.CommonMiddleware', 50 | 'django.middleware.csrf.CsrfViewMiddleware', 51 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 52 | 'django.contrib.messages.middleware.MessageMiddleware', 53 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 54 | ] 55 | 56 | ROOT_URLCONF = 'blog.urls' 57 | 58 | TEMPLATES = [ 59 | { 60 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 61 | 'DIRS': [], 62 | 'APP_DIRS': True, 63 | 'OPTIONS': { 64 | 'context_processors': [ 65 | 'django.template.context_processors.debug', 66 | 'django.template.context_processors.request', 67 | 'django.contrib.auth.context_processors.auth', 68 | 'django.contrib.messages.context_processors.messages', 69 | ], 70 | }, 71 | }, 72 | ] 73 | 74 | WSGI_APPLICATION = 'blog.wsgi.application' 75 | 76 | 77 | # Database 78 | # https://docs.djangoproject.com/en/3.1/ref/settings/#databases 79 | 80 | DATABASES = { 81 | 'default': { 82 | 'ENGINE': 'django.db.backends.sqlite3', 83 | 'NAME': BASE_DIR / 'db.sqlite3', 84 | } 85 | } 86 | 87 | 88 | 89 | 90 | # DATABASES = { 91 | # 'default': { 92 | # 'ENGINE': 'django.db.backends.postgresql', 93 | # 'NAME': 'MYData', 94 | # 'USER': 'postgres', 95 | # 'PASSWORD': 'Muhammed1984', 96 | # 'HOST':'localhost', 97 | # 'PORT':'5432' 98 | # } 99 | # } 100 | 101 | 102 | # Password validation 103 | # https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators 104 | 105 | AUTH_PASSWORD_VALIDATORS = [ 106 | { 107 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 108 | }, 109 | { 110 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 111 | }, 112 | { 113 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 114 | }, 115 | { 116 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 117 | }, 118 | ] 119 | 120 | 121 | # Internationalization 122 | # https://docs.djangoproject.com/en/3.1/topics/i18n/ 123 | 124 | LANGUAGE_CODE = 'en-us' 125 | 126 | TIME_ZONE = 'UTC' 127 | 128 | USE_I18N = True 129 | 130 | USE_L10N = True 131 | 132 | USE_TZ = True 133 | 134 | 135 | # Static files (CSS, JavaScript, Images) 136 | # https://docs.djangoproject.com/en/3.1/howto/static-files/ 137 | import os 138 | 139 | STATIC_URL = '/static/' 140 | 141 | MEDIA_URL = '/images/' 142 | 143 | STATICFILES_DIRS = [ 144 | os.path.join(BASE_DIR, 'static') 145 | ] 146 | 147 | 148 | MEDIA_ROOT = os.path.join(BASE_DIR, 'static/images') 149 | 150 | 151 | 152 | EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' 153 | EMAIL_HOST = 'smtp.gmail.com' 154 | EMAIL_PORT = 587 155 | EMAIL_USE_TLS = True 156 | EMAIL_HOST_USER = 'test@gmail.com' 157 | EMAIL_HOST_PASSWORD = '1234567' 158 | 159 | 160 | GOOGLE_RECAPTCHA_SECRET_KEY= '6Ldq_9AZAAAAAEBLVbknRrtgQfTZVBcDZXNgG6jL' -------------------------------------------------------------------------------- /blog/blog/urls.py: -------------------------------------------------------------------------------- 1 | """blog URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/3.1/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import path,include 18 | 19 | 20 | from django.conf.urls.static import static 21 | 22 | from django.conf import settings 23 | 24 | 25 | 26 | 27 | urlpatterns = [ 28 | path('admin/', admin.site.urls), 29 | path('' , include('bookstore.urls')) 30 | 31 | ] 32 | 33 | urlpatterns += static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT) 34 | -------------------------------------------------------------------------------- /blog/blog/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for blog project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'blog.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /blog/bookstore/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/.DS_Store -------------------------------------------------------------------------------- /blog/bookstore/__init__.py: -------------------------------------------------------------------------------- 1 | default_app_config = "bookstore.apps.BookstoreConfig" -------------------------------------------------------------------------------- /blog/bookstore/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/__pycache__/admin.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/__pycache__/admin.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/__pycache__/apps.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/__pycache__/apps.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/__pycache__/decorators.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/__pycache__/decorators.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/__pycache__/filters.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/__pycache__/filters.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/__pycache__/forms.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/__pycache__/forms.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/__pycache__/models.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/__pycache__/models.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/__pycache__/signals.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/__pycache__/signals.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/__pycache__/urls.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/__pycache__/urls.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/__pycache__/views.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/__pycache__/views.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | 5 | 6 | from .models import * 7 | 8 | admin.site.register(Customer) 9 | 10 | admin.site.register(Book) 11 | 12 | admin.site.register(Order) 13 | admin.site.register(Tag) -------------------------------------------------------------------------------- /blog/bookstore/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class BookstoreConfig(AppConfig): 5 | name = 'bookstore' 6 | 7 | def ready(self): 8 | import bookstore.signals 9 | -------------------------------------------------------------------------------- /blog/bookstore/decorators.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import redirect 2 | from django.http import HttpResponse 3 | 4 | 5 | 6 | 7 | def notLoggedUsers(view_func): 8 | def wrapper_func(request , *args,**kwargs): 9 | if request.user.is_authenticated: 10 | return redirect('home') 11 | else: 12 | return view_func(request , *args,**kwargs) 13 | return wrapper_func 14 | 15 | 16 | def allowedUsers(allowedGroups=[]): 17 | def decorator(view_func): 18 | def wrapper_func(request , *args,**kwargs): 19 | group = None 20 | if request.user.groups.exists(): 21 | group = request.user.groups.all()[0].name 22 | if group in allowedGroups: 23 | return view_func(request , *args,**kwargs) 24 | else: 25 | return redirect('user_profile') 26 | 27 | return wrapper_func 28 | return decorator 29 | 30 | 31 | 32 | 33 | def forAdmins(view_func): 34 | def wrapper_func(request , *args,**kwargs): 35 | group = None 36 | if request.user.groups.exists(): 37 | group = request.user.groups.all()[0].name 38 | if group == 'admin': 39 | return view_func(request , *args,**kwargs) 40 | if group == 'customer': 41 | return redirect('user_profile') 42 | 43 | return wrapper_func -------------------------------------------------------------------------------- /blog/bookstore/filters.py: -------------------------------------------------------------------------------- 1 | import django_filters 2 | 3 | from .models import * 4 | 5 | class OrderFilter(django_filters.FilterSet): 6 | class Meta: 7 | model = Order 8 | fields = '__all__' 9 | # fields = ['book' , 'status'] 10 | # exclude = ['book' , 'status'] -------------------------------------------------------------------------------- /blog/bookstore/forms.py: -------------------------------------------------------------------------------- 1 | from django.forms import ModelForm 2 | from django.contrib.auth.models import User 3 | from django.contrib.auth.forms import UserCreationForm 4 | 5 | 6 | from .models import Order , Customer 7 | 8 | class OrderForm(ModelForm): 9 | class Meta: 10 | model = Order 11 | fields ="__all__" 12 | 13 | 14 | class CustomerForm(ModelForm): 15 | class Meta: 16 | model = Customer 17 | fields ="__all__" 18 | exclude = ['user' ] 19 | 20 | 21 | class CreateNewUser(UserCreationForm): 22 | class Meta: 23 | model = User 24 | fields =['username','email','password1','password2'] 25 | 26 | -------------------------------------------------------------------------------- /blog/bookstore/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.1.1 on 2020-09-20 20:33 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | initial = True 9 | 10 | dependencies = [ 11 | ] 12 | 13 | operations = [ 14 | migrations.CreateModel( 15 | name='Customer', 16 | fields=[ 17 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 18 | ('name', models.CharField(max_length=190, null=True)), 19 | ('email', models.CharField(max_length=190, null=True)), 20 | ('phone', models.CharField(max_length=190, null=True)), 21 | ('age', models.CharField(max_length=190, null=True)), 22 | ('date_created', models.DateTimeField(auto_now_add=True, null=True)), 23 | ], 24 | ), 25 | ] 26 | -------------------------------------------------------------------------------- /blog/bookstore/migrations/0002_book_order.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.1.1 on 2020-09-20 20:51 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('bookstore', '0001_initial'), 10 | ] 11 | 12 | operations = [ 13 | migrations.CreateModel( 14 | name='Book', 15 | fields=[ 16 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 17 | ('name', models.CharField(max_length=190, null=True)), 18 | ('author', models.CharField(max_length=190, null=True)), 19 | ('price', models.FloatField(null=True)), 20 | ('category', models.CharField(choices=[('Classics', 'Classics'), ('Comic Book', 'Comic Book'), ('Fantasy', 'Fantasy'), ('Horror', 'Horror')], max_length=190, null=True)), 21 | ('description', models.CharField(max_length=200, null=True)), 22 | ('date_created', models.DateTimeField(auto_now_add=True, null=True)), 23 | ], 24 | ), 25 | migrations.CreateModel( 26 | name='Order', 27 | fields=[ 28 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 29 | ('date_created', models.DateTimeField(auto_now_add=True, null=True)), 30 | ('status', models.CharField(choices=[('Pending', 'Pending'), ('Delivered', 'Delivered'), ('in progress', 'in progress'), ('out of order', 'out of order')], max_length=200, null=True)), 31 | ], 32 | ), 33 | ] 34 | -------------------------------------------------------------------------------- /blog/bookstore/migrations/0003_auto_20200920_2106.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.1.1 on 2020-09-20 21:06 2 | 3 | from django.db import migrations, models 4 | import django.db.models.deletion 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | dependencies = [ 10 | ('bookstore', '0002_book_order'), 11 | ] 12 | 13 | operations = [ 14 | migrations.CreateModel( 15 | name='Tag', 16 | fields=[ 17 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 18 | ('name', models.CharField(max_length=190, null=True)), 19 | ], 20 | ), 21 | migrations.AddField( 22 | model_name='order', 23 | name='book', 24 | field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='bookstore.book'), 25 | ), 26 | migrations.AddField( 27 | model_name='order', 28 | name='customer', 29 | field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='bookstore.customer'), 30 | ), 31 | migrations.AddField( 32 | model_name='order', 33 | name='tags', 34 | field=models.ManyToManyField(to='bookstore.Tag'), 35 | ), 36 | ] 37 | -------------------------------------------------------------------------------- /blog/bookstore/migrations/0004_book_tags.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.1.1 on 2020-09-20 21:09 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('bookstore', '0003_auto_20200920_2106'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='book', 15 | name='tags', 16 | field=models.ManyToManyField(to='bookstore.Tag'), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /blog/bookstore/migrations/0005_customer_user.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.1.1 on 2020-09-23 18:46 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 | dependencies = [ 11 | migrations.swappable_dependency(settings.AUTH_USER_MODEL), 12 | ('bookstore', '0004_book_tags'), 13 | ] 14 | 15 | operations = [ 16 | migrations.AddField( 17 | model_name='customer', 18 | name='user', 19 | field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), 20 | ), 21 | ] 22 | -------------------------------------------------------------------------------- /blog/bookstore/migrations/0006_customer_avatar.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.1.1 on 2020-09-26 14:48 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('bookstore', '0005_customer_user'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='customer', 15 | name='avatar', 16 | field=models.ImageField(blank=True, null=True, upload_to=''), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /blog/bookstore/migrations/0007_auto_20200926_1542.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.1.1 on 2020-09-26 15:42 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('bookstore', '0006_customer_avatar'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AlterField( 14 | model_name='customer', 15 | name='avatar', 16 | field=models.ImageField(blank=True, default='preson.png', null=True, upload_to=''), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /blog/bookstore/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/migrations/__init__.py -------------------------------------------------------------------------------- /blog/bookstore/migrations/__pycache__/0001_initial.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/migrations/__pycache__/0001_initial.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/migrations/__pycache__/0002_book_order.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/migrations/__pycache__/0002_book_order.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/migrations/__pycache__/0003_auto_20200920_2106.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/migrations/__pycache__/0003_auto_20200920_2106.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/migrations/__pycache__/0004_book_tags.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/migrations/__pycache__/0004_book_tags.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/migrations/__pycache__/0005_customer_user.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/migrations/__pycache__/0005_customer_user.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/migrations/__pycache__/0006_customer_avatar.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/migrations/__pycache__/0006_customer_avatar.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/migrations/__pycache__/0007_auto_20200926_1542.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/migrations/__pycache__/0007_auto_20200926_1542.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/migrations/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/migrations/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.contrib.auth.models import User 3 | # Create your models here. 4 | 5 | 6 | class Customer(models.Model): 7 | user = models.OneToOneField(User,null=True, on_delete=models.CASCADE) 8 | name = models.CharField(max_length=190, null=True) 9 | email = models.CharField(max_length=190, null=True) 10 | phone = models.CharField(max_length=190, null=True) 11 | age = models.CharField(max_length=190, null=True) 12 | avatar = models.ImageField(blank=True, null=True, default="preson.png") 13 | date_created = models.DateTimeField(auto_now_add=True, null=True) 14 | 15 | def __str__(self): 16 | return self.name 17 | 18 | 19 | 20 | class Tag(models.Model): 21 | name = models.CharField(max_length=190, null=True) 22 | 23 | def __str__(self): 24 | return self.name 25 | 26 | 27 | class Book(models.Model): 28 | CATEGORY = ( 29 | ('Classics','Classics'), 30 | ('Comic Book','Comic Book'), 31 | ('Fantasy','Fantasy'), 32 | ('Horror','Horror') 33 | ) 34 | name = models.CharField(max_length=190, null=True) 35 | author = models.CharField(max_length=190, null=True) 36 | price = models.FloatField( null=True) 37 | category = models.CharField(max_length=190, null=True, choices=CATEGORY) 38 | description = models.CharField(max_length=200, null=True) 39 | tags = models.ManyToManyField(Tag) 40 | date_created = models.DateTimeField(auto_now_add=True, null=True) 41 | 42 | def __str__(self): 43 | return self.name 44 | 45 | 46 | 47 | 48 | 49 | class Order(models.Model): 50 | STATUS= ( 51 | ('Pending','Pending'), 52 | ('Delivered','Delivered'), 53 | ('in progress','in progress'), 54 | ('out of order','out of order') 55 | ) 56 | 57 | customer = models.ForeignKey(Customer, null=True, on_delete=models.SET_NULL) 58 | book = models.ForeignKey(Book, null=True, on_delete=models.SET_NULL) 59 | tags = models.ManyToManyField(Tag) 60 | date_created = models.DateTimeField(auto_now_add=True, null=True) 61 | status = models.CharField(max_length=200, null=True,choices=STATUS) -------------------------------------------------------------------------------- /blog/bookstore/signals.py: -------------------------------------------------------------------------------- 1 | from django.db.models.signals import post_save 2 | from django.contrib.auth.models import User, Group 3 | from .models import Customer 4 | 5 | 6 | def customer_create_profile(sender , instance ,created , **kwargs): 7 | if created: 8 | group = Group.objects.get(name="customer") 9 | instance.groups.add(group) 10 | 11 | Customer.objects.create( 12 | user = instance, 13 | name= instance.username 14 | ) 15 | 16 | print('Customer profile created ! ') 17 | 18 | post_save.connect(customer_create_profile, sender=User) -------------------------------------------------------------------------------- /blog/bookstore/templates/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/templates/.DS_Store -------------------------------------------------------------------------------- /blog/bookstore/templates/bookstore/books.html: -------------------------------------------------------------------------------- 1 | {% extends 'bookstore/main.html'%} 2 | 3 | {% block content %} 4 | 5 |

Books

6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | {% for item in books %} 21 | 22 | 23 | 24 | 25 | 26 | {% endfor %} 27 | 28 | 29 |
NamePriceAuthor
{{item.name}}{{item.price}}{{item.author}}
30 |
31 | 32 | 33 | {% endblock %} 34 | -------------------------------------------------------------------------------- /blog/bookstore/templates/bookstore/customer.html: -------------------------------------------------------------------------------- 1 | {% extends 'bookstore/main.html'%} 2 | 3 | {% block content %} 4 | 5 |

Customer

6 | 7 | 8 | 9 | 10 |
11 |
12 |
13 | Create Order 14 |
15 | 16 |
17 |
18 | 19 |
20 | 21 |
22 |
23 |
24 |
25 | {{myFilter.form}} 26 | 27 |
28 |
29 | 30 |
31 |
32 | 33 |
34 | 35 | 36 | 37 | 38 | 39 |
40 |
41 |
42 | Full name: {{customer.name}} 43 |
44 |
45 | Email: {{customer.email}} 46 |
47 |
48 | Age : {{customer.age}} 49 |
50 |
51 | Phone : {{customer.phone}} 52 |
53 |
54 | Number of Orders : {{number_orders}} 55 |
56 |
57 |
58 | 59 | 60 |
61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | {% for item in orders %} 73 | 74 | 75 | 76 | 77 | 78 | 82 | 83 | {% endfor %} 84 | 85 |
BookCategoryDatestatusActions
{{item.book}}{{item.book.category}}{{item.date_created}}{{item.status}} 79 | 80 | 81 |
86 |
87 | 88 | 89 | 90 | 91 | 92 | {% endblock %} 93 | -------------------------------------------------------------------------------- /blog/bookstore/templates/bookstore/dashboard.html: -------------------------------------------------------------------------------- 1 | {% extends 'bookstore/main.html'%} 2 | 3 | {% block content %} 4 | 5 |

Dashboard

6 | 7 | 8 |
9 |
10 |
11 | Total Orders : {{t_orders}} 12 |
13 |
14 | Pending : {{p_orders}} 15 |
16 |
17 | Delivered : {{d_orders}} 18 |
19 |
20 | In Progress : {{in_orders}} 21 |
22 |
23 | Out of Order : {{out_orders}} 24 |
25 |
26 |
27 | 28 | 29 |
30 |
31 |
32 |
33 |
34 |
Customers
35 |
create
36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | {% for item in customers %} 48 | 49 | 50 | 51 | 52 | 53 | 54 | {% endfor %} 55 | 56 | 57 |
nameemailageShow
{{item.name}}{{item.email}}{{item.age}}
58 |
59 |
60 |
61 |
62 |
63 |
64 |
Orders
65 | {% comment %}
create
{% endcomment %} 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | {% for item in orders %} 79 | 80 | 81 | 82 | 83 | 84 | 88 | 89 | {% endfor %} 90 | 91 | 92 |
DatecustomerbookstatusAction
{{item.date_created}}{{item.customer}}{{item.book}}{{item.status}} 85 | 86 | 87 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
Card title
102 |
Card subtitle
103 |

Some quick example text to build on the card title and make up the bulk of the card's content.

104 | Card link 105 | Another link 106 |
107 |
108 |
109 |
110 |
111 |
112 |
Card title
113 |
Card subtitle
114 |

Some quick example text to build on the card title and make up the bulk of the card's content.

115 | Card link 116 | Another link 117 |
118 |
119 |
120 | 121 |
122 |
123 | 124 | {% endblock %} 125 | 126 | -------------------------------------------------------------------------------- /blog/bookstore/templates/bookstore/delete_form.html: -------------------------------------------------------------------------------- 1 | {% extends 'bookstore/main.html'%} 2 | {% load static %} 3 | 4 | {% block content %} 5 | 6 |
7 |
8 | 9 |

Are you sure ?

10 | 11 |
12 | {% csrf_token %} 13 | Return 14 | 15 | 16 |
17 | 18 |
19 |
20 | 21 | 22 | 23 | 24 | {% endblock %} 25 | -------------------------------------------------------------------------------- /blog/bookstore/templates/bookstore/login.html: -------------------------------------------------------------------------------- 1 | {% load static %} 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 |

Login page

14 |
15 |
16 | 17 | 18 |
19 |

Login

20 | 21 |
22 | {% csrf_token %} 23 |
24 | 25 | 26 |
27 |
28 | 29 | 30 |
31 | 32 | 33 |
34 | 35 | 36 | Register 37 | 38 | Frogot password 39 | 40 | {% for msg in messages %} 41 |

{{msg}}

42 |
43 | 44 | 45 | 46 | {% endfor %} -------------------------------------------------------------------------------- /blog/bookstore/templates/bookstore/main.html: -------------------------------------------------------------------------------- 1 | {% load static %} 2 | 3 | 4 | 5 | 6 | 7 | Book Store 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | {% include 'bookstore/navbar.html'%} 21 | 22 | 23 | {% block content %} 24 | 25 | 26 | {% endblock %} 27 | 28 | 29 |

Footer

30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /blog/bookstore/templates/bookstore/my_order_form.html: -------------------------------------------------------------------------------- 1 | {% extends 'bookstore/main.html'%} 2 | {% load static %} 3 | 4 | {% block content %} 5 | 6 | 7 | 8 |
9 |
10 | 11 |
12 | {% csrf_token %} 13 | {{ formset.management_form }} 14 | {% for item in formset %} 15 | {{item}}
16 | {% endfor %} 17 | 18 |
19 | 20 |
21 |
22 | 23 | 24 | 25 | 26 | {% endblock %} 27 | -------------------------------------------------------------------------------- /blog/bookstore/templates/bookstore/navbar.html: -------------------------------------------------------------------------------- 1 | {% load static %} 2 | 3 | -------------------------------------------------------------------------------- /blog/bookstore/templates/bookstore/password_reset.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |

Password reset

4 |
5 |
6 | {% csrf_token %} 7 | {{form}} 8 | 9 |
10 | 11 | 12 |
13 |
-------------------------------------------------------------------------------- /blog/bookstore/templates/bookstore/password_reset_done.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |

Password Changed

4 |

password changed Successfully !

5 | 6 | Login 7 |
-------------------------------------------------------------------------------- /blog/bookstore/templates/bookstore/password_reset_form.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 | 5 | {% if validlink %} 6 | 7 |

New password

8 |
9 |
10 | {% csrf_token %} 11 | {{form }} 12 | 13 |
14 | 15 | 16 |
17 |
18 | 19 | {% else %} 20 | 21 | Expire Link 22 | 23 | {% endif %} 24 | 25 | -------------------------------------------------------------------------------- /blog/bookstore/templates/bookstore/password_reset_sent.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |

Password Sent

4 |

Check your Email inbox

5 |
-------------------------------------------------------------------------------- /blog/bookstore/templates/bookstore/profile.html: -------------------------------------------------------------------------------- 1 | {% extends 'bookstore/main.html'%} 2 | 3 | {% block content %} 4 | 5 |

Profile

6 |
7 | 8 | 9 | 10 | 11 |
12 |
13 |
14 | Name : {{request.user.username}} 15 |
16 |
17 | Total orders: {{t_orders}} 18 |
19 |
20 | Pending: {{p_orders}} 21 |
22 |
23 | Delivered : {{d_orders}} 24 |
25 |
26 | in progress : {{in_orders}} 27 |
28 |
29 | out of Orders : {{out_orders}} 30 |
31 |
32 |
33 | 34 |
35 |
36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | {% for item in orders %} 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | {% endfor %} 55 | 56 |
BookCategoryDatestatus
{{item.book}}{{item.book.category}}{{item.date_created}}{{item.status}}
57 |
58 | 59 | 60 | 61 | 62 | 63 | {% endblock %} 64 | 65 | -------------------------------------------------------------------------------- /blog/bookstore/templates/bookstore/profile_info.html: -------------------------------------------------------------------------------- 1 | {% extends 'bookstore/main.html'%} 2 | 3 | {% block content %} 4 | 5 |

Profile Info

6 |
7 | 8 |
9 |
10 | ... 11 |
12 | 13 | 14 |
15 |
16 | {% csrf_token %} 17 | {{form.as_p}} 18 |
19 | 20 | 21 |
22 | 23 | 24 |
25 |
26 |
27 | 28 | 29 | 30 | 31 | {% endblock %} 32 | 33 | -------------------------------------------------------------------------------- /blog/bookstore/templates/bookstore/register.html: -------------------------------------------------------------------------------- 1 |

Register

2 | 3 |
4 | {% csrf_token %} 5 | {% comment %} {{form.as_p}} {% endcomment %} 6 | 7 | 8 | {{form.username.label}} 9 | {{form.username}} 10 | 11 | {{form.email.label}} 12 | {{form.email}}
13 | 14 | {{form.password1.label}} 15 | {{form.password1}}
16 | 17 | {{form.password2.label}} 18 | {{form.password2}}
19 | 20 | 21 |
22 | 23 | 24 | 25 |
26 | 27 | {{form.errors}} 28 |
29 | 30 | Login page 31 |
-------------------------------------------------------------------------------- /blog/bookstore/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /blog/bookstore/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | from . import views 3 | 4 | from django.contrib.auth import views as authViews 5 | 6 | urlpatterns = [ 7 | path('' ,views.home , name="home"), 8 | path('books/' ,views.books , name="books"), 9 | # path('customer/' ,views.customer), 10 | path('customer/' ,views.customer, name="customer"), 11 | # path('create/' ,views.create, name="create"), 12 | path('create/' ,views.create, name="create"), 13 | path('update/' ,views.update, name="update"), 14 | path('delete/' ,views.delete, name="delete"), 15 | path('register/' ,views.register, name="register"), 16 | path('login/' ,views.userLogin, name="login"), 17 | path('logout/' ,views.userLogout, name="logout"), 18 | path('user/' ,views.userProfile, name="user_profile"), 19 | path('profile/' ,views.profileInfo, name="profile_info"), 20 | 21 | 22 | 23 | 24 | path('reset_password/' ,authViews.PasswordResetView.as_view(template_name= "bookstore/password_reset.html") , name="reset_password"), 25 | path('reset_password_sent/' ,authViews.PasswordResetDoneView.as_view(template_name= "bookstore/password_reset_sent.html") , name="password_reset_done"), 26 | path('reset///' ,authViews.PasswordResetConfirmView.as_view(template_name= "bookstore/password_reset_form.html") , name="password_reset_confirm"), 27 | path('reset_password_complete/' ,authViews.PasswordResetCompleteView.as_view(template_name= "bookstore/password_reset_done.html") , name="password_reset_complete"), 28 | 29 | ] -------------------------------------------------------------------------------- /blog/bookstore/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render,redirect 2 | from django.http import HttpResponse 3 | from .models import * 4 | from .forms import OrderForm,CreateNewUser,CustomerForm 5 | from .filters import OrderFilter 6 | from django.forms import inlineformset_factory 7 | from django.contrib import messages 8 | from django.contrib.auth.forms import UserCreationForm 9 | from django.contrib.auth import authenticate ,login , logout 10 | from django.contrib.auth.decorators import login_required 11 | from .decorators import notLoggedUsers , allowedUsers, forAdmins 12 | from django.contrib.auth.models import Group 13 | 14 | 15 | import requests 16 | from django.conf import settings 17 | 18 | 19 | 20 | @login_required(login_url='login') 21 | # @allowedUsers(allowedGroups=['admin']) 22 | @forAdmins 23 | def home(request): 24 | 25 | customers = Customer.objects.all() 26 | orders = Order.objects.all() 27 | t_orders = orders.count() 28 | p_orders = orders.filter(status='Pending').count() 29 | d_orders = orders.filter(status='Delivered').count() 30 | in_orders = orders.filter(status='in progress').count() 31 | out_orders = orders.filter(status='out of order').count() 32 | context = {'customers': customers , 33 | 'orders': orders, 34 | 't_orders': t_orders, 35 | 'p_orders': p_orders, 36 | 'd_orders': d_orders, 37 | 'in_orders': in_orders, 38 | 'out_orders': out_orders} 39 | 40 | return render(request , 'bookstore/dashboard.html',context) 41 | 42 | 43 | @login_required(login_url='login') 44 | @forAdmins 45 | def books(request): 46 | books = Book.objects.all() 47 | return render(request , 'bookstore/books.html',{'books': books }) 48 | 49 | @login_required(login_url='login') 50 | def customer(request,pk): 51 | customer = Customer.objects.get(id=pk) 52 | orders = customer.order_set.all() 53 | number_orders = orders.count() 54 | 55 | searchFilter = OrderFilter(request.GET , queryset=orders) 56 | orders = searchFilter.qs 57 | 58 | 59 | context = {'customer': customer ,'myFilter': searchFilter , 60 | 'orders': orders,'number_orders': number_orders } 61 | return render(request , 'bookstore/customer.html',context) 62 | 63 | 64 | 65 | # def create(request): 66 | # form = OrderForm() 67 | # if request.method == 'POST': 68 | # # print(request.POST) 69 | # form = OrderForm(request.POST) 70 | # if form.is_valid(): 71 | # form.save() 72 | # return redirect('/') 73 | # context = {'form':form} 74 | 75 | # return render(request , 'bookstore/my_order_form.html', context ) 76 | 77 | @login_required(login_url='login') 78 | @allowedUsers(allowedGroups=['admin']) 79 | def create(request,pk): 80 | OrderFormSet = inlineformset_factory(Customer,Order,fields=('book', 'status'),extra=8) 81 | customer = Customer.objects.get(id=pk) 82 | formset = OrderFormSet(queryset = Order.objects.none(), instance=customer) 83 | # form = OrderForm() 84 | if request.method == 'POST': 85 | # print(request.POST) 86 | # form = OrderForm(request.POST) 87 | formset = OrderFormSet(request.POST , instance=customer) 88 | if formset.is_valid(): 89 | formset.save() 90 | return redirect('/') 91 | #context = {'form':form} 92 | context = {'formset':formset} 93 | 94 | return render(request , 'bookstore/my_order_form.html', context ) 95 | 96 | 97 | 98 | @login_required(login_url='login') 99 | @allowedUsers(allowedGroups=['admin']) 100 | def update(request,pk): 101 | order = Order.objects.get(id=pk) 102 | form = OrderForm(instance=order) 103 | if request.method == 'POST': 104 | form = OrderForm(request.POST, instance=order) 105 | if form.is_valid(): 106 | form.save() 107 | 108 | return redirect('/') 109 | 110 | context = {'form':form} 111 | 112 | return render(request , 'bookstore/my_order_form.html', context ) 113 | 114 | @login_required(login_url='login') 115 | @allowedUsers(allowedGroups=['admin']) 116 | def delete(request,pk): 117 | order = Order.objects.get(id=pk) 118 | if request.method == 'POST': 119 | order.delete() 120 | return redirect('/') 121 | 122 | context = {'order':order} 123 | 124 | return render(request , 'bookstore/delete_form.html', context ) 125 | 126 | 127 | 128 | 129 | # def login(request): 130 | # if request.user.is_authenticated: 131 | # return redirect('home') 132 | # else: 133 | 134 | # context = {} 135 | 136 | # return render(request , 'bookstore/login.html', context ) 137 | 138 | @notLoggedUsers 139 | def register(request): 140 | form = CreateNewUser() 141 | if request.method == 'POST': 142 | form = CreateNewUser(request.POST) 143 | if form.is_valid(): 144 | 145 | recaptcha_response = request.POST.get('g-recaptcha-response') 146 | data = { 147 | 'secret' : settings.GOOGLE_RECAPTCHA_SECRET_KEY, 148 | 'response' : recaptcha_response 149 | } 150 | r = requests.post('https://www.google.com/recaptcha/api/siteverify',data=data) 151 | result = r.json() 152 | if result['success']: 153 | user = form.save() 154 | username = form.cleaned_data.get('username') 155 | messages.success(request , username + ' Created Successfully !') 156 | return redirect('login') 157 | else: 158 | messages.error(request , ' invalid Recaptcha please try again!') 159 | 160 | 161 | context = {'form':form} 162 | 163 | return render(request , 'bookstore/register.html', context ) 164 | 165 | 166 | @notLoggedUsers 167 | def userLogin(request): 168 | 169 | if request.method == 'POST': 170 | username = request.POST.get('username') 171 | password = request.POST.get('password') 172 | user = authenticate(request , username=username, password=password) 173 | if user is not None: 174 | login(request, user) 175 | return redirect('home') 176 | else: 177 | messages.info(request, 'Credentials error') 178 | 179 | context = {} 180 | 181 | return render(request , 'bookstore/login.html', context ) 182 | 183 | 184 | def userLogout(request): 185 | logout(request) 186 | return redirect('login') 187 | 188 | 189 | @login_required(login_url='login') 190 | @allowedUsers(allowedGroups=['customer']) 191 | def userProfile(request): 192 | 193 | orders = request.user.customer.order_set.all() 194 | 195 | t_orders = orders.count() 196 | p_orders = orders.filter(status='Pending').count() 197 | d_orders = orders.filter(status='Delivered').count() 198 | in_orders = orders.filter(status='in progress').count() 199 | out_orders = orders.filter(status='out of order').count() 200 | context = { 201 | 'orders': orders, 202 | 't_orders': t_orders, 203 | 'p_orders': p_orders, 204 | 'd_orders': d_orders, 205 | 'in_orders': in_orders, 206 | 'out_orders': out_orders} 207 | 208 | 209 | return render(request , 'bookstore/profile.html', context ) 210 | 211 | 212 | 213 | 214 | @login_required(login_url='login') 215 | 216 | def profileInfo(request): 217 | customer = request.user.customer 218 | form = CustomerForm(instance=customer) 219 | if request.method == 'POST': 220 | form = CustomerForm(request.POST , request.FILES, instance=customer) 221 | if form.is_valid(): 222 | form.save() 223 | 224 | 225 | 226 | 227 | 228 | 229 | context = {'form':form} 230 | 231 | 232 | return render(request , 'bookstore/profile_info.html', context ) -------------------------------------------------------------------------------- /blog/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/db.sqlite3 -------------------------------------------------------------------------------- /blog/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | """Run administrative tasks.""" 9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'blog.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /blog/static/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/static/.DS_Store -------------------------------------------------------------------------------- /blog/static/css/style.css: -------------------------------------------------------------------------------- 1 | .bg-primary { 2 | background-color: #d90a0a!important; 3 | } -------------------------------------------------------------------------------- /blog/static/images/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/static/images/.DS_Store -------------------------------------------------------------------------------- /blog/static/images/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/static/images/1.jpg -------------------------------------------------------------------------------- /blog/static/images/1_KGyfYbC.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/static/images/1_KGyfYbC.jpg -------------------------------------------------------------------------------- /blog/static/images/bP7gDPl1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/static/images/bP7gDPl1.jpg -------------------------------------------------------------------------------- /blog/static/images/bP7gDPl1_2aEMZQQ.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/static/images/bP7gDPl1_2aEMZQQ.jpg -------------------------------------------------------------------------------- /blog/static/images/book.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/static/images/book.png -------------------------------------------------------------------------------- /blog/static/images/preson.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/static/images/preson.png --------------------------------------------------------------------------------