Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a few edge case for mark.update() #394

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def sync_relay(self):
}
)
else:
logger.debug(f"Default relay is disabled.")
logger.info(f"Default relay is disabled.")
else:
if relay_follow:
logger.debug(
Expand Down
6 changes: 2 additions & 4 deletions journal/models/mark.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,12 @@ def update(
self.shelfmember.visibility = visibility
shelfmember_changed = True
# retract most recent post about this status when visibility changed
latest_post = self.shelfmember.latest_post
if latest_post:
Takahe.delete_posts([latest_post.pk])
if self.shelfmember.latest_post:
Takahe.delete_posts([self.shelfmember.latest_post.pk])
if created_time and created_time != self.shelfmember.created_time:
self.shelfmember.created_time = created_time
log_entry.timestamp = created_time
log_entry.save(update_fields=["timestamp"])
self.shelfmember.change_timestamp(created_time)
shelfmember_changed = True
if shelfmember_changed:
self.shelfmember.save()
Expand Down
10 changes: 9 additions & 1 deletion journal/models/shelf.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def ensure_log_entry(self):
return log

def log_and_delete(self):
ShelfLogEntry.objects.create(
ShelfLogEntry.objects.get_or_create(
owner=self.owner,
shelf_type=None,
item=self.item,
Expand Down Expand Up @@ -180,6 +180,14 @@ class ShelfLogEntry(models.Model):
"takahe.Post", related_name="log_entries", through="ShelfLogEntryPost"
)

class Meta:
constraints = [
models.UniqueConstraint(
fields=["owner", "item", "timestamp", "shelf_type"],
name="unique_shelf_log_entry",
),
]

def __str__(self):
return f"{self.owner}:{self.shelf_type}:{self.item.uuid}:{self.timestamp}"

Expand Down
9 changes: 8 additions & 1 deletion journal/views/mark.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,14 @@ def mark(request: AuthedHttpRequest, item_uuid):
)
mark_date = None
if request.POST.get("mark_anotherday"):
dt = parse_datetime(request.POST.get("mark_date", "") + " 20:00:00")
shelf_time_offset = {
ShelfType.WISHLIST: " 20:00:00",
ShelfType.PROGRESS: " 21:00:00",
ShelfType.COMPLETE: " 22:00:00",
}
dt = parse_datetime(
request.POST.get("mark_date", "") + shelf_time_offset[status]
)
mark_date = (
dt.replace(tzinfo=timezone.get_current_timezone()) if dt else None
)
Expand Down
2 changes: 1 addition & 1 deletion takahe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ def create_local(
post.emojis.set(emojis)
if published and published < timezone.now():
post.published = published
if timezone.now() - published > datetime.timedelta(days=2):
if timezone.now() - published > datetime.timedelta(days=9):
post.state = "fanned_out" # add post quietly if it's old
# if attachments:# FIXME
# post.attachments.set(attachments)
Expand Down