mirror of
http://git.carcosa.net/jmcbray/brutaldon.git
synced 2024-11-23 07:13:52 -05: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,
|
||||
|
@ -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
|
||||
if acct == username:
|
||||
return True
|
||||
try:
|
||||
user, host = username.split("@", 1)
|
||||
myhost = account.username.split("@",1)[1]
|
||||
if acct == user and host == myhost: return True
|
||||
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