db parse module
This commit is contained in:
BIN
mysql-apt-config_0.8.24-1_all.deb
Normal file
BIN
mysql-apt-config_0.8.24-1_all.deb
Normal file
Binary file not shown.
@@ -83,10 +83,16 @@ DATABASES = {
|
|||||||
'default': {
|
'default': {
|
||||||
'ENGINE': 'django.db.backends.sqlite3',
|
'ENGINE': 'django.db.backends.sqlite3',
|
||||||
'NAME': BASE_DIR / 'db.sqlite3',
|
'NAME': BASE_DIR / 'db.sqlite3',
|
||||||
}
|
},
|
||||||
|
'wordpress': {
|
||||||
|
'ENGINE': 'django.db.backends.mysql',
|
||||||
|
'NAME': 'u1510415_wp832',
|
||||||
|
'USER': 'root',
|
||||||
|
'PASSWORD': 'R0sebud',
|
||||||
|
'HOST': '0.0.0.0',
|
||||||
|
'PORT': '3306',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Password validation
|
# Password validation
|
||||||
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators
|
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators
|
||||||
|
|
||||||
|
|||||||
29
users/management/commands/sync_activity_log.py
Normal file
29
users/management/commands/sync_activity_log.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
from users.models import WordPressUserActivityLog
|
||||||
|
from users.models import LocalUserActivityLog
|
||||||
|
from asgiref.sync import sync_to_async
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = "Синхронизация данных из WordPress в локальную базу данных"
|
||||||
|
|
||||||
|
def handle(self, *args, **kwargs):
|
||||||
|
self.stdout.write("Начало синхронизации данных...")
|
||||||
|
try:
|
||||||
|
# Получаем данные из WordPress
|
||||||
|
wordpress_logs = WordPressUserActivityLog.objects.using('wordpress').all()
|
||||||
|
|
||||||
|
for log in wordpress_logs:
|
||||||
|
# Сохраняем данные в локальную базу
|
||||||
|
LocalUserActivityLog.objects.update_or_create(
|
||||||
|
id=log.id, # Используем уникальный идентификатор
|
||||||
|
defaults={
|
||||||
|
'user_id': log.user_id,
|
||||||
|
'activity_type': log.activity_type,
|
||||||
|
'timestamp': log.timestamp,
|
||||||
|
'additional_data': log.additional_data,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
self.stdout.write(self.style.SUCCESS("Синхронизация завершена успешно!"))
|
||||||
|
except Exception as e:
|
||||||
|
self.stderr.write(self.style.ERROR(f"Ошибка синхронизации: {str(e)}"))
|
||||||
@@ -49,3 +49,25 @@ class UserConfirmation(models.Model):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"Confirmation for {self.user.username} - {self.confirmation_code}"
|
return f"Confirmation for {self.user.username} - {self.confirmation_code}"
|
||||||
|
|
||||||
|
class WordPressUserActivityLog(models.Model):
|
||||||
|
id = models.AutoField(primary_key=True)
|
||||||
|
user_id = models.IntegerField()
|
||||||
|
activity_type = models.CharField(max_length=255)
|
||||||
|
timestamp = models.DateTimeField()
|
||||||
|
additional_data = models.JSONField(null=True, blank=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
db_table = 'wpts_user_activity_log' # Название таблицы в базе данных WordPress
|
||||||
|
managed = False # Django не будет управлять этой таблицей
|
||||||
|
app_label = 'Users' # Замените на имя вашего приложения
|
||||||
|
|
||||||
|
class LocalUserActivityLog(models.Model):
|
||||||
|
id = models.AutoField(primary_key=True)
|
||||||
|
user_id = models.IntegerField()
|
||||||
|
activity_type = models.CharField(max_length=255)
|
||||||
|
timestamp = models.DateTimeField()
|
||||||
|
additional_data = models.JSONField(null=True, blank=True)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"User {self.user_id} - {self.activity_type}"
|
||||||
Reference in New Issue
Block a user