add objective collection to timeline
This commit is contained in:
parent
5c773cde1b
commit
1a51d00cd4
5 changed files with 41 additions and 20 deletions
|
@ -181,3 +181,16 @@ div.jsoneditor-menu {
|
|||
vertical-align: middle;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
progress {
|
||||
border-radius: 7px;
|
||||
width: 80%;
|
||||
height: 10px;
|
||||
box-shadow: 1px 1px 4px rgba( 0, 0, 0, 0.2 );
|
||||
}
|
||||
::-webkit-progress-bar {
|
||||
background-color: #ccc;
|
||||
}
|
||||
::-webkit-progress-value {
|
||||
background-color: #00a1cc;
|
||||
}
|
||||
|
|
|
@ -47,20 +47,6 @@
|
|||
{% if user.featured_collections.all %}
|
||||
<div class="relation-dropdown__body">
|
||||
<div class="aside-section-wrapper aside-section-wrapper--transparent aside-section-wrapper--collapse">
|
||||
<style type="text/css">
|
||||
progress {
|
||||
border-radius: 7px;
|
||||
width: 80%;
|
||||
height: 10px;
|
||||
box-shadow: 1px 1px 4px rgba( 0, 0, 0, 0.2 );
|
||||
}
|
||||
::-webkit-progress-bar {
|
||||
background-color: #ccc;
|
||||
}
|
||||
::-webkit-progress-value {
|
||||
background-color: #00a1cc;
|
||||
}
|
||||
</style>
|
||||
<div class="user-relation">
|
||||
<h5 class="user-relation__label">
|
||||
{% trans '当前目标' %}
|
||||
|
|
|
@ -711,7 +711,9 @@ class Collection(List):
|
|||
if len(items) == 0:
|
||||
return 0
|
||||
shelf = user.shelf_manager.shelf_list["complete"]
|
||||
return shelf.members.all().filter(item_id__in=items).count() * 100 / len(items)
|
||||
return round(
|
||||
shelf.members.all().filter(item_id__in=items).count() * 100 / len(items)
|
||||
)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if getattr(self, "catalog_item", None) is None:
|
||||
|
@ -727,14 +729,22 @@ class Collection(List):
|
|||
super().save(*args, **kwargs)
|
||||
|
||||
|
||||
class FeaturedCollection(models.Model):
|
||||
class FeaturedCollection(Piece):
|
||||
owner = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
collection = models.ForeignKey(Collection, on_delete=models.CASCADE)
|
||||
target = models.ForeignKey(Collection, on_delete=models.CASCADE)
|
||||
created_time = models.DateTimeField(auto_now_add=True)
|
||||
edited_time = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
unique_together = [["owner", "collection"]]
|
||||
unique_together = [["owner", "target"]]
|
||||
|
||||
@property
|
||||
def visibility(self):
|
||||
return self.target.visibility
|
||||
|
||||
@cached_property
|
||||
def progress(self):
|
||||
return self.target.get_progress_for_user(self.owner)
|
||||
|
||||
|
||||
"""
|
||||
|
|
|
@ -221,7 +221,7 @@ def collection_add_featured(request, collection_uuid):
|
|||
collection = get_object_or_404(Collection, uid=base62.decode(collection_uuid))
|
||||
if not collection.is_visible_to(request.user):
|
||||
raise PermissionDenied()
|
||||
request.user.featured_collections.add(collection)
|
||||
FeaturedCollection.objects.update_or_create(owner=request.user, target=collection)
|
||||
return HttpResponseRedirect(request.META.get("HTTP_REFERER"))
|
||||
|
||||
|
||||
|
@ -231,7 +231,11 @@ def collection_remove_featured(request, collection_uuid):
|
|||
collection = get_object_or_404(Collection, uid=base62.decode(collection_uuid))
|
||||
if not collection.is_visible_to(request.user):
|
||||
raise PermissionDenied()
|
||||
request.user.featured_collections.remove(collection)
|
||||
fc = FeaturedCollection.objects.filter(
|
||||
owner=request.user, target=collection
|
||||
).first()
|
||||
if fc:
|
||||
fc.delete()
|
||||
return HttpResponseRedirect(request.META.get("HTTP_REFERER"))
|
||||
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ class ActivityTemplate(models.TextChoices):
|
|||
ReviewItem = "review_item"
|
||||
CreateCollection = "create_collection"
|
||||
LikeCollection = "like_collection"
|
||||
FeatureCollection = "feature_collection"
|
||||
|
||||
|
||||
class LocalActivity(models.Model, UserOwnedObjectMixin):
|
||||
|
@ -78,6 +79,7 @@ class DataSignalManager:
|
|||
@staticmethod
|
||||
def save_handler(sender, instance, created, **kwargs):
|
||||
processor_class = DataSignalManager.processors.get(instance.__class__)
|
||||
|
||||
if processor_class:
|
||||
processor = processor_class(instance)
|
||||
if created:
|
||||
|
@ -173,3 +175,9 @@ class LikeCollectionProcessor(DefaultActivityProcessor):
|
|||
def updated(self):
|
||||
if isinstance(self.action_object.target, Collection):
|
||||
super().update()
|
||||
|
||||
|
||||
@DataSignalManager.register
|
||||
class FeaturedCollectionProcessor(DefaultActivityProcessor):
|
||||
model = FeaturedCollection
|
||||
template = ActivityTemplate.FeatureCollection
|
||||
|
|
Loading…
Add table
Reference in a new issue