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 issue #411

Merged
merged 5 commits into from
Dec 2, 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
36 changes: 35 additions & 1 deletion catalog/templates/edition.html
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ <h5>目录</h5>
<div>
<a target="_blank"
rel="noopener"
href="https://library.oapen.org/discover?filtertype_1=isbn&filter_relational_operator_1=equals&filter_1={{ item.isbn }}">
href="https://library.oapen.org/discover?filtertype_1=isbn&amp;filter_relational_operator_1=equals&amp;filter_1={{ item.isbn }}">
OAPEN</a>
</div>
<div>
Expand All @@ -160,11 +160,45 @@ <h5>目录</h5>
<a target="_blank"
rel="noopener"
href="https://www.amazon.com/s?k={{ item.isbn }}">Amazon</a>
<a target="_blank"
rel="noopener"
href="https://www.amazon.de/s?k={{ item.isbn }}">DE</a>
<a target="_blank"
rel="noopener"
href="https://www.amazon.co.jp/s?k={{ item.isbn }}">JP</a>
<a target="_blank"
rel="noopener"
href="https://www.amazon.co.uk/s?k={{ item.isbn }}">UK</a>
</div>
<div>
<a target="_blank"
rel="noopener"
href="https://www.kobo.com/search?query={{ item.isbn }}">Kobo</a>
<a target="_blank"
rel="noopener"
href="https://www.kobo.com/jp/en/search?query={{ item.isbn }}">JP</a>
<a target="_blank"
rel="noopener"
href="https://www.kobo.com/tw/zh/search?query={{ item.isbn }}">TW</a>
<a target="_blank"
rel="noopener"
href="https://www.kobo.com/us/en/search?query={{ item.isbn }}">US</a>
</div>
<div>
<a target="_blank"
rel="noopener"
href="https://www.duozhuayu.com/search/book/{{ item.isbn }}">多抓鱼</a>
<a target="_blank"
rel="noopener"
href="https://search.kongfz.com/product_result/?key={{ item.isbn }}">孔夫子旧书</a>
</div>
<div>
<a target="_blank"
rel="noopener"
href="https://search.books.com.tw/search/query/key/{{ item.isbn }}/cat/all">博客来</a>
<a target="_blank"
rel="noopener"
href="https://readmoo.com/search/keyword?q={{ item.isbn }}">Readmoo 讀墨</a>
</div>
</div>
</details>
Expand Down
2 changes: 1 addition & 1 deletion journal/models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def q_owned_piece_visible_to_user(viewing_user: User, owner: APIdentity):
return Q(visibility=0)
viewer = viewing_user.identity
if viewer == owner:
return Q()
return Q(owner=owner)
# elif viewer.is_blocked_by(owner):
# return Q(pk__in=[])
elif viewer.is_following(owner):
Expand Down
8 changes: 3 additions & 5 deletions journal/views/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,16 @@ def render_list(
request: AuthedHttpRequest,
user_name,
type,
shelf_type=None,
shelf_type: ShelfType | None = None,
item_category=None,
tag_title=None,
year=None,
):
target = request.target_identity
viewer = request.user.identity
tag = None
if type == "mark":
queryset = target.user.shelf_manager.get_latest_members(
shelf_type, item_category
)
if type == "mark" and shelf_type:
queryset = target.shelf_manager.get_latest_members(shelf_type, item_category)
elif type == "tagmember":
tag = Tag.objects.filter(owner=target, title=tag_title).first()
if not tag:
Expand Down
6 changes: 4 additions & 2 deletions journal/views/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ def profile(request: AuthedHttpRequest, user_name):
"count": members.count(),
"members": members[:10].prefetch_related("item"),
}
reviews = Review.objects.filter(q_item_in_category(category)).order_by(
"-created_time"
reviews = (
Review.objects.filter(q_item_in_category(category))
.filter(qv)
.order_by("-created_time")
)
shelf_list[category]["reviewed"] = {
"title": "评论过的" + category.label,
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ djlint~=1.34.0
isort~=5.12.0
lxml-stubs
pre-commit
pyright==1.1.336
pyright==1.1.338
6 changes: 5 additions & 1 deletion takahe/management/commands/backfill_takahe.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import datetime, timezone

from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.core.management.base import BaseCommand
Expand All @@ -19,6 +21,8 @@

BATCH_SIZE = 1000

TIMELINE_START = datetime.datetime(2023, 7, 1, tzinfo=timezone.utc)


def content_type_id(cls):
return ContentType.objects.get(app_label="journal", model=cls.__name__.lower()).pk
Expand Down Expand Up @@ -115,7 +119,7 @@ def add_event(post_id, author_id, owner_id, published):
published=post.published,
)
)
if post.visibility != 3:
if post.visibility != 3 and post.published > TIMELINE_START:
for follower_id in followers[post.author_id]:
events.append(
TimelineEvent(
Expand Down
13 changes: 13 additions & 0 deletions takahe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,19 @@ def generate_keypair(self):
self.public_key_id = self.actor_uri + "#main-key"
self.save()

def ensure_uris(self):
"""
Ensures that local identities have all the URIs populated on their fields
(this lets us add new ones easily)
"""
if self.local:
self.inbox_uri = self.actor_uri + "inbox/"
self.outbox_uri = self.actor_uri + "outbox/"
self.featured_collection_uri = self.actor_uri + "collections/featured/"
self.followers_uri = self.actor_uri + "followers/"
self.following_uri = self.actor_uri + "following/"
self.shared_inbox_uri = f"https://{self.domain.uri_domain}/inbox/"


class Follow(models.Model):
"""
Expand Down
1 change: 1 addition & 0 deletions takahe/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def init_identity_for_local_user(u: "NeoUser"):
discoverable=not u.preference.no_anonymous_view,
)
identity.generate_keypair()
identity.ensure_uris()
if not user.identities.filter(pk=identity.pk).exists():
user.identities.add(identity)
apidentity = APIdentity.objects.filter(pk=identity.pk).first()
Expand Down
2 changes: 2 additions & 0 deletions users/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ def identity_linked(self):
return APIdentity.objects.filter(user=self).exists()

def initialize(self):
if not self.username:
raise ValueError("Username is not set")
Takahe.init_identity_for_local_user(self)
self.identity.shelf_manager

Expand Down