mirror of
https://gitlab.com/brutaldon/brutaldon.git
synced 2024-12-04 14:46:24 -05:00
Instead of setting a max_length on posts, catch API error on posting
This commit is contained in:
parent
0d3cc1c5ac
commit
928f0fd7a7
@ -11,8 +11,6 @@ PRIVACY_CHOICES = (('public', 'Public'),
|
||||
|
||||
timezones = [ (tz, tz) for tz in common_timezones]
|
||||
|
||||
MAX_LENGTH = settings.TOOT_MAX_LENGTH
|
||||
|
||||
class LoginForm(forms.Form):
|
||||
instance = forms.CharField(label="Instance",
|
||||
max_length=256)
|
||||
@ -31,39 +29,25 @@ class PreferencesForm(forms.ModelForm):
|
||||
class PostForm(forms.Form):
|
||||
"""def status_post(self, status, in_reply_to_id=None, media_ids=None,
|
||||
sensitive=False, visibility=None, spoiler_text=None):"""
|
||||
status = forms.CharField(label="Toot", max_length=MAX_LENGTH, widget=forms.Textarea)
|
||||
status = forms.CharField(label="Toot", widget=forms.Textarea)
|
||||
visibility = forms.ChoiceField(label="Toot visibility", choices=PRIVACY_CHOICES,
|
||||
required=False)
|
||||
spoiler_text = forms.CharField(label="CW or Subject", max_length=MAX_LENGTH,
|
||||
spoiler_text = forms.CharField(label="CW or Subject",
|
||||
required=False)
|
||||
media_file_1 = forms.FileField(label = "Media 1",
|
||||
required=False)
|
||||
media_text_1 = forms.CharField(label="Describe media 1.",
|
||||
max_length=MAX_LENGTH,
|
||||
required=False)
|
||||
media_file_2 = forms.FileField(label = "Media 2",
|
||||
required=False)
|
||||
media_text_2 = forms.CharField(label="Describe media 2.",
|
||||
max_length=MAX_LENGTH,
|
||||
required=False)
|
||||
media_file_3 = forms.FileField(label = "Media 3",
|
||||
required=False)
|
||||
media_text_3 = forms.CharField(label="Describe media 3.",
|
||||
max_length=MAX_LENGTH,
|
||||
required=False)
|
||||
media_file_4 = forms.FileField(label = "Media 4",
|
||||
required=False)
|
||||
media_text_4 = forms.CharField(label="Describe media 4.",
|
||||
max_length=MAX_LENGTH,
|
||||
required=False)
|
||||
media_sensitive = forms.BooleanField(label="Sensitive media?", required=False)
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super().clean()
|
||||
status = cleaned_data.get("status")
|
||||
spoiler_text = cleaned_data.get("spoiler_text")
|
||||
|
||||
if (status and spoiler_text and len(status) + len(spoiler_text) > MAX_LENGTH):
|
||||
raise forms.ValidationError("Max length of toot exceeded: %(max_length)s",
|
||||
code="too_long",
|
||||
params={"max_length": MAX_LENGTH})
|
||||
|
@ -7,7 +7,7 @@ from django.urls import reverse
|
||||
from django.core.files.uploadhandler import TemporaryFileUploadHandler
|
||||
from brutaldon.forms import LoginForm, OAuthLoginForm, PreferencesForm, PostForm
|
||||
from brutaldon.models import Client, Account, Preference, Theme
|
||||
from mastodon import Mastodon, AttribAccessDict, MastodonError
|
||||
from mastodon import Mastodon, AttribAccessDict, MastodonError, MastodonAPIError
|
||||
from urllib import parse
|
||||
from pdb import set_trace
|
||||
from bs4 import BeautifulSoup
|
||||
@ -411,10 +411,17 @@ def toot(request, mention=None):
|
||||
None)))
|
||||
if form.cleaned_data['visibility'] == '':
|
||||
form.cleaned_data['visibility'] = request.session['user'].source.privacy
|
||||
mastodon.status_post(status=form.cleaned_data['status'],
|
||||
visibility=form.cleaned_data['visibility'],
|
||||
spoiler_text=form.cleaned_data['spoiler_text'],
|
||||
media_ids=media_objects)
|
||||
try:
|
||||
mastodon.status_post(status=form.cleaned_data['status'],
|
||||
visibility=form.cleaned_data['visibility'],
|
||||
spoiler_text=form.cleaned_data['spoiler_text'],
|
||||
media_ids=media_objects)
|
||||
except MastodonAPIError as error:
|
||||
form.add_error("", "%s" % error.args[-1])
|
||||
return render(request, 'main/post.html',
|
||||
{'form': form,
|
||||
'own_acct': request.session['user'],
|
||||
'preferences': account.preferences})
|
||||
return redirect(home)
|
||||
else:
|
||||
return render(request, 'main/post.html',
|
||||
|
Loading…
Reference in New Issue
Block a user