mirror of
https://github.com/mediacms-io/mediacms.git
synced 2025-11-19 13:26:03 -05:00
MediaCMS backend, initial commit
This commit is contained in:
0
actions/__init__.py
Normal file
0
actions/__init__.py
Normal file
0
actions/admin.py
Normal file
0
actions/admin.py
Normal file
5
actions/apps.py
Normal file
5
actions/apps.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ActionsConfig(AppConfig):
|
||||
name = "actions"
|
||||
54
actions/migrations/0001_initial.py
Normal file
54
actions/migrations/0001_initial.py
Normal file
@@ -0,0 +1,54 @@
|
||||
# Generated by Django 3.1.4 on 2020-12-01 07:12
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = []
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="MediaAction",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.AutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
(
|
||||
"session_key",
|
||||
models.CharField(
|
||||
blank=True,
|
||||
db_index=True,
|
||||
help_text="for not logged in users",
|
||||
max_length=33,
|
||||
null=True,
|
||||
),
|
||||
),
|
||||
(
|
||||
"action",
|
||||
models.CharField(
|
||||
choices=[
|
||||
("like", "Like"),
|
||||
("dislike", "Dislike"),
|
||||
("watch", "Watch"),
|
||||
("report", "Report"),
|
||||
("rate", "Rate"),
|
||||
],
|
||||
default="watch",
|
||||
max_length=20,
|
||||
),
|
||||
),
|
||||
("extra_info", models.TextField(blank=True, null=True)),
|
||||
("action_date", models.DateTimeField(auto_now_add=True)),
|
||||
("remote_ip", models.CharField(blank=True, max_length=40, null=True)),
|
||||
],
|
||||
),
|
||||
]
|
||||
26
actions/migrations/0002_mediaaction_media.py
Normal file
26
actions/migrations/0002_mediaaction_media.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# Generated by Django 3.1.4 on 2020-12-01 07:12
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
("actions", "0001_initial"),
|
||||
("files", "0001_initial"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="mediaaction",
|
||||
name="media",
|
||||
field=models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name="mediaactions",
|
||||
to="files.media",
|
||||
),
|
||||
),
|
||||
]
|
||||
42
actions/migrations/0003_auto_20201201_0712.py
Normal file
42
actions/migrations/0003_auto_20201201_0712.py
Normal file
@@ -0,0 +1,42 @@
|
||||
# Generated by Django 3.1.4 on 2020-12-01 07:12
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
("actions", "0002_mediaaction_media"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="mediaaction",
|
||||
name="user",
|
||||
field=models.ForeignKey(
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name="useractions",
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name="mediaaction",
|
||||
index=models.Index(
|
||||
fields=["user", "action", "-action_date"],
|
||||
name="actions_med_user_id_940054_idx",
|
||||
),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name="mediaaction",
|
||||
index=models.Index(
|
||||
fields=["session_key", "action"], name="actions_med_session_fac55a_idx"
|
||||
),
|
||||
),
|
||||
]
|
||||
0
actions/migrations/__init__.py
Normal file
0
actions/migrations/__init__.py
Normal file
55
actions/models.py
Normal file
55
actions/models.py
Normal file
@@ -0,0 +1,55 @@
|
||||
from django.db import models
|
||||
from users.models import User
|
||||
from files.models import Media
|
||||
|
||||
USER_MEDIA_ACTIONS = (
|
||||
("like", "Like"),
|
||||
("dislike", "Dislike"),
|
||||
("watch", "Watch"),
|
||||
("report", "Report"),
|
||||
("rate", "Rate"),
|
||||
)
|
||||
|
||||
|
||||
class MediaAction(models.Model):
|
||||
"""Stores different user actions"""
|
||||
|
||||
user = models.ForeignKey(
|
||||
User,
|
||||
on_delete=models.CASCADE,
|
||||
db_index=True,
|
||||
blank=True,
|
||||
null=True,
|
||||
related_name="useractions",
|
||||
)
|
||||
session_key = models.CharField(
|
||||
max_length=33,
|
||||
db_index=True,
|
||||
blank=True,
|
||||
null=True,
|
||||
help_text="for not logged in users",
|
||||
)
|
||||
|
||||
action = models.CharField(
|
||||
max_length=20, choices=USER_MEDIA_ACTIONS, default="watch"
|
||||
)
|
||||
# keeps extra info, eg on report action, why it is reported
|
||||
extra_info = models.TextField(blank=True, null=True)
|
||||
|
||||
media = models.ForeignKey(
|
||||
Media, on_delete=models.CASCADE, related_name="mediaactions"
|
||||
)
|
||||
action_date = models.DateTimeField(auto_now_add=True)
|
||||
remote_ip = models.CharField(max_length=40, blank=True, null=True)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
super(MediaAction, self).save(*args, **kwargs)
|
||||
|
||||
def __str__(self):
|
||||
return self.action
|
||||
|
||||
class Meta:
|
||||
indexes = [
|
||||
models.Index(fields=["user", "action", "-action_date"]),
|
||||
models.Index(fields=["session_key", "action"]),
|
||||
]
|
||||
0
actions/tests.py
Normal file
0
actions/tests.py
Normal file
0
actions/views.py
Normal file
0
actions/views.py
Normal file
Reference in New Issue
Block a user