first commit
This commit is contained in:
0
socials/__init__.py
Normal file
0
socials/__init__.py
Normal file
21
socials/admin.py
Normal file
21
socials/admin.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from django.contrib import admin
|
||||
from .models import *
|
||||
|
||||
|
||||
# class OrganizationAdmin(admin.ModelAdmin):
|
||||
# # prepopulated_fields = {"slug": ("shortname",)}
|
||||
# list_display = ( "name", "city",)
|
||||
# # list_filter = ("promo_type",)
|
||||
|
||||
class PostAdmin(admin.ModelAdmin):
|
||||
# prepopulated_fields = {"slug": ("shortname",)}
|
||||
list_display = ( "handle", "platform")
|
||||
list_filter = ("platform",)
|
||||
|
||||
|
||||
|
||||
|
||||
# Register your models here.
|
||||
admin.site.register(Faq)
|
||||
admin.site.register(SocialLink, PostAdmin)
|
||||
# admin.site.register(SocialPost, PostAdmin)
|
||||
6
socials/apps.py
Normal file
6
socials/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class SocialsConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'socials'
|
||||
65
socials/migrations/0001_initial.py
Normal file
65
socials/migrations/0001_initial.py
Normal file
@@ -0,0 +1,65 @@
|
||||
# Generated by Django 5.1.1 on 2024-12-04 05:42
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Faq',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('question', models.CharField(max_length=516)),
|
||||
('post', models.TextField()),
|
||||
('seq_num', models.SmallIntegerField()),
|
||||
('published', models.BooleanField(default=False)),
|
||||
],
|
||||
options={
|
||||
'verbose_name_plural': 'FAQs',
|
||||
'ordering': ['seq_num'],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='SocialPost',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('title', models.CharField(max_length=64)),
|
||||
('post', models.TextField()),
|
||||
('created_at', models.DateField(auto_now=True)),
|
||||
('author', models.CharField(blank=True, max_length=64, null=True)),
|
||||
('published', models.BooleanField(default=False)),
|
||||
],
|
||||
options={
|
||||
'verbose_name_plural': 'Social Posts',
|
||||
'ordering': ['created_at', 'title'],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='SocialLink',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('cid', models.CharField(blank=True, max_length=255, null=True)),
|
||||
('uri', models.URLField()),
|
||||
('text', models.CharField(blank=True, max_length=515, null=True)),
|
||||
('text_link', models.URLField(blank=True, null=True)),
|
||||
('handle', models.CharField(blank=True, max_length=63, null=True)),
|
||||
('likes', models.IntegerField()),
|
||||
('reposts', models.IntegerField()),
|
||||
('quotes', models.IntegerField()),
|
||||
('replies', models.IntegerField()),
|
||||
('more_details', models.JSONField(blank=True, null=True)),
|
||||
('created_at', models.DateTimeField(auto_now=True)),
|
||||
],
|
||||
options={
|
||||
'verbose_name_plural': 'Events',
|
||||
'ordering': ['created_at'],
|
||||
'unique_together': {('uri',)},
|
||||
},
|
||||
),
|
||||
]
|
||||
31
socials/migrations/0002_alter_sociallink_options_and_more.py
Normal file
31
socials/migrations/0002_alter_sociallink_options_and_more.py
Normal file
@@ -0,0 +1,31 @@
|
||||
# Generated by Django 5.1.1 on 2024-12-04 07:34
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('socials', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='sociallink',
|
||||
options={'ordering': ['-created_at'], 'verbose_name_plural': 'Social Links'},
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name='sociallink',
|
||||
old_name='text_link',
|
||||
new_name='link',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='sociallink',
|
||||
name='more_details',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='sociallink',
|
||||
name='created_at',
|
||||
field=models.DateTimeField(),
|
||||
),
|
||||
]
|
||||
19
socials/migrations/0003_socialpost_uri.py
Normal file
19
socials/migrations/0003_socialpost_uri.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# Generated by Django 5.1.1 on 2025-10-03 01:42
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('socials', '0002_alter_sociallink_options_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='socialpost',
|
||||
name='uri',
|
||||
field=models.URLField(default='test'),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,38 @@
|
||||
# Generated by Django 5.1.1 on 2025-10-03 05:44
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('socials', '0003_socialpost_uri'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='sociallink',
|
||||
options={'ordering': ['-likes'], 'verbose_name_plural': 'Social Links'},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='sociallink',
|
||||
name='rt_handle',
|
||||
field=models.CharField(blank=True, max_length=63, null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='sociallink',
|
||||
name='rt_link',
|
||||
field=models.URLField(blank=True, null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='sociallink',
|
||||
name='rt_text',
|
||||
field=models.CharField(blank=True, max_length=515, null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='sociallink',
|
||||
name='rt_uri',
|
||||
field=models.URLField(default='blank'),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,23 @@
|
||||
# Generated by Django 5.1.1 on 2025-10-03 05:50
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('socials', '0004_alter_sociallink_options_sociallink_rt_handle_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='sociallink',
|
||||
name='rt_link',
|
||||
field=models.CharField(blank=True, max_length=64, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='sociallink',
|
||||
name='uri',
|
||||
field=models.CharField(blank=True, max_length=64, null=True),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,32 @@
|
||||
# Generated by Django 5.1.1 on 2025-10-03 05:59
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('socials', '0005_alter_sociallink_rt_link_alter_sociallink_uri'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='sociallink',
|
||||
name='cid',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='sociallink',
|
||||
name='rt_link',
|
||||
field=models.URLField(blank=True, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='sociallink',
|
||||
name='rt_uri',
|
||||
field=models.CharField(blank=True, max_length=63, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='sociallink',
|
||||
name='uri',
|
||||
field=models.CharField(blank=True, max_length=63, null=True),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,23 @@
|
||||
# Generated by Django 5.1.1 on 2025-10-04 00:19
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('socials', '0006_remove_sociallink_cid_alter_sociallink_rt_link_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='sociallink',
|
||||
options={'ordering': ['-created_at'], 'verbose_name_plural': 'Social Links'},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='sociallink',
|
||||
name='platform',
|
||||
field=models.CharField(default='bluesky', max_length=16),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,33 @@
|
||||
# Generated by Django 5.1.1 on 2025-10-04 00:28
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('socials', '0007_alter_sociallink_options_sociallink_platform'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='sociallink',
|
||||
name='likes',
|
||||
field=models.IntegerField(blank=True, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='sociallink',
|
||||
name='quotes',
|
||||
field=models.IntegerField(blank=True, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='sociallink',
|
||||
name='replies',
|
||||
field=models.IntegerField(blank=True, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='sociallink',
|
||||
name='reposts',
|
||||
field=models.IntegerField(blank=True, null=True),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,23 @@
|
||||
# Generated by Django 5.1.1 on 2025-10-04 20:07
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('socials', '0008_alter_sociallink_likes_alter_sociallink_quotes_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='sociallink',
|
||||
name='pub_link',
|
||||
field=models.URLField(blank=True, null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='sociallink',
|
||||
name='published',
|
||||
field=models.BooleanField(default=0),
|
||||
),
|
||||
]
|
||||
30
socials/migrations/0010_socialimg.py
Normal file
30
socials/migrations/0010_socialimg.py
Normal file
@@ -0,0 +1,30 @@
|
||||
# Generated by Django 5.1.1 on 2025-10-05 07:56
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('socials', '0009_sociallink_pub_link_sociallink_published'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='SocialImg',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('uri', models.CharField(blank=True, max_length=63, null=True)),
|
||||
('text', models.CharField(blank=True, max_length=515, null=True)),
|
||||
('img_link', models.URLField(blank=True, null=True)),
|
||||
('handle', models.CharField(blank=True, max_length=63, null=True)),
|
||||
('created_at', models.DateTimeField()),
|
||||
('platform', models.CharField(max_length=16)),
|
||||
],
|
||||
options={
|
||||
'verbose_name_plural': 'Social Images',
|
||||
'ordering': ['-created_at'],
|
||||
'unique_together': {('uri',)},
|
||||
},
|
||||
),
|
||||
]
|
||||
0
socials/migrations/__init__.py
Normal file
0
socials/migrations/__init__.py
Normal file
97
socials/models.py
Normal file
97
socials/models.py
Normal file
@@ -0,0 +1,97 @@
|
||||
from django.db import models
|
||||
from django.core.files.storage import FileSystemStorage
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
# Create your models here.
|
||||
|
||||
|
||||
class Faq(models.Model):
|
||||
question = models.CharField(max_length=516)
|
||||
post = models.TextField()
|
||||
seq_num = models.SmallIntegerField()
|
||||
published = models.BooleanField(default=False)
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = "FAQs"
|
||||
ordering = ['seq_num',]
|
||||
|
||||
def __unicode__(self):
|
||||
return "%s" % self.question
|
||||
|
||||
def __str__(self):
|
||||
return u'%s' % self.question
|
||||
|
||||
|
||||
class SocialPost(models.Model):
|
||||
title = models.CharField(max_length=64)
|
||||
post = models.TextField()
|
||||
uri = models.URLField()
|
||||
created_at = models.DateField(auto_now=True)
|
||||
author = models.CharField(max_length=64, blank=True, null=True)
|
||||
published = models.BooleanField(default=False)
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = "Social Posts"
|
||||
ordering = ['created_at', 'title']
|
||||
|
||||
def __unicode__(self):
|
||||
return "%s" % self.title
|
||||
|
||||
def __str__(self):
|
||||
return u'%s' % self.title
|
||||
|
||||
|
||||
class SocialLink(models.Model):
|
||||
uri = models.CharField(max_length=63, blank=True, null=True)
|
||||
text = models.CharField(max_length=515, blank=True, null=True)
|
||||
link = models.URLField(blank=True, null=True)
|
||||
handle = models.CharField(max_length=63, blank=True, null=True)
|
||||
likes = models.IntegerField(blank=True, null=True)
|
||||
reposts = models.IntegerField(blank=True, null=True)
|
||||
quotes = models.IntegerField(blank=True, null=True)
|
||||
replies = models.IntegerField(blank=True, null=True)
|
||||
created_at = models.DateTimeField()
|
||||
platform = models.CharField(max_length=16)
|
||||
|
||||
rt_uri = models.CharField(max_length=63, blank=True, null=True)
|
||||
rt_text = models.CharField(max_length=515, blank=True, null=True)
|
||||
rt_link = models.URLField(blank=True, null=True)
|
||||
rt_handle = models.CharField(max_length=63, blank=True, null=True)
|
||||
|
||||
published = models.BooleanField(default=0)
|
||||
pub_link = models.URLField(blank=True, null=True)
|
||||
|
||||
class Meta:
|
||||
unique_together = ("uri",)
|
||||
verbose_name_plural = "Social Links"
|
||||
# ordering = ['-likes', ]
|
||||
ordering = ['-created_at', ]
|
||||
|
||||
|
||||
def __unicode__(self):
|
||||
return "%s-" % self.handle
|
||||
|
||||
def __str__(self):
|
||||
return u'%s' % self.handle
|
||||
|
||||
|
||||
class SocialImg(models.Model):
|
||||
uri = models.CharField(max_length=63, blank=True, null=True)
|
||||
text = models.CharField(max_length=515, blank=True, null=True)
|
||||
img_link = models.URLField(blank=True, null=True)
|
||||
handle = models.CharField(max_length=63, blank=True, null=True)
|
||||
created_at = models.DateTimeField()
|
||||
platform = models.CharField(max_length=16)
|
||||
|
||||
class Meta:
|
||||
unique_together = ("uri",)
|
||||
verbose_name_plural = "Social Images"
|
||||
# ordering = ['-likes', ]
|
||||
ordering = ['-created_at', ]
|
||||
|
||||
|
||||
def __unicode__(self):
|
||||
return "%s-" % self.handle
|
||||
|
||||
def __str__(self):
|
||||
return u'%s' % self.handle
|
||||
39
socials/serializers.py
Normal file
39
socials/serializers.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from rest_framework import serializers
|
||||
from .models import *
|
||||
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
from rest_framework.permissions import BasePermission
|
||||
|
||||
|
||||
|
||||
class FAQSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Faq
|
||||
# fields = ('id', 'name', 'website', 'city')
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class SocialPostSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = SocialPost
|
||||
# fields = ('id', 'name', 'website', 'city')
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class SocialLinkSerializer(serializers.ModelSerializer):
|
||||
# target_language = serializers.SerializerMethodField()
|
||||
class Meta:
|
||||
model = SocialLink
|
||||
fields = '__all__'
|
||||
# depth = 2
|
||||
# fields = ('id', 'name',)
|
||||
|
||||
|
||||
class SocialImgsSerializer(serializers.ModelSerializer):
|
||||
# target_language = serializers.SerializerMethodField()
|
||||
class Meta:
|
||||
model = SocialImg
|
||||
fields = '__all__'
|
||||
# depth = 2
|
||||
# fields = ('id', 'name',)
|
||||
3
socials/tests.py
Normal file
3
socials/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
27
socials/urls.py
Normal file
27
socials/urls.py
Normal file
@@ -0,0 +1,27 @@
|
||||
"""ds_events URL Configuration
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/4.1/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import path, include, re_path
|
||||
from .views import *
|
||||
|
||||
urlpatterns = [
|
||||
# re_path(r'^faqs/', FAQsAPIView.as_view(), name="get-faqs"),
|
||||
re_path(r'^links/', SocialLinksAPIView.as_view(), name="get-links"),
|
||||
# re_path(r'^posts/', SocialPostsAPIView.as_view(), name="get-posts"),
|
||||
re_path(r'^images/', SocialImgsAPIView.as_view(), name="get-images"),
|
||||
# re_path(r'^events-token/', EventsTokenAPIView.as_view(), name="get-token-events"),
|
||||
|
||||
]
|
||||
50
socials/views.py
Normal file
50
socials/views.py
Normal file
@@ -0,0 +1,50 @@
|
||||
from django.shortcuts import render
|
||||
from datetime import datetime, timedelta
|
||||
import pytz, random
|
||||
|
||||
from .models import *
|
||||
from .serializers import *
|
||||
|
||||
from django.db.models import Q
|
||||
|
||||
from rest_framework import generics
|
||||
from rest_framework.decorators import authentication_classes, permission_classes
|
||||
from rest_framework.authentication import SessionAuthentication, BasicAuthentication
|
||||
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
# from durin.auth import TokenAuthentication
|
||||
|
||||
# from durin.views import APIAccessTokenView
|
||||
|
||||
from django_filters.rest_framework import DjangoFilterBackend
|
||||
from rest_framework import filters
|
||||
|
||||
from rest_framework.response import Response
|
||||
|
||||
td = timedelta(hours=8)
|
||||
odt = datetime.now() - td
|
||||
|
||||
# Create your views here.
|
||||
class FAQsAPIView(generics.ListAPIView):
|
||||
serializer_class = FAQSerializer
|
||||
queryset = Faq.objects.filter(published=True).order_by('seq_num')
|
||||
# filter_backends = [DjangoFilterBackend, filters.SearchFilter]
|
||||
# filterset_fields = ['show_title', 'event_type', 'show_date', 'show_day', 'venue__name']
|
||||
# search_fields = ['show_title', 'event_type']
|
||||
|
||||
|
||||
class SocialPostsAPIView(generics.ListAPIView):
|
||||
serializer_class = SocialPostSerializer
|
||||
queryset = SocialPost.objects.filter(published=True)
|
||||
|
||||
|
||||
class SocialLinksAPIView(generics.ListAPIView):
|
||||
serializer_class = SocialLinkSerializer
|
||||
queryset = SocialLink.objects.all()[:50]
|
||||
|
||||
|
||||
class SocialImgsAPIView(generics.ListAPIView):
|
||||
serializer_class = SocialImgsSerializer
|
||||
queryset = SocialImg.objects.all()[:18]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user