Add share view

This commit is contained in:
Jason McBrayer 2019-11-07 13:32:51 -05:00
parent c836861027
commit da1de5ea32
2 changed files with 41 additions and 1 deletions

View File

@ -69,5 +69,6 @@ urlpatterns = [
path("accounts/", views.accounts, name="accounts"),
path("accounts/<id>", views.accounts, name="accounts"),
path("vote/<id>", views.vote, name="vote"),
path("share/", views.share, name="share"),
path("", views.home, name=""),
]

View File

@ -33,20 +33,26 @@ import re
class NotLoggedInException(Exception):
pass
class LabeledList(list):
"""A subclass of list that can accept additional attributes"""
def __new__(self, *args, **kwargs):
return super(LabeledList, self).__new__(self, args, kwargs)
def __init(self, *args, **kwargs):
if len(args) == 1 and hasattr(args[0], '__iter__'):
if len(args) == 1 and hasattr(args[0], "__iter__"):
list.__init__(self, args[0])
else:
list.__init__(self, args)
self.__dict__.update(kwargs)
def __call(self, **kwargs):
self.__dict__.update(kwargs)
return self
global sessons_cache
sessions_cache = {}
@ -629,8 +635,10 @@ def note(request, next=None, prev=None):
# Now group notes into lists based on type and status
groups = []
if account.preferences.bundle_notifications:
def bundle_key(note):
return str(note.status.id) + note.type
sorted_notes = sorted(notes, key=bundle_key, reverse=True)
for _, group in groupby(sorted_notes, bundle_key):
group = LabeledList(group)
@ -1154,6 +1162,37 @@ def reply(request, id):
return HttpResponseRedirect(reverse("reply", args=[id]) + "#toot-" + str(id))
@br_login_required
def share(request):
account, mastodon = get_usercontext(request)
if request.method == "GET":
params = request.GET
if request.method == "POST":
params = request.POST
title = params.get("title")
url = params.get("url")
if title:
initial_text = f"{title}\n\n{url}"
else:
initial_text = f"{url}"
form = PostForm(
initial={
"status": initial_text,
"visibility": request.session["active_user"].source.privacy,
}
)
return render(
request,
"main/post.html",
{
"form": form,
"own_acct": request.session["active_user"],
"preferences": account.preferences,
},
)
@never_cache
@br_login_required
def fav(request, id):