From 65feb36f7784004074a8c07de1af763ed98c3db1 Mon Sep 17 00:00:00 2001 From: erjemin Date: Wed, 18 Feb 2026 16:00:52 +0300 Subject: [PATCH] =?UTF-8?q?mod:=20=D1=81=D0=BE=D0=B2=D1=80=D0=B5=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=BD=D1=8B=D0=B9=20=D1=81=D0=BF=D0=BE=D1=81=D0=BE?= =?UTF-8?q?=D0=B1=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F=20sit?= =?UTF-8?q?emap.xml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dicquo/dicquo/settings.py | 4 +++ dicquo/dicquo/urls.py | 8 +++++- dicquo/templates/sitemap.xml | 5 ---- .../0002_tbdictumandquotes_bischecked.py | 18 ++++++++++++ dicquo/web/models.py | 28 +++++++++++-------- dicquo/web/sitemaps.py | 20 +++++++++++++ dicquo/web/views.py | 14 ++-------- 7 files changed, 68 insertions(+), 29 deletions(-) delete mode 100644 dicquo/templates/sitemap.xml create mode 100644 dicquo/web/migrations/0002_tbdictumandquotes_bischecked.py create mode 100644 dicquo/web/sitemaps.py diff --git a/dicquo/dicquo/settings.py b/dicquo/dicquo/settings.py index d1bab03..d259d65 100644 --- a/dicquo/dicquo/settings.py +++ b/dicquo/dicquo/settings.py @@ -52,6 +52,8 @@ INSTALLED_APPS: list[str] = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'django.contrib.sites', + 'django.contrib.sitemaps', 'taggit.apps.TaggitAppConfig', 'web.apps.WebConfig', ] @@ -138,3 +140,5 @@ STATICFILES_DIRS = [ # Enable WhiteNoise's Gzip compression of static assets. if not DEBUG: STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' + +SITE_ID = 1 diff --git a/dicquo/dicquo/urls.py b/dicquo/dicquo/urls.py index 1de9082..1fb1637 100644 --- a/dicquo/dicquo/urls.py +++ b/dicquo/dicquo/urls.py @@ -17,15 +17,21 @@ Including another URLconf from django.contrib import admin from django.urls import path, re_path from django.conf.urls.static import static +from django.contrib.sitemaps.views import sitemap from dicquo import settings from web import views +from web.sitemaps import DictumSitemap + +sitemaps = { + 'dictums': DictumSitemap, +} urlpatterns = [ path('admin/', admin.site.urls), re_path(r'^$', views.index), re_path(r'^(?P\d{1,12})_\S*$', views.by_id), - re_path(r'^sitemap.xml$', views.sitemap), + path('sitemap.xml', sitemap, {'sitemaps': sitemaps}, name='django.contrib.sitemaps.views.sitemap'), ] urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/dicquo/templates/sitemap.xml b/dicquo/templates/sitemap.xml deleted file mode 100644 index 3082aac..0000000 --- a/dicquo/templates/sitemap.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - https://dq.cube2.ru/0.1{% for I in DATA %} - https://dq.cube2.ru/{{ I.ID }}_{{ I.SLUG }}1{% endfor %} - \ No newline at end of file diff --git a/dicquo/web/migrations/0002_tbdictumandquotes_bischecked.py b/dicquo/web/migrations/0002_tbdictumandquotes_bischecked.py new file mode 100644 index 0000000..b29ac95 --- /dev/null +++ b/dicquo/web/migrations/0002_tbdictumandquotes_bischecked.py @@ -0,0 +1,18 @@ +# Generated by Django 6.0.2 on 2026-02-18 12:21 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('web', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='tbdictumandquotes', + name='bIsChecked', + field=models.BooleanField(db_index=True, default=True, help_text='Цитата проверена.', verbose_name='Проверен'), + ), + ] diff --git a/dicquo/web/models.py b/dicquo/web/models.py index 1ae865e..8c3bf4b 100644 --- a/dicquo/web/models.py +++ b/dicquo/web/models.py @@ -243,22 +243,22 @@ class TbAuthor(models.Model): return self.__str__() def save(self, *args, **kwargs): - http = urllib3.PoolManager() + # http = urllib3.PoolManager() # последовательно # Используем типограф typus (https://github.com/byashimov/typus) # Используем типограф Eugene Spearance (http://www.typograf.ru/) # Используем типограф Муравьева (http://mdash.ru/api.v1.php) self.szAuthor = ru_typus(self.szAuthor) - resp = http.request("POST", - "http://www.typograf.ru/webservice/", - fields={"text": self.szAuthor.encode('cp1251')}) - self.szAuthorHTML = resp.data.decode('cp1251') - # print(self.szContentHTML) - resp = http.request("POST", - "http://mdash.ru/api.v1.php", - fields={"text": self.szAuthorHTML.encode('utf-8')}) - self.szAuthorHTML = json.loads(resp.data)["result"] - # print(self.szContentHTML) + # resp = http.request("POST", + # "http://www.typograf.ru/webservice/", + # fields={"text": self.szAuthor.encode('cp1251')}) + # self.szAuthorHTML = resp.data.decode('cp1251') + # # print(self.szContentHTML) + # resp = http.request("POST", + # "http://mdash.ru/api.v1.php", + # fields={"text": self.szAuthorHTML.encode('utf-8')}) + # self.szAuthorHTML = json.loads(resp.data)["result"] + # # print(self.szContentHTML) super(TbAuthor, self).save(*args, **kwargs) class Meta: @@ -315,6 +315,12 @@ class TbDictumAndQuotes(models.Model): verbose_name=u"Типографить", help_text=u"Применять типографику?" ) + bIsChecked = models.BooleanField( + default=True, + db_index=True, + verbose_name=u"Проверен", + help_text=u"Цитата проверена." + ) kAuthor = models.ForeignKey( TbAuthor, default=None, diff --git a/dicquo/web/sitemaps.py b/dicquo/web/sitemaps.py new file mode 100644 index 0000000..634e760 --- /dev/null +++ b/dicquo/web/sitemaps.py @@ -0,0 +1,20 @@ +from django.contrib.sitemaps import Sitemap +from web.models import TbDictumAndQuotes +import pytils + +class DictumSitemap(Sitemap): + changefreq = "weekly" # Как часто меняются страницы + priority = 0.9 # Приоритет (от 0.0 до 1.0) + + def items(self): + # Only show checked items in sitemap + return TbDictumAndQuotes.objects.filter(bIsChecked=True).order_by('-id') + + def lastmod(self, obj): + return obj.dtEdited + + def location(self, obj): + # Generates URL in format: /123_slug + slug = pytils.translit.slugify(obj.szContent.lower())[:120] + return f"/{obj.id}_{slug}" + diff --git a/dicquo/web/views.py b/dicquo/web/views.py index 02d5ce2..6ea3b2c 100644 --- a/dicquo/web/views.py +++ b/dicquo/web/views.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- __author__ = "Sergei Erjemin" -__copyright__ = "Copyright 2020, Sergei Erjemin" +__copyright__ = "Copyright 2020-2026, Sergei Erjemin" __credits__ = ["Sergei Erjemin", ] __license__ = "GPL" -__version__ = "0.0.1" +__version__ = "0.3.9" __maintainer__ = "Sergei Erjemin" __email__ = "erjemin@gmail.com" __status__ = "in progress" @@ -92,13 +92,3 @@ def index(request): response = render(request, template, to_template) return response - -def sitemap(request): - template = "sitemap.xml" # шаблон - to_template = [] - dq = TbDictumAndQuotes.objects.order_by('id').all() - for i in dq: - to_template.append({"ID": i.id, - "SLUG": pytils.translit.slugify(i.szContent.lower()[:120])}) - response = render(request, template, {"DATA": to_template}) - return response