Mini-post form and default post privacy

This commit is contained in:
Jason McBrayer 2018-05-22 08:57:45 -04:00
parent 7af72887e9
commit 02f0ee560a
5 changed files with 42 additions and 7 deletions

View File

@ -1,6 +1,7 @@
from django import forms
PRIVACY_CHOICES = (('public', 'Public'),
PRIVACY_CHOICES = (('default', 'Default'),
('public', 'Public'),
('unlisted', 'Unlisted'),
('private', 'Private'),
('direct', 'Direct'))
@ -29,7 +30,8 @@ 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=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,
required=False)
media_file_1 = forms.FileField(label = "Media attachment 1",

View File

@ -131,3 +131,7 @@ SANITIZER_ALLOWED_ATTRIBUTES = ['href', 'src']
# File upload settings.
# Important: media will not work if you change this.
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'

View File

@ -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>

View File

@ -9,7 +9,7 @@
{% if form %}
<h1 class="title">Post</h1>
<div class="box">
{% include "main/post_partial.html" %}
{% include "main/post_minimal_partial.html" %}
</div>
<hr class="is-hidden">
{% endif %}

View File

@ -57,7 +57,7 @@ def timeline(request, timeline='home', timeline_name='Home', max_id=None, since_
except NotLoggedInException:
return redirect(login)
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:
prev = data[0]._pagination_prev
if len(mastodon.timeline(since_id=prev['since_id'])) == 0:
@ -153,7 +153,7 @@ def oauth_callback(request):
scopes=['read', 'write', 'follow'])
request.session['access_token'] = access_token
user = mastodon.account_verify_credentials()
request.session['user'] = user.acct
request.session['user'] = user
return redirect(home)
@ -207,7 +207,7 @@ def old_login(request):
account.save()
request.session['username'] = username
user = mastodon.account_verify_credentials()
request.session['user'] = user.acct
request.session['user'] = user
return redirect(home)
except:
@ -269,7 +269,7 @@ def settings(request):
@never_cache
def toot(request):
if request.method == 'GET':
form = PostForm()
form = PostForm(initial={'visibility': request.session['user'].source.privacy})
return render(request, 'main/post.html',
{'form': form,
'fullbrutalism': fullbrutalism_p(request)})
@ -288,6 +288,8 @@ def toot(request):
description=request.POST.get('media_text_'
+str(index),
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'],