mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 11:31:08 +00:00
Runs black
This commit is contained in:
parent
ad43e5c83a
commit
3bdfc341e4
4 changed files with 40 additions and 24 deletions
|
@ -14,8 +14,8 @@ class Tombstone(ActivityObject):
|
||||||
type: str = "Tombstone"
|
type: str = "Tombstone"
|
||||||
|
|
||||||
def to_model(self, *args, **kwargs): # pylint: disable=unused-argument
|
def to_model(self, *args, **kwargs): # pylint: disable=unused-argument
|
||||||
''' this should never really get serialized, just searched for '''
|
""" this should never really get serialized, just searched for """
|
||||||
model = apps.get_model('bookwyrm.Status')
|
model = apps.get_model("bookwyrm.Status")
|
||||||
return model.find_existing_by_remote_id(self.id)
|
return model.find_existing_by_remote_id(self.id)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,44 +6,61 @@ from django.db.models import Q
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
from psycopg2.extras import execute_values
|
from psycopg2.extras import execute_values
|
||||||
|
|
||||||
|
|
||||||
def convert_review_rating(app_registry, schema_editor):
|
def convert_review_rating(app_registry, schema_editor):
|
||||||
''' take rating type Reviews and convert them to ReviewRatings '''
|
""" take rating type Reviews and convert them to ReviewRatings """
|
||||||
db_alias = schema_editor.connection.alias
|
db_alias = schema_editor.connection.alias
|
||||||
|
|
||||||
reviews = app_registry.get_model(
|
reviews = (
|
||||||
'bookwyrm', 'Review'
|
app_registry.get_model("bookwyrm", "Review")
|
||||||
).objects.using(db_alias).filter(
|
.objects.using(db_alias)
|
||||||
Q(content__isnull=True) | Q(content='')
|
.filter(Q(content__isnull=True) | Q(content=""))
|
||||||
)
|
)
|
||||||
|
|
||||||
with connection.cursor() as cursor:
|
with connection.cursor() as cursor:
|
||||||
values = [(r.id,) for r in reviews]
|
values = [(r.id,) for r in reviews]
|
||||||
execute_values(cursor, '''
|
execute_values(
|
||||||
|
cursor,
|
||||||
|
"""
|
||||||
INSERT INTO bookwyrm_reviewrating(review_ptr_id)
|
INSERT INTO bookwyrm_reviewrating(review_ptr_id)
|
||||||
VALUES %s''', values)
|
VALUES %s""",
|
||||||
|
values,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def unconvert_review_rating(app_registry, schema_editor):
|
def unconvert_review_rating(app_registry, schema_editor):
|
||||||
''' undo the conversion from ratings back to reviews'''
|
""" undo the conversion from ratings back to reviews"""
|
||||||
# All we need to do to revert this is drop the table, which Django will do
|
# All we need to do to revert this is drop the table, which Django will do
|
||||||
# on its own, as long as we have a valid reverse function. So, this is a
|
# on its own, as long as we have a valid reverse function. So, this is a
|
||||||
# no-op function so Django will do its thing
|
# no-op function so Django will do its thing
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('bookwyrm', '0045_auto_20210210_2114'),
|
("bookwyrm", "0045_auto_20210210_2114"),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='ReviewRating',
|
name="ReviewRating",
|
||||||
fields=[
|
fields=[
|
||||||
('review_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='bookwyrm.Review')),
|
(
|
||||||
|
"review_ptr",
|
||||||
|
models.OneToOneField(
|
||||||
|
auto_created=True,
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
parent_link=True,
|
||||||
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
to="bookwyrm.Review",
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
options={
|
options={
|
||||||
'abstract': False,
|
"abstract": False,
|
||||||
},
|
},
|
||||||
bases=('bookwyrm.review',),
|
bases=("bookwyrm.review",),
|
||||||
),
|
),
|
||||||
migrations.RunPython(convert_review_rating, unconvert_review_rating),
|
migrations.RunPython(convert_review_rating, unconvert_review_rating),
|
||||||
]
|
]
|
||||||
|
|
|
@ -6,9 +6,8 @@ from django.db import migrations
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('bookwyrm', '0046_reviewrating'),
|
("bookwyrm", "0046_reviewrating"),
|
||||||
('bookwyrm', '0046_sitesettings_privacy_policy'),
|
("bookwyrm", "0046_sitesettings_privacy_policy"),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = []
|
||||||
]
|
|
||||||
|
|
|
@ -295,11 +295,11 @@ class Review(Status):
|
||||||
|
|
||||||
|
|
||||||
class ReviewRating(Review):
|
class ReviewRating(Review):
|
||||||
''' a subtype of review that only contains a rating '''
|
""" a subtype of review that only contains a rating """
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
if not self.rating:
|
if not self.rating:
|
||||||
raise ValueError(
|
raise ValueError("ReviewRating object must include a numerical rating")
|
||||||
'ReviewRating object must include a numerical rating')
|
|
||||||
return super().save(*args, **kwargs)
|
return super().save(*args, **kwargs)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -307,7 +307,7 @@ class ReviewRating(Review):
|
||||||
return 'Rated "{}": {:d} stars'.format(self.book.title, self.rating)
|
return 'Rated "{}": {:d} stars'.format(self.book.title, self.rating)
|
||||||
|
|
||||||
activity_serializer = activitypub.Rating
|
activity_serializer = activitypub.Rating
|
||||||
pure_type = 'Note'
|
pure_type = "Note"
|
||||||
|
|
||||||
|
|
||||||
class Boost(ActivityMixin, Status):
|
class Boost(ActivityMixin, Status):
|
||||||
|
|
Loading…
Reference in a new issue