Fix up models and forms to meet current needs
This commit is contained in:
parent
9cb40914d4
commit
50406383b3
|
@ -1,7 +1,7 @@
|
|||
from django import forms
|
||||
from django.conf import settings
|
||||
from pytz import common_timezones
|
||||
from .models import Theme
|
||||
from .models import Theme, Preference
|
||||
|
||||
|
||||
PRIVACY_CHOICES = (('public', 'Public'),
|
||||
|
@ -24,28 +24,10 @@ class OAuthLoginForm(forms.Form):
|
|||
instance = forms.CharField(label="Instance",
|
||||
max_length=256)
|
||||
|
||||
class SettingsForm(forms.Form):
|
||||
fullbrutalism = forms.BooleanField(label="Use FULLBRUTALISM mode?",
|
||||
required=False,
|
||||
help_text=
|
||||
"""FULLBRUTALISM mode strips away most of the niceties of modern web design when
|
||||
brutaldon is viewed in a graphical browser. It has no effect in text-only browsers.""")
|
||||
filter_replies = forms.BooleanField(label="Filter replies from home timeline?",
|
||||
required=False,
|
||||
help_text=
|
||||
"""Should replies be filtered out of your home timeline, giving you only pure,
|
||||
top-level posts?""")
|
||||
filter_boosts = forms.BooleanField(label="Filter boosts from home timeline?",
|
||||
required=False,
|
||||
help_text=
|
||||
"""Should replies be filtered out of your home timeline, giving you only pure,
|
||||
Original Content?""")
|
||||
timezone = forms.ChoiceField(label="Your local timezone",
|
||||
choices=timezones,
|
||||
required=False,
|
||||
help_text=
|
||||
"""What time zone do you prefer to have times displayed in? The default choice is UTC.""")
|
||||
|
||||
class PreferencesForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Preference
|
||||
fields = ['theme', 'filter_replies', 'filter_boosts', 'timezone']
|
||||
|
||||
class PostForm(forms.Form):
|
||||
"""def status_post(self, status, in_reply_to_id=None, media_ids=None,
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -5,20 +5,20 @@ from pytz import common_timezones
|
|||
timezones = [(tz, tz) for tz in common_timezones]
|
||||
|
||||
class Client(models.Model):
|
||||
name = models.TextField(default = "brutaldon")
|
||||
name = models.CharField(default = "brutaldon", max_length=80)
|
||||
api_base_id = models.URLField(default="https://mastodon.social")
|
||||
client_id = models.TextField(null=True, blank=True)
|
||||
client_secret = models.TextField(null=True, blank=True)
|
||||
client_id = models.CharField(null=True, blank=True, max_length=2048)
|
||||
client_secret = models.CharField(null=True, blank=True, max_length=2048)
|
||||
|
||||
def __str__(self):
|
||||
return self.name + ": " + self.api_base_id
|
||||
|
||||
class Theme(models.Model):
|
||||
name = models.TextField(max_length=80, unique=True)
|
||||
prefix = models.TextField(max_length=40, null=True, default="default")
|
||||
main_css = models.TextField(max_length=1024, blank=True, null=True,
|
||||
name = models.CharField(max_length=80, unique=True)
|
||||
prefix = models.CharField(max_length=40, null=True, default="default")
|
||||
main_css = models.CharField(max_length=1024, blank=True, null=True,
|
||||
default="css/fullbrutalism.css")
|
||||
tweaks_css = models.TextField(max_length=1024, blank=True, null=True)
|
||||
tweaks_css = models.CharField(max_length=1024, blank=True, null=True)
|
||||
is_brutalist = models.BooleanField(default=False)
|
||||
|
||||
def __str__(self):
|
||||
|
@ -28,14 +28,14 @@ class Preference(models.Model):
|
|||
theme = models.ForeignKey(Theme, models.SET_NULL, null=True)
|
||||
filter_replies = models.BooleanField(default=False)
|
||||
filter_boosts = models.BooleanField(default=False)
|
||||
timezone = models.TextField(max_length=80, blank=True, null=True,
|
||||
choices=timezones)
|
||||
timezone = models.CharField(max_length=80, blank=True, null=True,
|
||||
choices=timezones, default='UTC')
|
||||
|
||||
class Account(models.Model):
|
||||
username = models.EmailField()
|
||||
email = models.EmailField(null=True, blank=True)
|
||||
django_user = models.ForeignKey(settings.AUTH_USER_MODEL, models.CASCADE, null=True)
|
||||
access_token = models.TextField(null=True, blank=True)
|
||||
access_token = models.CharField(null=True, blank=True, max_length=2048)
|
||||
client= models.ForeignKey(Client, models.SET_NULL, null=True)
|
||||
preferences = models.ForeignKey(Preference, models.SET_NULL, null=True)
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ from django.urls import reverse
|
|||
from django.views.decorators.cache import never_cache, cache_page
|
||||
from django.urls import reverse
|
||||
from django.core.files.uploadhandler import TemporaryFileUploadHandler
|
||||
from brutaldon.forms import LoginForm, OAuthLoginForm, SettingsForm, PostForm
|
||||
from brutaldon.forms import LoginForm, OAuthLoginForm, PreferencesForm, PostForm
|
||||
from brutaldon.models import Client, Account, Preference, Theme
|
||||
from mastodon import Mastodon, AttribAccessDict, MastodonError
|
||||
from urllib import parse
|
||||
|
@ -370,7 +370,7 @@ def user(request, username, prev=None, next=None):
|
|||
def settings(request):
|
||||
account = Account.objects.get(username=username, client_id=client.id)
|
||||
if request.method == 'POST':
|
||||
form = SettingsForm(request.POST)
|
||||
form = PreferencesForm(request.POST)
|
||||
if form.is_valid():
|
||||
account.preferences.theme = Theme.objects.get(form.cleaned_data['theme'])
|
||||
account.preferences.filter_replies = form.cleaned_data['filter_replies']
|
||||
|
@ -383,7 +383,7 @@ def settings(request):
|
|||
return render(request, 'setup/settings.html',
|
||||
{'form' : form, 'account': account})
|
||||
else:
|
||||
form = SettingsForm(account.preferences)
|
||||
form = PreferencesForm(account.preferences)
|
||||
return render(request, 'setup/settings.html',
|
||||
{ 'form': form,
|
||||
'own_acct': request.session['user'],
|
||||
|
|
Loading…
Reference in New Issue