initial
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
"""
|
||||
ASGI config for core project.
|
||||
|
||||
It exposes the ASGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
|
||||
|
||||
application = get_asgi_application()
|
||||
@@ -0,0 +1,55 @@
|
||||
from settings.models import *
|
||||
from accounts.models import UserProfile
|
||||
from menus.models import *
|
||||
from home.models import serviceSection, projectSection
|
||||
from django.conf import settings
|
||||
|
||||
# Website Setting Context
|
||||
def website_settings_context(request):
|
||||
settings = websiteSetting.objects.first()
|
||||
return {'settings': settings}
|
||||
|
||||
def seo_settings_context(request):
|
||||
seo_settings = SeoSetting.objects.first()
|
||||
return {'seo_settings': seo_settings}
|
||||
|
||||
def header_footer_context(request):
|
||||
header_footer = headerFooterSetting.objects.first()
|
||||
return {'header_footer': header_footer}
|
||||
|
||||
# Menu Context
|
||||
def menu_data(request):
|
||||
primary_menus = primaryMenu.objects.all()
|
||||
sub_menus = subMenu.objects.all()
|
||||
|
||||
return {
|
||||
'primary_menus': primary_menus,
|
||||
'sub_menus': sub_menus,
|
||||
}
|
||||
|
||||
## User Profile Context Processor
|
||||
def user_profile_context(request):
|
||||
user_profile = None
|
||||
if request.user.is_authenticated:
|
||||
user_profile = UserProfile.objects.filter(user=request.user).first()
|
||||
return {
|
||||
'user_profile': user_profile
|
||||
}
|
||||
|
||||
# Service Context Processor
|
||||
def service_context(request):
|
||||
services = serviceSection.objects.all()
|
||||
return {
|
||||
'fservices': services,
|
||||
}
|
||||
|
||||
# Project Context Processor
|
||||
def project_context(request):
|
||||
projects = projectSection.objects.all().order_by('?')
|
||||
return {
|
||||
'fprojects': projects,
|
||||
}
|
||||
|
||||
## Demo Mode Template Context Proccessor
|
||||
def demo_mode_enabled(request):
|
||||
return {'demo_mode_enabled': 'core.middleware.middleware.DemoModeMiddleware' in settings.MIDDLEWARE}
|
||||
@@ -0,0 +1,20 @@
|
||||
from django.http import Http404
|
||||
from functools import wraps
|
||||
|
||||
def admin_role_required(view_func):
|
||||
@wraps(view_func)
|
||||
def _wrapped_view(request, *args, **kwargs):
|
||||
if request.user.is_authenticated and request.user.role == 'Admin':
|
||||
return view_func(request, *args, **kwargs)
|
||||
else:
|
||||
raise Http404("Page not found")
|
||||
return _wrapped_view
|
||||
|
||||
def both_role_required(view_func):
|
||||
@wraps(view_func)
|
||||
def _wrapped_view(request, *args, **kwargs):
|
||||
if request.user.is_authenticated and request.user.role == 'Admin' or request.user.role == 'Editor':
|
||||
return view_func(request, *args, **kwargs)
|
||||
else:
|
||||
raise Http404("Page not fount")
|
||||
return _wrapped_view
|
||||
@@ -0,0 +1,55 @@
|
||||
from datetime import datetime, timedelta
|
||||
from django.http import HttpResponseForbidden
|
||||
|
||||
def cookie_consent_middleware(get_response):
|
||||
def middleware(request):
|
||||
response = get_response(request)
|
||||
|
||||
if request.method == 'POST' and 'cookie_consent' in request.POST:
|
||||
# Set the cookie to expire in 365 days (you can adjust the duration)
|
||||
expiration_date = datetime.now() + timedelta(days=365)
|
||||
response.set_cookie('cookie_consent', True, expires=expiration_date, path='/')
|
||||
|
||||
return response
|
||||
|
||||
return middleware
|
||||
|
||||
|
||||
class DemoModeMiddleware:
|
||||
def __init__(self, get_response):
|
||||
self.get_response = get_response
|
||||
|
||||
def __call__(self, request):
|
||||
if '/delete/' in request.path.lower():
|
||||
html = """
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
text-align: center;
|
||||
background-color: #f4f4f4;
|
||||
color: #333;
|
||||
padding: 50px 0;
|
||||
}
|
||||
.error-container {
|
||||
background-color: #fff;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 0 15px rgba(0,0,0,0.1);
|
||||
max-width: 500px;
|
||||
margin: auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="error-container">
|
||||
<h2>Deletions are not allowed in demo mode.</h2>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
return HttpResponseForbidden(html)
|
||||
|
||||
response = self.get_response(request)
|
||||
return response
|
||||
@@ -0,0 +1,144 @@
|
||||
from pathlib import Path
|
||||
import os
|
||||
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
def load_env():
|
||||
env_file = os.path.join(BASE_DIR, '.env')
|
||||
if os.path.exists(env_file):
|
||||
with open(env_file, 'r') as file:
|
||||
for line in file:
|
||||
line = line.strip()
|
||||
if line and not line.startswith("#"):
|
||||
key, value = line.split('=')
|
||||
os.environ[key] = value
|
||||
|
||||
load_env()
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'django-insecure-x=qe5@^3%@t1fk)pk@uyv&r!z^#9==^*-&aiqfau3@9x@+j%nm'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True if os.getenv('DEBUG') == 'True' else False
|
||||
|
||||
ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS').split(',')
|
||||
|
||||
# Application definition
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'accounts',
|
||||
'home',
|
||||
'about',
|
||||
'contact',
|
||||
'service',
|
||||
'project',
|
||||
'settings',
|
||||
'menus',
|
||||
'adminapp',
|
||||
'custompage',
|
||||
'ckeditor',
|
||||
]
|
||||
|
||||
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',
|
||||
]
|
||||
|
||||
if os.getenv('DEMO_MODE') == 'True':
|
||||
MIDDLEWARE.append('core.middleware.middleware.DemoModeMiddleware')
|
||||
|
||||
if os.getenv("WHITENOISE_CONFIG") == "True":
|
||||
MIDDLEWARE.insert(1, 'whitenoise.middleware.WhiteNoiseMiddleware')
|
||||
|
||||
|
||||
ROOT_URLCONF = 'core.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [os.path.join(BASE_DIR, os.getenv('TEMPLATES_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',
|
||||
'core.context_processors.website_settings_context',
|
||||
'core.context_processors.seo_settings_context',
|
||||
'core.context_processors.header_footer_context',
|
||||
'core.context_processors.menu_data',
|
||||
'core.context_processors.user_profile_context',
|
||||
'core.context_processors.service_context',
|
||||
'core.context_processors.project_context',
|
||||
'core.context_processors.demo_mode_enabled',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'core.wsgi.application'
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': BASE_DIR / 'db.sqlite3',
|
||||
}
|
||||
}
|
||||
# Email Setup
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
||||
EMAIL_HOST = os.getenv('EMAIL_HOST')
|
||||
EMAIL_PORT = os.getenv('EMAIL_PORT')
|
||||
EMAIL_USE_TLS = os.getenv('EMAIL_USE_TLS')
|
||||
EMAIL_HOST_USER = os.getenv('EMAIL_HOST_USER')
|
||||
EMAIL_HOST_PASSWORD = os.getenv('EMAIL_HOST_PASSWORD')
|
||||
|
||||
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',
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
TIME_ZONE = os.getenv('TIME_ZONE')
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
STATIC_URL = os.getenv('STATIC_URL')
|
||||
STATICFILES_DIRS = [os.path.join(BASE_DIR, str(os.getenv('STATICFILES_DIRS')))]
|
||||
STATIC_ROOT = os.path.join(BASE_DIR, str(os.getenv('STATIC_ROOT')))
|
||||
MEDIA_URL = str(os.getenv('MEDIA_URL'))
|
||||
MEDIA_ROOT = os.path.join(BASE_DIR, str(os.getenv('MEDIA_ROOT')))
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
|
||||
AUTH_USER_MODEL = 'accounts.User'
|
||||
if os.getenv('WHITENOISE_CONFIG') == 'True':
|
||||
STORAGES = {
|
||||
"staticfiles": {
|
||||
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
from django.http import HttpResponse
|
||||
from django.template import loader
|
||||
from home.models import *
|
||||
|
||||
def generate_sitemap(request):
|
||||
apps = [
|
||||
'home',
|
||||
'about',
|
||||
'service',
|
||||
'project',
|
||||
'contact',
|
||||
]
|
||||
|
||||
urls = []
|
||||
|
||||
for app_name in apps:
|
||||
try:
|
||||
urlconf = __import__(f'{app_name}.urls', fromlist=['urlpatterns'])
|
||||
urlpatterns = getattr(urlconf, 'urlpatterns', [])
|
||||
|
||||
# Extract URL patterns from the resolver
|
||||
for pattern in urlpatterns:
|
||||
if hasattr(pattern, 'url_patterns'):
|
||||
# If it's an included namespace, extract its URL patterns
|
||||
urls.extend([f'/{url.pattern}' for url in pattern.url_patterns])
|
||||
else:
|
||||
# Otherwise, add the URL pattern itself
|
||||
urls.append(f'/{pattern.pattern}')
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
# URLs for the Service model
|
||||
service_slugs = serviceSection.objects.values_list('slug', flat=True)
|
||||
if service_slugs:
|
||||
for slug in service_slugs:
|
||||
service_url = f'/service/details/{slug}/'
|
||||
urls.append(service_url)
|
||||
|
||||
# URLs for the Project model
|
||||
project_slugs = projectSection.objects.values_list('slug', flat=True)
|
||||
if project_slugs:
|
||||
for slug in project_slugs:
|
||||
project_url = f'/project/details/{slug}/'
|
||||
urls.append(project_url)
|
||||
|
||||
# Filter out the unwanted URLs with placeholders
|
||||
urls = [url for url in urls if '<slug:slug>' not in url and '<int:id>' not in url and '<str:slug>' not in url and '<slug:category_slug>' not in url and '/contact/' not in url and '/subscribe/' not in url]
|
||||
|
||||
|
||||
context = {
|
||||
'urls': urls,
|
||||
'request': request,
|
||||
}
|
||||
|
||||
sitemap_xml = loader.render_to_string('sitemap/sitemap.xml', context)
|
||||
sitemap_xml = sitemap_xml.replace('<priority>0.8</priority>', '<priority>1.0</priority>', 1)
|
||||
|
||||
|
||||
return HttpResponse(sitemap_xml, content_type="application/xml")
|
||||
@@ -0,0 +1,33 @@
|
||||
from django.contrib import admin
|
||||
from django.urls import path ,include
|
||||
from django.conf import settings
|
||||
from django.conf.urls.static import static
|
||||
from django.views.generic import RedirectView
|
||||
from django.urls import re_path
|
||||
from django.views.static import serve
|
||||
|
||||
urlpatterns = [
|
||||
path('oldadmin/', admin.site.urls),
|
||||
path('admin/' , RedirectView.as_view(pattern_name="adminHome"), name='adminRedirect'),
|
||||
path('dashboard/' , RedirectView.as_view(pattern_name="adminHome"), name='adminRedirect2'),
|
||||
path('', include('adminapp.urls')),
|
||||
path('', include('accounts.urls')),
|
||||
path('', include('home.urls')),
|
||||
path('', include('about.urls')),
|
||||
path('', include('contact.urls')),
|
||||
path('', include('service.urls')),
|
||||
path('', include('project.urls')),
|
||||
path('', include('custompage.urls')),
|
||||
]
|
||||
|
||||
handler404 = 'accounts.views.error_404'
|
||||
handler404 = 'adminapp.views.error_404'
|
||||
handler404 = 'home.views.error_404'
|
||||
handler404 = 'service.views.error_404'
|
||||
handler404 = 'project.views.error_404'
|
||||
handler404 = 'contact.views.error_404'
|
||||
handler404 = 'about.views.error_404'
|
||||
|
||||
handler500 = 'adminapp.views.error_500'
|
||||
|
||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
@@ -0,0 +1,16 @@
|
||||
"""
|
||||
WSGI config for core project.
|
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
|
||||
|
||||
application = get_wsgi_application()
|
||||
Reference in New Issue
Block a user