mirror of
https://gitlab.com/brutaldon/brutaldon.git
synced 2024-11-02 16:37:19 -04:00
Fix errors introduced in same_user, apply standard formatting
This commit is contained in:
parent
b1a2c7f57d
commit
fd5e4874c8
File diff suppressed because one or more lines are too long
@ -6,13 +6,15 @@ from django.db import migrations, models
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('brutaldon', '0024_auto_20200601_0945'),
|
||||
("brutaldon", "0024_auto_20200601_0945"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='preference',
|
||||
name='preview_sensitive',
|
||||
field=models.BooleanField(default=False, help_text='Show preview for media marked as "sensitive"'),
|
||||
model_name="preference",
|
||||
name="preview_sensitive",
|
||||
field=models.BooleanField(
|
||||
default=False, help_text='Show preview for media marked as "sensitive"'
|
||||
),
|
||||
),
|
||||
]
|
||||
|
@ -29,19 +29,26 @@ class Theme(models.Model):
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
from django.db.models.fields.related_descriptors import ForeignKeyDeferredAttribute
|
||||
|
||||
|
||||
def set_fields(klass):
|
||||
fields = []
|
||||
for n in dir(klass):
|
||||
assert n != "_fields"
|
||||
v = getattr(klass, n)
|
||||
if not hasattr(v, 'field'): continue
|
||||
if not isinstance(v.field, models.Field): continue
|
||||
if isinstance(v, ForeignKeyDeferredAttribute): continue
|
||||
if not hasattr(v, "field"):
|
||||
continue
|
||||
if not isinstance(v.field, models.Field):
|
||||
continue
|
||||
if isinstance(v, ForeignKeyDeferredAttribute):
|
||||
continue
|
||||
fields.append(n)
|
||||
setattr(klass, '_fields', fields)
|
||||
setattr(klass, "_fields", fields)
|
||||
return klass
|
||||
|
||||
|
||||
@set_fields
|
||||
class Preference(models.Model):
|
||||
theme = models.ForeignKey(Theme, models.CASCADE, null=False, default=1)
|
||||
@ -51,9 +58,8 @@ class Preference(models.Model):
|
||||
max_length=80, blank=True, null=True, choices=timezones, default="UTC"
|
||||
)
|
||||
preview_sensitive = models.BooleanField(
|
||||
default=False,
|
||||
help_text=_(
|
||||
'Show preview for media marked as "sensitive"'))
|
||||
default=False, help_text=_('Show preview for media marked as "sensitive"')
|
||||
)
|
||||
|
||||
no_javascript = models.BooleanField(
|
||||
default=False,
|
||||
|
@ -45,11 +45,11 @@ urlpatterns = [
|
||||
path("tags/<tag>", views.tag, name="tag"),
|
||||
path("user/", views.home, name="user_bad"),
|
||||
path("user/<username>", views.user, name="user"),
|
||||
# next/prev are integers, but pleroma uses 128 bit integers
|
||||
# ...encoded in Base62.
|
||||
# aka a "flake_id"
|
||||
# from baseconv import base62, but we don't need to decode it
|
||||
# just pass it along back to pleroma but it is NOT an <int:>
|
||||
# next/prev are integers, but pleroma uses 128 bit integers
|
||||
# ...encoded in Base62.
|
||||
# aka a "flake_id"
|
||||
# from baseconv import base62, but we don't need to decode it
|
||||
# just pass it along back to pleroma but it is NOT an <int:>
|
||||
path("user/<username>/next/<next>", views.user, name="user_next"),
|
||||
path("user/<username>/prev/<prev>", views.user, name="user_prev"),
|
||||
path("toot/<mention>", views.toot, name="toot"),
|
||||
|
@ -91,7 +91,7 @@ def get_usercontext(request, feature_set="mainline"):
|
||||
api_base_url=client.api_base_id,
|
||||
session=get_session(client.api_base_id),
|
||||
ratelimit_method="throw",
|
||||
feature_set=feature_set
|
||||
feature_set=feature_set,
|
||||
)
|
||||
return user, mastodon
|
||||
else:
|
||||
@ -144,6 +144,7 @@ def br_login_required(function=None, home_url=None, redirect_field_name=None):
|
||||
if not url:
|
||||
url = "/"
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
if not is_logged_in(request):
|
||||
return not_logged_in()
|
||||
else:
|
||||
@ -616,7 +617,8 @@ def note(request, next=None, prev=None):
|
||||
return redirect(about)
|
||||
try:
|
||||
last_seen = mastodon.notifications(limit=1)[0]
|
||||
except IndexError: pass
|
||||
except IndexError:
|
||||
pass
|
||||
else:
|
||||
account.note_seen = last_seen.id
|
||||
account.save()
|
||||
@ -652,6 +654,7 @@ def note(request, next=None, prev=None):
|
||||
return str(note.status.id) + note.type
|
||||
except:
|
||||
return str(note.id) + note.type
|
||||
|
||||
def group_sort_key(group):
|
||||
return max([k.id for k in group])
|
||||
|
||||
@ -716,13 +719,20 @@ def thread(request, id):
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def same_username(account, acct, username):
|
||||
if acct == username: return True
|
||||
user, host = username.split("@", 1)
|
||||
myhost = account.username.split("@",1)[1]
|
||||
if acct == user and host == myhost: return True
|
||||
if acct == username:
|
||||
return True
|
||||
try:
|
||||
user, host = username.split("@", 1)
|
||||
except ValueError:
|
||||
user, host = username, ""
|
||||
myhost = account.username.split("@", 1)[1]
|
||||
if acct == user and host == myhost:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
@br_login_required
|
||||
def user(request, username, prev=None, next=None):
|
||||
try:
|
||||
@ -735,13 +745,14 @@ def user(request, username, prev=None, next=None):
|
||||
# but until then, we might have to fallback to a regular search,
|
||||
# if the account search fails to return results.
|
||||
for dict in mastodon.account_search(username):
|
||||
if not same_username(account, dict.acct, username): continue
|
||||
if not same_username(account, dict.acct, username):
|
||||
continue
|
||||
user_dict = dict
|
||||
break
|
||||
else:
|
||||
for dict in mastodon.search(username,
|
||||
result_type="accounts").accounts:
|
||||
if not same_username(account, dict.acct, username): continue
|
||||
for dict in mastodon.search(username, result_type="accounts").accounts:
|
||||
if not same_username(account, dict.acct, username):
|
||||
continue
|
||||
user_dict = dict
|
||||
break
|
||||
else:
|
||||
@ -790,8 +801,7 @@ def settings(request):
|
||||
if form.is_valid():
|
||||
for field in account.preferences._fields:
|
||||
if field in form.cleaned_data:
|
||||
setattr(account.preferences, field,
|
||||
form.cleaned_data[field])
|
||||
setattr(account.preferences, field, form.cleaned_data[field])
|
||||
request.session["timezone"] = account.preferences.timezone
|
||||
account.preferences.save()
|
||||
account.save()
|
||||
@ -818,17 +828,17 @@ def settings(request):
|
||||
{"form": form, "account": account, "preferences": account.preferences},
|
||||
)
|
||||
|
||||
|
||||
def status_post(account, request, mastodon, **kw):
|
||||
while True:
|
||||
try:
|
||||
mastodon.status_post(**kw)
|
||||
except MastodonIllegalArgumentError as e:
|
||||
if not 'is only available with feature set' in e.args[0]:
|
||||
if not "is only available with feature set" in e.args[0]:
|
||||
raise
|
||||
feature_set = e.args[0].rsplit(" ",1)[-1]
|
||||
feature_set = e.args[0].rsplit(" ", 1)[-1]
|
||||
|
||||
account, mastodon = get_usercontext(request,
|
||||
feature_set=feature_set)
|
||||
account, mastodon = get_usercontext(request, feature_set=feature_set)
|
||||
|
||||
continue
|
||||
except TypeError:
|
||||
@ -840,6 +850,7 @@ def status_post(account, request, mastodon, **kw):
|
||||
break
|
||||
return account, mastodon
|
||||
|
||||
|
||||
@never_cache
|
||||
@br_login_required
|
||||
def toot(request, mention=None):
|
||||
@ -902,12 +913,15 @@ def toot(request, mention=None):
|
||||
].source.privacy
|
||||
try:
|
||||
status_post(
|
||||
account, request, mastodon,
|
||||
account,
|
||||
request,
|
||||
mastodon,
|
||||
status=form.cleaned_data["status"],
|
||||
visibility=form.cleaned_data["visibility"],
|
||||
spoiler_text=form.cleaned_data["spoiler_text"],
|
||||
media_ids=media_objects,
|
||||
content_type="text/markdown")
|
||||
content_type="text/markdown",
|
||||
)
|
||||
except MastodonAPIError as error:
|
||||
form.add_error(
|
||||
"",
|
||||
@ -1002,7 +1016,9 @@ def redraft(request, id):
|
||||
].source.privacy
|
||||
try:
|
||||
status_post(
|
||||
account, request, mastodon,
|
||||
account,
|
||||
request,
|
||||
mastodon,
|
||||
status=form.cleaned_data["status"],
|
||||
visibility=form.cleaned_data["visibility"],
|
||||
spoiler_text=form.cleaned_data["spoiler_text"],
|
||||
@ -1127,7 +1143,9 @@ def reply(request, id):
|
||||
)
|
||||
try:
|
||||
status_post(
|
||||
account, request, mastodon,
|
||||
account,
|
||||
request,
|
||||
mastodon,
|
||||
status=form.cleaned_data["status"],
|
||||
visibility=form.cleaned_data["visibility"],
|
||||
spoiler_text=form.cleaned_data["spoiler_text"],
|
||||
|
Loading…
Reference in New Issue
Block a user