Mini-post form and default post privacy
This commit is contained in:
parent
7af72887e9
commit
02f0ee560a
|
@ -1,6 +1,7 @@
|
||||||
from django import forms
|
from django import forms
|
||||||
|
|
||||||
PRIVACY_CHOICES = (('public', 'Public'),
|
PRIVACY_CHOICES = (('default', 'Default'),
|
||||||
|
('public', 'Public'),
|
||||||
('unlisted', 'Unlisted'),
|
('unlisted', 'Unlisted'),
|
||||||
('private', 'Private'),
|
('private', 'Private'),
|
||||||
('direct', 'Direct'))
|
('direct', 'Direct'))
|
||||||
|
@ -29,7 +30,8 @@ class PostForm(forms.Form):
|
||||||
"""def status_post(self, status, in_reply_to_id=None, media_ids=None,
|
"""def status_post(self, status, in_reply_to_id=None, media_ids=None,
|
||||||
sensitive=False, visibility=None, spoiler_text=None):"""
|
sensitive=False, visibility=None, spoiler_text=None):"""
|
||||||
status = forms.CharField(label="Toot", max_length=500, widget=forms.Textarea)
|
status = forms.CharField(label="Toot", max_length=500, widget=forms.Textarea)
|
||||||
visibility = forms.ChoiceField(label="Toot visibility", choices=PRIVACY_CHOICES)
|
visibility = forms.ChoiceField(label="Toot visibility", choices=PRIVACY_CHOICES,
|
||||||
|
required=False)
|
||||||
spoiler_text = forms.CharField(label="CW or Subject", max_length=500,
|
spoiler_text = forms.CharField(label="CW or Subject", max_length=500,
|
||||||
required=False)
|
required=False)
|
||||||
media_file_1 = forms.FileField(label = "Media attachment 1",
|
media_file_1 = forms.FileField(label = "Media attachment 1",
|
||||||
|
|
|
@ -131,3 +131,7 @@ SANITIZER_ALLOWED_ATTRIBUTES = ['href', 'src']
|
||||||
# File upload settings.
|
# File upload settings.
|
||||||
# Important: media will not work if you change this.
|
# Important: media will not work if you change this.
|
||||||
FILE_UPLOAD_HANDLERS = ["django.core.files.uploadhandler.TemporaryFileUploadHandler"]
|
FILE_UPLOAD_HANDLERS = ["django.core.files.uploadhandler.TemporaryFileUploadHandler"]
|
||||||
|
|
||||||
|
# Session serialization
|
||||||
|
# Important: whatever you choose has to be able to serialize DateTime, so not JSON.
|
||||||
|
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
{% load widget_tweaks %}
|
||||||
|
<form method="post" action="{% url "toot" %}" enctype="multipart/form-data">
|
||||||
|
{% csrf_token %}
|
||||||
|
|
||||||
|
<div class="field" >
|
||||||
|
<label class="label" >{{ form.status.label }}</label>
|
||||||
|
<div class="control">
|
||||||
|
{% render_field form.status class+="textarea is-primary" rows="4" %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
{{ form.errors }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="field has-addons">
|
||||||
|
<div class="control">
|
||||||
|
<input type="submit" class="button is-primary"
|
||||||
|
name="toot" value="Toot">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<a href="{% url "toot" %}">
|
||||||
|
Complete toot form (media, etc)
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</form>
|
|
@ -9,7 +9,7 @@
|
||||||
{% if form %}
|
{% if form %}
|
||||||
<h1 class="title">Post</h1>
|
<h1 class="title">Post</h1>
|
||||||
<div class="box">
|
<div class="box">
|
||||||
{% include "main/post_partial.html" %}
|
{% include "main/post_minimal_partial.html" %}
|
||||||
</div>
|
</div>
|
||||||
<hr class="is-hidden">
|
<hr class="is-hidden">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -57,7 +57,7 @@ def timeline(request, timeline='home', timeline_name='Home', max_id=None, since_
|
||||||
except NotLoggedInException:
|
except NotLoggedInException:
|
||||||
return redirect(login)
|
return redirect(login)
|
||||||
data = mastodon.timeline(timeline, limit=100, max_id=max_id, since_id=since_id)
|
data = mastodon.timeline(timeline, limit=100, max_id=max_id, since_id=since_id)
|
||||||
form = PostForm()
|
form = PostForm(initial={'visibility': request.session['user'].source.privacy})
|
||||||
try:
|
try:
|
||||||
prev = data[0]._pagination_prev
|
prev = data[0]._pagination_prev
|
||||||
if len(mastodon.timeline(since_id=prev['since_id'])) == 0:
|
if len(mastodon.timeline(since_id=prev['since_id'])) == 0:
|
||||||
|
@ -153,7 +153,7 @@ def oauth_callback(request):
|
||||||
scopes=['read', 'write', 'follow'])
|
scopes=['read', 'write', 'follow'])
|
||||||
request.session['access_token'] = access_token
|
request.session['access_token'] = access_token
|
||||||
user = mastodon.account_verify_credentials()
|
user = mastodon.account_verify_credentials()
|
||||||
request.session['user'] = user.acct
|
request.session['user'] = user
|
||||||
return redirect(home)
|
return redirect(home)
|
||||||
|
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@ def old_login(request):
|
||||||
account.save()
|
account.save()
|
||||||
request.session['username'] = username
|
request.session['username'] = username
|
||||||
user = mastodon.account_verify_credentials()
|
user = mastodon.account_verify_credentials()
|
||||||
request.session['user'] = user.acct
|
request.session['user'] = user
|
||||||
|
|
||||||
return redirect(home)
|
return redirect(home)
|
||||||
except:
|
except:
|
||||||
|
@ -269,7 +269,7 @@ def settings(request):
|
||||||
@never_cache
|
@never_cache
|
||||||
def toot(request):
|
def toot(request):
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
form = PostForm()
|
form = PostForm(initial={'visibility': request.session['user'].source.privacy})
|
||||||
return render(request, 'main/post.html',
|
return render(request, 'main/post.html',
|
||||||
{'form': form,
|
{'form': form,
|
||||||
'fullbrutalism': fullbrutalism_p(request)})
|
'fullbrutalism': fullbrutalism_p(request)})
|
||||||
|
@ -288,6 +288,8 @@ def toot(request):
|
||||||
description=request.POST.get('media_text_'
|
description=request.POST.get('media_text_'
|
||||||
+str(index),
|
+str(index),
|
||||||
None)))
|
None)))
|
||||||
|
if form.cleaned_data['visibility'] == '':
|
||||||
|
form.cleaned_data['visibility'] = request.session['user'].source.privacy
|
||||||
mastodon.status_post(status=form.cleaned_data['status'],
|
mastodon.status_post(status=form.cleaned_data['status'],
|
||||||
visibility=form.cleaned_data['visibility'],
|
visibility=form.cleaned_data['visibility'],
|
||||||
spoiler_text=form.cleaned_data['spoiler_text'],
|
spoiler_text=form.cleaned_data['spoiler_text'],
|
||||||
|
|
Loading…
Reference in New Issue