restructure posts and fragment
This commit is contained in:
parent
47bbec8dfe
commit
f3ecaedb55
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@ venv/
|
||||
.vscode/
|
||||
__pycache__/
|
||||
db.sqlite3
|
||||
.env
|
@ -1,3 +1,5 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
|
||||
|
||||
|
@ -1,5 +0,0 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from blog.models import *
|
||||
|
||||
admin.site.register(Post)
|
@ -1,7 +0,0 @@
|
||||
from django.urls import path, include
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('blogs/', include('blog.urls')),
|
||||
path('', views.index, name='index')
|
||||
]
|
3
website/control/admin.py
Normal file
3
website/control/admin.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
6
website/control/apps.py
Normal file
6
website/control/apps.py
Normal file
@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ControlConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'control'
|
34
website/control/models.py
Normal file
34
website/control/models.py
Normal file
@ -0,0 +1,34 @@
|
||||
from django.db import models
|
||||
|
||||
class ScheduledTask(models.Model):
|
||||
from control.tasks import REGISTERED_TASKS
|
||||
|
||||
class CatchupMode(models.IntegerChoices):
|
||||
SKIP = 0, ('SKIP TO LATEST')
|
||||
EXEC = 1, ('EXECUTE ALL')
|
||||
|
||||
class Interval(models.IntegerChoices):
|
||||
HOURS = 1, ('HOURS')
|
||||
DAYS = 24, ('DAYS')
|
||||
WEEKS = 168, ('WEEKS')
|
||||
|
||||
active = models.BooleanField(default=False)
|
||||
name = models.CharField(max_length=128)
|
||||
action = models.CharField(max_length=128, choices=zip(
|
||||
REGISTERED_TASKS.keys(), REGISTERED_TASKS.keys()))
|
||||
kwargs = models.JSONField(blank=True, null=True)
|
||||
repeat = models.IntegerField('Repeat Every', default=0)
|
||||
repeat_interval = models.IntegerField(
|
||||
'Interval', choices=Interval.choices, default=1)
|
||||
start_datetime = models.DateTimeField()
|
||||
end_datetime = models.DateTimeField(blank=True, null=True)
|
||||
next_cycle = models.DateTimeField(blank=True, null=True)
|
||||
catchup_mode = models.IntegerField(
|
||||
default=0, choices=CatchupMode.choices)
|
||||
|
||||
class Meta():
|
||||
verbose_name = 'Scheduled Task'
|
||||
verbose_name_plural = 'Scheduled Tasks'
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
9
website/control/tasks.py
Normal file
9
website/control/tasks.py
Normal file
@ -0,0 +1,9 @@
|
||||
from datetime import datetime, timezone, timedelta,
|
||||
|
||||
### TASKS ###
|
||||
|
||||
# def test_task(comms: dict, debug=False):
|
||||
# timestamp = datetime.now(tz=timezone.utc).strftime("%b %d %Y %H:%M")
|
||||
# text = "Test Task fired at " + timestamp
|
||||
# blocks = [make_section(text)]
|
||||
# process_comms(comms, blocks, debug)
|
Binary file not shown.
0
website/posts/__init__.py
Normal file
0
website/posts/__init__.py
Normal file
5
website/posts/admin.py
Normal file
5
website/posts/admin.py
Normal file
@ -0,0 +1,5 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from posts.models import *
|
||||
|
||||
admin.site.register(Post)
|
@ -1,6 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class BlogConfig(AppConfig):
|
||||
class PostsConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'blog'
|
||||
name = 'posts'
|
0
website/posts/migrations/__init__.py
Normal file
0
website/posts/migrations/__init__.py
Normal file
3
website/posts/tests.py
Normal file
3
website/posts/tests.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
11
website/posts/urls.py
Normal file
11
website/posts/urls.py
Normal file
@ -0,0 +1,11 @@
|
||||
from django.urls import path, include
|
||||
from rest_framework.routers import DefaultRouter
|
||||
from . import views
|
||||
|
||||
router = DefaultRouter()
|
||||
router.register(r'posts', views.PostsViewSet)
|
||||
# router.register(r'users', views.UserViewSet)
|
||||
|
||||
urlpatterns = [
|
||||
path('', include(router.urls)),
|
||||
]
|
30
website/posts/views.py
Normal file
30
website/posts/views.py
Normal file
@ -0,0 +1,30 @@
|
||||
from django.contrib.auth.models import User
|
||||
from django.shortcuts import render
|
||||
from snippets.serializers import UserSerializer
|
||||
from .models import Post
|
||||
from .serializers import PostSerializer
|
||||
from posts.permissions import IsOwnerOrReadOnly
|
||||
from rest_framework import permissions, renderers
|
||||
from rest_framework.reverse import reverse
|
||||
from rest_framework import viewsets
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.response import Response
|
||||
|
||||
class PostsViewSet(viewsets.ModelViewSet):
|
||||
"""
|
||||
docstring
|
||||
"""
|
||||
queryset = Post.objects.all()
|
||||
serializer_class = PostSerializer
|
||||
permission_classes = [permissions.IsAuthenticatedOrReadOnly,
|
||||
IsOwnerOrReadOnly]
|
||||
|
||||
def perform_create(self, serializer):
|
||||
serializer.save(owner=self.request.user)
|
||||
|
||||
class UserViewSet(viewsets.ReadOnlyModelViewSet):
|
||||
"""
|
||||
This viewset automatically provides `list` and `retrieve` actions.
|
||||
"""
|
||||
queryset = User.objects.all()
|
||||
serializer_class = UserSerializer
|
@ -39,8 +39,9 @@ INSTALLED_APPS = [
|
||||
'django.contrib.staticfiles',
|
||||
'rest_framework',
|
||||
'snippets.apps.SnippetsConfig',
|
||||
'blog.apps.BlogConfig',
|
||||
'posts.apps.PostsConfig',
|
||||
'api.apps.ApiConfig',
|
||||
'control.apps.ControlConfig',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
@ -18,7 +18,8 @@ from django.urls import path, include
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('', include('snippets.urls')),
|
||||
path('snippets/', include('snippets.urls')),
|
||||
path('posts/', include('posts.urls'))
|
||||
]
|
||||
|
||||
urlpatterns += [
|
||||
|
Reference in New Issue
Block a user