diff --git a/ModelTracker/middleware.py b/ModelTracker/middleware.py index 81d2c73..62b371e 100644 --- a/ModelTracker/middleware.py +++ b/ModelTracker/middleware.py @@ -9,4 +9,4 @@ def __call__(self, request): ModelTracker.thread.request = request response = self.get_response(request) - return response + return response \ No newline at end of file diff --git a/ModelTracker/migrations/0004_auto_20230105_1841.py b/ModelTracker/migrations/0004_auto_20230105_1841.py new file mode 100644 index 0000000..35f962f --- /dev/null +++ b/ModelTracker/migrations/0004_auto_20230105_1841.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2 on 2023-01-05 18:41 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ModelTracker', '0003_history_related_objects'), + ] + + operations = [ + migrations.AlterField( + model_name='history', + name='new_state', + field=models.JSONField(default=dict), + ), + migrations.AlterField( + model_name='history', + name='old_state', + field=models.JSONField(default=dict), + ), + ] diff --git a/TestApp/urls.py b/TestApp/urls.py new file mode 100644 index 0000000..8a1a1b5 --- /dev/null +++ b/TestApp/urls.py @@ -0,0 +1,9 @@ +try: + from django.urls import re_path +except ModuleNotFoundError: + from django.conf.urls import re_path +from . import views + +urlpatterns = [ + re_path('^$',views.test,name="test"), +] \ No newline at end of file diff --git a/TestApp/views.py b/TestApp/views.py index 91ea44a..455b6c8 100644 --- a/TestApp/views.py +++ b/TestApp/views.py @@ -1,3 +1,13 @@ from django.shortcuts import render +from django.contrib.auth.decorators import login_required +from TestApp.models import employee +from django.http import HttpResponse -# Create your views here. +@login_required +def test(request): + e=employee() + e.name="Ahmed2" + e.address="Giza" + e.age=29 + e.save() + return HttpResponse("Shall be saved by " + request.user.username) diff --git a/TestApp3/TestApp3/__init__.py b/TestApp3/TestApp3/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/TestApp3/TestApp3/asgi.py b/TestApp3/TestApp3/asgi.py new file mode 100644 index 0000000..bb01030 --- /dev/null +++ b/TestApp3/TestApp3/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for TestApp3 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.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'TestApp3.settings') + +application = get_asgi_application() diff --git a/TestApp3/TestApp3/migrations/0001_initial.py b/TestApp3/TestApp3/migrations/0001_initial.py new file mode 100644 index 0000000..77996c0 --- /dev/null +++ b/TestApp3/TestApp3/migrations/0001_initial.py @@ -0,0 +1,26 @@ +# Generated by Django 3.2 on 2023-01-05 18:41 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='employee', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255)), + ('address', models.CharField(max_length=255)), + ('age', models.IntegerField()), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/TestApp3/TestApp3/migrations/__init__.py b/TestApp3/TestApp3/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/TestApp3/TestApp3/models.py b/TestApp3/TestApp3/models.py new file mode 100644 index 0000000..69e9cc9 --- /dev/null +++ b/TestApp3/TestApp3/models.py @@ -0,0 +1,9 @@ +from django.db import models + +from ModelTracker import Tracker + +class employee(Tracker.ModelTracker): + name=models.CharField(max_length=255) + address=models.CharField(max_length=255) + age=models.IntegerField() + diff --git a/TestApp3/TestApp3/settings.py b/TestApp3/TestApp3/settings.py new file mode 100644 index 0000000..bdfcbbf --- /dev/null +++ b/TestApp3/TestApp3/settings.py @@ -0,0 +1,128 @@ +""" +Django settings for TestApp3 project. + +Generated by 'django-admin startproject' using Django 3.2. + +For more information on this file, see +https://docs.djangoproject.com/en/3.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/3.2/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/3.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-8y69cus367#@pr+mfw9l1!q27f(7x%%o+n%@4_eda3g)(76vr)' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'TestApp3', + 'ModelTracker' +] + +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', + 'ModelTracker.middleware.ModelTrackerMiddleware' +] + +ROOT_URLCONF = 'TestApp3.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 = 'TestApp3.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/3.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/3.2/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.2/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/3.2/howto/static-files/ + +STATIC_URL = '/static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/TestApp3/TestApp3/urls.py b/TestApp3/TestApp3/urls.py new file mode 100644 index 0000000..f2ba176 --- /dev/null +++ b/TestApp3/TestApp3/urls.py @@ -0,0 +1,22 @@ +"""TestApp3 URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/3.2/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 . import views +urlpatterns = [ + path('admin/', admin.site.urls), + path('test/', views.test, name="test"), +] diff --git a/TestApp3/TestApp3/views.py b/TestApp3/TestApp3/views.py new file mode 100644 index 0000000..830a0bd --- /dev/null +++ b/TestApp3/TestApp3/views.py @@ -0,0 +1,13 @@ +from django.shortcuts import render +from django.contrib.auth.decorators import login_required +from .models import employee +from django.http import HttpResponse + +@login_required +def test(request): + e=employee() + e.name="Ahmed2" + e.address="Giza" + e.age=29 + e.save() + return HttpResponse("Shall be saved by " + request.user.username) diff --git a/TestApp3/TestApp3/wsgi.py b/TestApp3/TestApp3/wsgi.py new file mode 100644 index 0000000..847a412 --- /dev/null +++ b/TestApp3/TestApp3/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for TestApp3 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.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'TestApp3.settings') + +application = get_wsgi_application() diff --git a/setup.py b/setup.py index d1f29c3..adfdeaf 100644 --- a/setup.py +++ b/setup.py @@ -33,8 +33,8 @@ 'simplejson' ], include_package_data=True, - zip_safe=False, # because we're including static files - python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", + zip_safe=False, # because we're including static files + python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", classifiers=[ "Development Status :: 5 - Production/Stable", #"Development Status :: 4 - Beta",