1.4.0 sitemap

This commit is contained in:
SDE
2024-06-29 16:34:36 +03:00
parent 0e184f0b87
commit 0be38ac466
8 changed files with 193 additions and 10 deletions

View File

@@ -13,15 +13,15 @@ def get_options_by_opt_types(opt_types, only_vals=False):
res = {} res = {}
opts = opts.values('opt_type', 'value', 'prefix') opts = opts.values('opt_type', 'value', 'prefix')
for item in opts: for item in opts:
if item['opt_type'] == 'domain': # if item['opt_type'] == 'domain':
#
try: # try:
from django.contrib.sites.models import Site # from django.contrib.sites.models import Site
current_site = Site.objects.get_current() # current_site = Site.objects.get_current()
res.update({item['opt_type']: current_site.domain}) # res.update({item['opt_type']: current_site.domain})
continue # # continue
except Exception as e: # except Exception as e:
print(str(e)) # print(str(e))
if item['prefix']: if item['prefix']:
res.update({item['opt_type']: f"{item['prefix']}{item['value']}"}) res.update({item['opt_type']: f"{item['prefix']}{item['value']}"})

0
SitemapApp/__init__.py Normal file
View File

3
SitemapApp/models.py Normal file
View File

@@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

16
SitemapApp/tests.py Normal file
View File

@@ -0,0 +1,16 @@
"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".
Replace this with more appropriate tests for your application.
"""
from django.test import TestCase
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)

11
SitemapApp/urls.py Normal file
View File

@@ -0,0 +1,11 @@
from django.urls import include, path
from django.contrib.sitemaps import views as sitemaps_views
from django.views.decorators.cache import cache_page
from django.contrib.sitemaps.views import sitemap
from SitemapApp.views import sitemaps
urlpatterns = [
path('sitemap.xml', sitemap, {'sitemaps': sitemaps},
name='django.contrib.sitemaps.views.sitemap')
]

149
SitemapApp/views.py Normal file
View File

@@ -0,0 +1,149 @@
# coding=utf-8
from django.contrib.sitemaps import Sitemap
from django.urls import reverse
from BaseModels.mailSender import techSendMail
import json
from datetime import datetime, time, timezone
# from PageSetsApp.models import *
# from ArticlesApp.models import *
# from BaseModels.base_api_requests import base_api_request
# from tEsiteProj.settings import API_URL
from django.db.models import Q
limit_records = 1000
sitemaps = {
}
protocol = 'https'
class sm_StaticPage(Sitemap):
changefreq = 'monthly'
priority = 1
i18n = True
protocol = protocol
def items(self):
from GeneralApp.models import StaticPage
return StaticPage.objects.filter(enable=True)
def location(self, item):
if item.url == 'main':
return reverse('main')
else:
return reverse('static_page', args=[item.url])
def lastmod(self, obj):
return obj.modifiedDT
sitemaps.update({'static_pages': sm_StaticPage})
class sm_ArticlesPage(Sitemap):
changefreq = 'daily'
priority = 2
i18n = True
protocol = protocol
def items(self):
return ['']
def location(self, item):
return reverse('articles')
def lastmod(self, obj):
from ArticlesApp.models import ArticleModel
article = ArticleModel.objects.filter(enable=True).order_by('-modifiedDT').first()
if article:
return article.modifiedDT
else:
return datetime.now()
sitemaps.update({'articles_page': sm_ArticlesPage})
class sm_Article(Sitemap):
changefreq = 'yearly'
priority = 2
i18n = True
protocol = protocol
def items(self):
from ArticlesApp.views import ArticleModel
objs = ArticleModel.objects.filter(enable=True)
return objs
def location(self, item):
return reverse('article_one', args=[item.url])
def lastmod(self, obj):
return obj.modifiedDT
sitemaps.update({'article': sm_Article})
class sm_UserPage(Sitemap):
changefreq = 'yearly'
priority = 2
i18n = True
protocol = protocol
def items(self):
from ArticlesApp.views import UserPageModel
objs = UserPageModel.objects.filter(enable=True)
return objs
def location(self, item):
return reverse('user_page', args=[item.url])
def lastmod(self, obj):
return obj.modifiedDT
sitemaps.update({'user_page': sm_UserPage})
class sm_Registration(Sitemap):
changefreq = 'never'
priority = 1
i18n = True
protocol = protocol
def items(self):
return ['']
def location(self, item):
return reverse('registration_page')
def lastmod(self, obj):
return datetime(2024, 6, 1)
sitemaps.update({'registration': sm_Registration})
class sm_Login(Sitemap):
changefreq = 'never'
priority = 1
i18n = True
protocol = protocol
def items(self):
return ['']
def location(self, item):
return reverse('login_profile')
def lastmod(self, obj):
return datetime(2024, 6, 1)
sitemaps.update({'login': sm_Login})

View File

@@ -95,6 +95,8 @@ INSTALLED_APPS = [
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'django.contrib.humanize', 'django.contrib.humanize',
'django.contrib.sitemaps',
'django.contrib.sites', 'django.contrib.sites',
'colorfield', 'colorfield',

View File

@@ -40,7 +40,9 @@ urlpatterns = [
path('test_404', Page404, name='page_404'), path('test_404', Page404, name='page_404'),
path('', include('PushMessages.urls')) path('', include('PushMessages.urls')),
path('', include('SitemapApp.urls')),
] ]
from django.conf.urls.i18n import i18n_patterns from django.conf.urls.i18n import i18n_patterns