diff --git a/.gitignore b/.gitignore index 0bcdbc3..9c19884 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ venv/ .vscode/ __pycache__/ db.sqlite3 +.env \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..868a1c5 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "public/libcasa/themes/risotto"] + path = public/libcasa/themes/risotto + url = https://github.com/joeroe/risotto.git diff --git a/website/api/__init__.py b/api/api/__init__.py similarity index 100% rename from website/api/__init__.py rename to api/api/__init__.py diff --git a/website/api/admin.py b/api/api/admin.py similarity index 100% rename from website/api/admin.py rename to api/api/admin.py diff --git a/website/api/apps.py b/api/api/apps.py similarity index 100% rename from website/api/apps.py rename to api/api/apps.py diff --git a/website/api/migrations/__init__.py b/api/api/migrations/__init__.py similarity index 100% rename from website/api/migrations/__init__.py rename to api/api/migrations/__init__.py diff --git a/website/api/models.py b/api/api/models.py similarity index 96% rename from website/api/models.py rename to api/api/models.py index 71a8362..508029f 100644 --- a/website/api/models.py +++ b/api/api/models.py @@ -1,3 +1,5 @@ from django.db import models # Create your models here. + + diff --git a/website/api/permissions.py b/api/api/permissions.py similarity index 100% rename from website/api/permissions.py rename to api/api/permissions.py diff --git a/website/api/serializers.py b/api/api/serializers.py similarity index 100% rename from website/api/serializers.py rename to api/api/serializers.py diff --git a/website/api/tests.py b/api/api/tests.py similarity index 100% rename from website/api/tests.py rename to api/api/tests.py diff --git a/website/api/urls.py b/api/api/urls.py similarity index 100% rename from website/api/urls.py rename to api/api/urls.py diff --git a/website/api/views.py b/api/api/views.py similarity index 100% rename from website/api/views.py rename to api/api/views.py diff --git a/website/blog/__init__.py b/api/control/__init__.py similarity index 100% rename from website/blog/__init__.py rename to api/control/__init__.py diff --git a/api/control/admin.py b/api/control/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/api/control/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/api/control/apps.py b/api/control/apps.py new file mode 100644 index 0000000..14765b6 --- /dev/null +++ b/api/control/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ControlConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'control' diff --git a/website/blog/migrations/__init__.py b/api/control/migrations/__init__.py similarity index 100% rename from website/blog/migrations/__init__.py rename to api/control/migrations/__init__.py diff --git a/api/control/models.py b/api/control/models.py new file mode 100644 index 0000000..d9870f3 --- /dev/null +++ b/api/control/models.py @@ -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 diff --git a/api/control/tasks.py b/api/control/tasks.py new file mode 100644 index 0000000..8c33ded --- /dev/null +++ b/api/control/tasks.py @@ -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) diff --git a/website/blog/tests.py b/api/control/tests.py similarity index 100% rename from website/blog/tests.py rename to api/control/tests.py diff --git a/website/blog/views.py b/api/control/views.py similarity index 100% rename from website/blog/views.py rename to api/control/views.py diff --git a/website/manage.py b/api/manage.py similarity index 100% rename from website/manage.py rename to api/manage.py diff --git a/website/snippets/__init__.py b/api/posts/__init__.py similarity index 100% rename from website/snippets/__init__.py rename to api/posts/__init__.py diff --git a/api/posts/admin.py b/api/posts/admin.py new file mode 100644 index 0000000..921d847 --- /dev/null +++ b/api/posts/admin.py @@ -0,0 +1,5 @@ +from django.contrib import admin + +from posts.models import * + +admin.site.register(Post) \ No newline at end of file diff --git a/website/blog/apps.py b/api/posts/apps.py similarity index 65% rename from website/blog/apps.py rename to api/posts/apps.py index 94788a5..b18ed0d 100644 --- a/website/blog/apps.py +++ b/api/posts/apps.py @@ -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' diff --git a/website/blog/migrations/0001_initial.py b/api/posts/migrations/0001_initial.py similarity index 100% rename from website/blog/migrations/0001_initial.py rename to api/posts/migrations/0001_initial.py diff --git a/website/snippets/migrations/__init__.py b/api/posts/migrations/__init__.py similarity index 100% rename from website/snippets/migrations/__init__.py rename to api/posts/migrations/__init__.py diff --git a/website/blog/models.py b/api/posts/models.py similarity index 100% rename from website/blog/models.py rename to api/posts/models.py diff --git a/website/blog/permissions.py b/api/posts/permissions.py similarity index 100% rename from website/blog/permissions.py rename to api/posts/permissions.py diff --git a/website/blog/serializers.py b/api/posts/serializers.py similarity index 100% rename from website/blog/serializers.py rename to api/posts/serializers.py diff --git a/website/snippets/tests.py b/api/posts/tests.py similarity index 100% rename from website/snippets/tests.py rename to api/posts/tests.py diff --git a/api/posts/urls.py b/api/posts/urls.py new file mode 100644 index 0000000..3ba3655 --- /dev/null +++ b/api/posts/urls.py @@ -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)), +] \ No newline at end of file diff --git a/api/posts/views.py b/api/posts/views.py new file mode 100644 index 0000000..5d31666 --- /dev/null +++ b/api/posts/views.py @@ -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 \ No newline at end of file diff --git a/website/website/__init__.py b/api/snippets/__init__.py similarity index 100% rename from website/website/__init__.py rename to api/snippets/__init__.py diff --git a/website/snippets/admin.py b/api/snippets/admin.py similarity index 100% rename from website/snippets/admin.py rename to api/snippets/admin.py diff --git a/website/snippets/apps.py b/api/snippets/apps.py similarity index 100% rename from website/snippets/apps.py rename to api/snippets/apps.py diff --git a/website/snippets/migrations/0001_initial.py b/api/snippets/migrations/0001_initial.py similarity index 100% rename from website/snippets/migrations/0001_initial.py rename to api/snippets/migrations/0001_initial.py diff --git a/api/snippets/migrations/__init__.py b/api/snippets/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/website/snippets/models.py b/api/snippets/models.py similarity index 100% rename from website/snippets/models.py rename to api/snippets/models.py diff --git a/website/snippets/permissions.py b/api/snippets/permissions.py similarity index 100% rename from website/snippets/permissions.py rename to api/snippets/permissions.py diff --git a/website/snippets/serializers.py b/api/snippets/serializers.py similarity index 100% rename from website/snippets/serializers.py rename to api/snippets/serializers.py diff --git a/api/snippets/tests.py b/api/snippets/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/api/snippets/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/website/snippets/urls.py b/api/snippets/urls.py similarity index 100% rename from website/snippets/urls.py rename to api/snippets/urls.py diff --git a/website/snippets/views.py b/api/snippets/views.py similarity index 100% rename from website/snippets/views.py rename to api/snippets/views.py diff --git a/api/website/__init__.py b/api/website/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/website/website/asgi.py b/api/website/asgi.py similarity index 100% rename from website/website/asgi.py rename to api/website/asgi.py diff --git a/website/website/settings.py b/api/website/settings.py similarity index 72% rename from website/website/settings.py rename to api/website/settings.py index cf7ad8b..294ee1b 100644 --- a/website/website/settings.py +++ b/api/website/settings.py @@ -11,10 +11,26 @@ https://docs.djangoproject.com/en/4.0/ref/settings/ """ from pathlib import Path +import os # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent +## ENVARS ## + +POSTGRES_DB = os.getenv('POSTGRES_DB') +POSTGRES_USER = os.getenv('POSTGRES_USER') +POSTGRES_PASSWORD = os.getenv('POSTGRES_PASSWORD') +POSTGRES_HOST = os.getenv('POSTGRES_HOST') + + + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = False +if os.getenv('DEBUG') == 'True': + DEBUG = True + + # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/ @@ -39,8 +55,9 @@ INSTALLED_APPS = [ 'django.contrib.staticfiles', 'rest_framework', 'snippets.apps.SnippetsConfig', - 'blog.apps.BlogConfig', + 'posts.apps.PostsConfig', 'api.apps.ApiConfig', + 'control.apps.ControlConfig', ] MIDDLEWARE = [ @@ -79,11 +96,23 @@ WSGI_APPLICATION = 'website.wsgi.application' DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': BASE_DIR / 'db.sqlite3', + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': POSTGRES_DB, + 'USER': POSTGRES_USER, + 'PASSWORD': POSTGRES_PASSWORD, + 'HOST': POSTGRES_HOST, + 'PORT': '5432', } } +if os.getenv('DEV') == 'true': + DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } + } + # Password validation # https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators @@ -133,4 +162,27 @@ REST_FRAMEWORK = { 'rest_framework.authentication.BasicAuthentication', 'rest_framework.authentication.SessionAuthentication', ] -} \ No newline at end of file +} + +# LOGGING = { +# 'version': 1, +# 'disable_existing_loggers': False, +# 'handlers': { +# 'file': { +# 'level': 'DEBUG', +# 'class': 'logging.FileHandler', +# 'filename': './debug.log', +# }, +# 'error_file': { +# 'level': 'ERROR', +# 'class': 'logging.FileHandler', +# 'filename': './error.log', +# }, +# }, +# 'loggers': { +# 'django': { +# 'handlers': ['file', 'error_file'], +# 'propagate': True, +# }, +# }, +# } diff --git a/website/website/urls.py b/api/website/urls.py similarity index 90% rename from website/website/urls.py rename to api/website/urls.py index 74b2a77..1eea40e 100644 --- a/website/website/urls.py +++ b/api/website/urls.py @@ -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 += [ diff --git a/website/website/wsgi.py b/api/website/wsgi.py similarity index 100% rename from website/website/wsgi.py rename to api/website/wsgi.py diff --git a/public/libcasa/.hugo_build.lock b/public/libcasa/.hugo_build.lock new file mode 100644 index 0000000..e69de29 diff --git a/public/libcasa/archetypes/default.md b/public/libcasa/archetypes/default.md new file mode 100644 index 0000000..00e77bd --- /dev/null +++ b/public/libcasa/archetypes/default.md @@ -0,0 +1,6 @@ +--- +title: "{{ replace .Name "-" " " | title }}" +date: {{ .Date }} +draft: true +--- + diff --git a/public/libcasa/config.yml b/public/libcasa/config.yml new file mode 100644 index 0000000..9873898 --- /dev/null +++ b/public/libcasa/config.yml @@ -0,0 +1,53 @@ +baseURL: https://liberta.casa +theme: risotto +languageCode: en-us +title: Liberta Casa +paginate: 3 +authors: [ Georg Pfuetzenreuter, Pratyush Desai ] + +# Automatically add content sections to main menu +sectionPagesMenu: main + +params: + theme: + palette: monokai-dark + mode: dark-mode + about: + title: Liberta Casa + description: 'For those who FLOSS shall be free.' + logo: images/logo.png + socialLinks: + - icon: fab fa-irc + title: IRC + url: 'https://liberta.casa/gamja' + - icon: fas fa-envelope + title: Email + url: 'mailto:hello@liberta.casa' + +menu: + main: + - identifier: about + name: About + url: /about/ + weight: 10 + - identifier: rules + name: Rules + url: /rules/ + weight: 10 + - identifier: faqs + name: FAQ + url: /faqs/ + weight: 10 + - identifier: accounts + name: Account + url: /accounts/ + weight: 10 + - identifier: tools + name: Tools + url: /tools/ + weight: 10 + +taxonomies: + category: categories + tag: tags + series: series \ No newline at end of file diff --git a/public/libcasa/content/_index.md b/public/libcasa/content/_index.md new file mode 100644 index 0000000..8407b17 --- /dev/null +++ b/public/libcasa/content/_index.md @@ -0,0 +1,3 @@ ++++ +author = "LibCasa Authors" ++++ diff --git a/public/libcasa/content/about.md b/public/libcasa/content/about.md new file mode 100644 index 0000000..a4916d9 --- /dev/null +++ b/public/libcasa/content/about.md @@ -0,0 +1,7 @@ ++++ +title = "About" +description = "Liberta Casa, providing services.. for some reason." +date = "2021-12-12" +aliases = ["about-us", "about-libertacasa", "contact"] +author = "LibCasa Authors" ++++ \ No newline at end of file diff --git a/public/libcasa/content/accounts/_index.md b/public/libcasa/content/accounts/_index.md new file mode 100644 index 0000000..0f4fedd --- /dev/null +++ b/public/libcasa/content/accounts/_index.md @@ -0,0 +1,6 @@ +--- +title: "Accounts" +date: 2022-01-08T15:14:39+05:30 +draft: true +--- + diff --git a/public/libcasa/content/faqs/_index.md b/public/libcasa/content/faqs/_index.md new file mode 100644 index 0000000..d3b5b08 --- /dev/null +++ b/public/libcasa/content/faqs/_index.md @@ -0,0 +1,6 @@ +--- +title: "Faqs" +date: 2022-01-08T15:14:13+05:30 +draft: true +--- + diff --git a/public/libcasa/content/rules.md b/public/libcasa/content/rules.md new file mode 100644 index 0000000..2c1609c --- /dev/null +++ b/public/libcasa/content/rules.md @@ -0,0 +1,3 @@ ++++ +title = "Rules" ++++ \ No newline at end of file diff --git a/public/libcasa/content/tools/_index.md b/public/libcasa/content/tools/_index.md new file mode 100644 index 0000000..78e8042 --- /dev/null +++ b/public/libcasa/content/tools/_index.md @@ -0,0 +1,6 @@ +--- +title: "Tools" +date: 2022-01-08T15:14:47+05:30 +draft: true +--- + diff --git a/public/libcasa/themes/risotto b/public/libcasa/themes/risotto new file mode 160000 index 0000000..07f1b3e --- /dev/null +++ b/public/libcasa/themes/risotto @@ -0,0 +1 @@ +Subproject commit 07f1b3ecfd4202a69847d47c89ece4e4d01278c4 diff --git a/website/blog/admin.py b/website/blog/admin.py deleted file mode 100644 index 6bd12cc..0000000 --- a/website/blog/admin.py +++ /dev/null @@ -1,5 +0,0 @@ -from django.contrib import admin - -from blog.models import * - -admin.site.register(Post) \ No newline at end of file diff --git a/website/blog/urls.py b/website/blog/urls.py deleted file mode 100644 index 20d1748..0000000 --- a/website/blog/urls.py +++ /dev/null @@ -1,7 +0,0 @@ -from django.urls import path, include -from . import views - -urlpatterns = [ - path('blogs/', include('blog.urls')), - path('', views.index, name='index') -] \ No newline at end of file diff --git a/website/db.sqlite3 b/website/db.sqlite3 deleted file mode 100644 index 2b93ace..0000000 Binary files a/website/db.sqlite3 and /dev/null differ