Merge branch 'feature/transfer-page-counters' into 'develop'
Add rating.views_count transfer See merge request gm/gm-backend!134
This commit is contained in:
commit
c644cbfd64
20
apps/news/migrations/0035_news_views_count.py
Normal file
20
apps/news/migrations/0035_news_views_count.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# Generated by Django 2.2.4 on 2019-11-14 20:43
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('rating', '0004_auto_20191114_2041'),
|
||||
('news', '0034_merge_20191030_1714'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='news',
|
||||
name='views_count',
|
||||
field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='rating.ViewCount'),
|
||||
),
|
||||
]
|
||||
|
|
@ -6,7 +6,7 @@ from django.utils import timezone
|
|||
from django.utils.translation import gettext_lazy as _
|
||||
from rest_framework.reverse import reverse
|
||||
|
||||
from rating.models import Rating
|
||||
from rating.models import Rating, ViewCount
|
||||
from utils.models import BaseAttributes, TJSONField, TranslatedFieldsMixin, ProjectBaseMixin
|
||||
from utils.querysets import TranslationQuerysetMixin
|
||||
|
||||
|
|
@ -37,7 +37,8 @@ class NewsQuerySet(TranslationQuerysetMixin):
|
|||
return self.order_by('-start')
|
||||
|
||||
def rating_value(self):
|
||||
return self.annotate(rating=models.Count('ratings__ip', distinct=True))
|
||||
# return self.annotate(rating=models.Count('ratings__ip', distinct=True))
|
||||
return self.annotate(rating='views_count__count') # TODO: совместить новый и старый функционал
|
||||
|
||||
def with_base_related(self):
|
||||
"""Return qs with related objects."""
|
||||
|
|
@ -182,6 +183,7 @@ class News(BaseAttributes, TranslatedFieldsMixin):
|
|||
tags = models.ManyToManyField('tag.Tag', related_name='news',
|
||||
verbose_name=_('Tags'))
|
||||
gallery = models.ManyToManyField('gallery.Image', through='news.NewsGallery')
|
||||
views_count = models.OneToOneField('rating.ViewCount', blank=True, null=True, on_delete=models.SET_NULL)
|
||||
ratings = generic.GenericRelation(Rating)
|
||||
favorites = generic.GenericRelation(to='favorites.Favorites')
|
||||
agenda = models.ForeignKey('news.Agenda', blank=True, null=True,
|
||||
|
|
|
|||
27
apps/rating/migrations/0003_viewcount.py
Normal file
27
apps/rating/migrations/0003_viewcount.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
# Generated by Django 2.2.4 on 2019-11-14 17:15
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('contenttypes', '0002_remove_content_type_name'),
|
||||
('rating', '0002_auto_20191004_0928'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='ViewCount',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('object_id', models.PositiveIntegerField()),
|
||||
('count', models.IntegerField()),
|
||||
('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')),
|
||||
],
|
||||
options={
|
||||
'unique_together': {('object_id', 'content_type')},
|
||||
},
|
||||
),
|
||||
]
|
||||
25
apps/rating/migrations/0004_auto_20191114_2041.py
Normal file
25
apps/rating/migrations/0004_auto_20191114_2041.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# Generated by Django 2.2.4 on 2019-11-14 20:41
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('rating', '0003_viewcount'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterUniqueTogether(
|
||||
name='viewcount',
|
||||
unique_together=set(),
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='viewcount',
|
||||
name='content_type',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='viewcount',
|
||||
name='object_id',
|
||||
),
|
||||
]
|
||||
|
|
@ -20,3 +20,7 @@ class Rating(models.Model):
|
|||
return self.content_object.name
|
||||
if hasattr(self.content_object, 'title'):
|
||||
return self.content_object.title_translated
|
||||
|
||||
|
||||
class ViewCount(models.Model):
|
||||
count = models.IntegerField()
|
||||
|
|
|
|||
29
apps/rating/transfer_data.py
Normal file
29
apps/rating/transfer_data.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
from transfer.models import PageTexts, PageCounters
|
||||
from news.models import News
|
||||
from rating.models import ViewCount
|
||||
|
||||
|
||||
def transfer_news_view_count():
|
||||
news_list = News.objects.filter(old_id__isnull=False)
|
||||
for news_object in news_list:
|
||||
try:
|
||||
mysql_page_text = PageTexts.objects.get(id=news_object.old_id)
|
||||
except PageTexts.DoesNotExist:
|
||||
continue
|
||||
|
||||
try:
|
||||
mysql_views_count = PageCounters.objects.get(page_id=mysql_page_text.page_id)
|
||||
except PageCounters.DoesNotExist:
|
||||
continue
|
||||
|
||||
view_count = ViewCount.objects.create(
|
||||
count=mysql_views_count.count
|
||||
)
|
||||
|
||||
news_object.views_count = view_count
|
||||
news_object.save()
|
||||
|
||||
|
||||
data_types = {
|
||||
"rating_count": [transfer_news_view_count]
|
||||
}
|
||||
|
|
@ -36,6 +36,7 @@ class Command(BaseCommand):
|
|||
'souvenir',
|
||||
'establishment_note',
|
||||
'assemblage',
|
||||
'rating_count'
|
||||
]
|
||||
|
||||
def handle(self, *args, **options):
|
||||
|
|
|
|||
|
|
@ -36,14 +36,15 @@ THUMBNAIL_DEBUG = True
|
|||
|
||||
|
||||
# ADDED TRANSFER APP
|
||||
# INSTALLED_APPS.append('transfer.apps.TransferConfig')
|
||||
INSTALLED_APPS.append('transfer.apps.TransferConfig')
|
||||
|
||||
|
||||
# DATABASES
|
||||
DATABASES.update({
|
||||
'legacy': {
|
||||
'ENGINE': 'django.db.backends.mysql',
|
||||
'HOST': 'mysql_db',
|
||||
'HOST': '172.22.0.1',
|
||||
# 'HOST': 'mysql_db',
|
||||
'PORT': 3306,
|
||||
'NAME': 'dev',
|
||||
'USER': 'dev',
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user