forked from Fediversity/Fediversity
Seperation of configuration form
This commit is contained in:
parent
c7937ac705
commit
2429b37ee9
7 changed files with 158 additions and 8 deletions
panel/src/panel
|
@ -1,4 +1,22 @@
|
|||
from django.contrib import admin
|
||||
from panel.models import Configuration
|
||||
from panel.models import Configuration, PeertubeConfig, PixelfedConfig, MastodonConfig
|
||||
|
||||
admin.site.register(Configuration)
|
||||
|
||||
class MastodonConfigInline(admin.StackedInline):
|
||||
model = MastodonConfig
|
||||
|
||||
|
||||
class PixelfedConfigInline(admin.StackedInline):
|
||||
model = PixelfedConfig
|
||||
|
||||
|
||||
class PeertubeConfigInline(admin.StackedInline):
|
||||
model = PeertubeConfig
|
||||
|
||||
|
||||
class DeployFormModelServices(admin.ModelAdmin):
|
||||
inlines = [MastodonConfigInline,
|
||||
PixelfedConfigInline, PeertubeConfigInline]
|
||||
|
||||
|
||||
admin.site.register(Configuration, DeployFormModelServices)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from django import forms
|
||||
from panel.models import Configuration
|
||||
from panel.models import Configuration, PeertubeConfig, PixelfedConfig, MastodonConfig
|
||||
|
||||
|
||||
class Deployment(forms.ModelForm):
|
||||
|
@ -7,10 +7,7 @@ class Deployment(forms.ModelForm):
|
|||
model = Configuration
|
||||
fields = [
|
||||
'domain',
|
||||
'mastodon',
|
||||
'pixelfed',
|
||||
'peertube',
|
||||
]
|
||||
]
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
@ -20,3 +17,23 @@ class Deployment(forms.ModelForm):
|
|||
(code, f"{operator}.{label}")
|
||||
for code, label in self.instance._meta.get_field('domain').choices
|
||||
]
|
||||
model = Configuration
|
||||
fields = ['domain']
|
||||
|
||||
|
||||
class MastodonConfigForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = MastodonConfig
|
||||
fields = ['mastodon']
|
||||
|
||||
|
||||
class PixelfedConfigForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = PixelfedConfig
|
||||
fields = ['pixelfed']
|
||||
|
||||
|
||||
class PeertubeConfigForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = PeertubeConfig
|
||||
fields = ['peertube']
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
# Generated by Django 4.2.16 on 2025-02-25 10:25
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('panel', '0002_deployformmodel_user'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='deployformmodel',
|
||||
name='mastodon',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='deployformmodel',
|
||||
name='peertube',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='deployformmodel',
|
||||
name='pixelfed',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='deployformmodel',
|
||||
name='domain',
|
||||
field=models.CharField(choices=[('fediversity_eu', 'fediversity.eu'), ('fediversity_net', 'fediversity.net')], max_length=255),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='PixelfedConfig',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('pixelfed', models.BooleanField(default=False)),
|
||||
('deploy_form', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='panel.deployformmodel')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='PeertubeConfig',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('peertube', models.BooleanField(default=False)),
|
||||
('deploy_form', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='panel.deployformmodel')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='MastodonConfig',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('mastodon', models.BooleanField(default=False)),
|
||||
('deploy_form', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='panel.deployformmodel')),
|
||||
],
|
||||
),
|
||||
]
|
14
panel/src/panel/migrations/0005_merge_20250226_1037.py
Normal file
14
panel/src/panel/migrations/0005_merge_20250226_1037.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
# Generated by Django 4.2.16 on 2025-02-26 10:37
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('panel', '0003_remove_deployformmodel_mastodon_and_more'),
|
||||
('panel', '0004_remove_configuration_user_configuration_enable_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
]
|
|
@ -2,7 +2,6 @@ from django.db import models
|
|||
from django.contrib.auth.models import User
|
||||
|
||||
|
||||
|
||||
class Configuration(models.Model):
|
||||
operator = models.ForeignKey(
|
||||
User,
|
||||
|
@ -26,6 +25,30 @@ class Configuration(models.Model):
|
|||
max_length=255,
|
||||
)
|
||||
# TODO: map to configuration model per service
|
||||
|
||||
|
||||
class MastodonConfig(models.Model):
|
||||
deploy_form = models.OneToOneField(
|
||||
Configuration, on_delete=models.CASCADE)
|
||||
mastodon = models.BooleanField(default=False)
|
||||
|
||||
def __str__(self):
|
||||
return f"Mastodon: {self.mastodon}"
|
||||
|
||||
|
||||
class PixelfedConfig(models.Model):
|
||||
deploy_form = models.OneToOneField(
|
||||
Configuration, on_delete=models.CASCADE)
|
||||
pixelfed = models.BooleanField(default=False)
|
||||
|
||||
def __str__(self):
|
||||
return f"Pixelfed: {self.pixelfed}"
|
||||
|
||||
|
||||
class PeertubeConfig(models.Model):
|
||||
deploy_form = models.OneToOneField(
|
||||
Configuration, on_delete=models.CASCADE)
|
||||
peertube = models.BooleanField(default=False)
|
||||
|
||||
def __str__(self):
|
||||
return f"Peertube: {self.peertube}"
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
<form method="post" enctype="multipart/form-data" action="{% url 'configuration_form' %}">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
{{ mastodon_form.as_p }}
|
||||
{{ pixelfed_form.as_p }}
|
||||
{{ peertube_form.as_p }}
|
||||
|
||||
</fieldset>
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@ from django.shortcuts import get_object_or_404
|
|||
from django.urls import reverse_lazy
|
||||
from panel.models import Configuration
|
||||
from panel import forms
|
||||
from .models import Configuration, MastodonConfig, PixelfedConfig, PeertubeConfig
|
||||
from .forms import Deployment, MastodonConfigForm, PixelfedConfigForm, PeertubeConfigForm
|
||||
|
||||
|
||||
class Index(TemplateView):
|
||||
|
@ -34,4 +36,22 @@ class ConfigurationForm(LoginRequiredMixin, UpdateView):
|
|||
def get_object(self, queryset=None):
|
||||
obj, created = Configuration.objects.get_or_create(
|
||||
operator=self.request.user)
|
||||
|
||||
return obj
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
deploy_form = self.get_object()
|
||||
|
||||
mastodon_config, _ = MastodonConfig.objects.get_or_create(
|
||||
deploy_form=deploy_form)
|
||||
pixelfed_config, _ = PixelfedConfig.objects.get_or_create(
|
||||
deploy_form=deploy_form)
|
||||
peertube_config, _ = PeertubeConfig.objects.get_or_create(
|
||||
deploy_form=deploy_form)
|
||||
|
||||
context['mastodon_form'] = MastodonConfigForm(instance=mastodon_config)
|
||||
context['pixelfed_form'] = PixelfedConfigForm(instance=pixelfed_config)
|
||||
context['peertube_form'] = PeertubeConfigForm(instance=peertube_config)
|
||||
|
||||
return context
|
||||
|
|
Loading…
Add table
Reference in a new issue