mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
Updating counts for tagged stories.
This commit is contained in:
parent
1edf74b8f1
commit
2106446e15
2 changed files with 36 additions and 8 deletions
|
@ -29,7 +29,7 @@ from apps.analyzer.models import get_classifiers_for_user, sort_classifiers_by_f
|
|||
from apps.profile.models import Profile
|
||||
from apps.reader.models import UserSubscription, UserSubscriptionFolders, RUserStory, Feature
|
||||
from apps.reader.forms import SignupForm, LoginForm, FeatureForm
|
||||
from apps.rss_feeds.models import MFeedIcon
|
||||
from apps.rss_feeds.models import MFeedIcon, MStarredStoryCounts
|
||||
from apps.statistics.models import MStatistics
|
||||
# from apps.search.models import SearchStarredStory
|
||||
try:
|
||||
|
@ -257,7 +257,10 @@ def load_feeds(request):
|
|||
len(scheduled_feeds))
|
||||
ScheduleImmediateFetches.apply_async(kwargs=dict(feed_ids=scheduled_feeds))
|
||||
|
||||
starred_count = MStarredStory.objects(user_id=user.pk).count()
|
||||
starred_counts = MStarredStoryCounts.user_counts(user.pk)
|
||||
starred_count = starred_counts.get("", 0)
|
||||
if not starred_count and len(starred_counts.keys()):
|
||||
starred_count = MStarredStory.objects(user_id=user.pk).count()
|
||||
|
||||
social_params = {
|
||||
'user_id': user.pk,
|
||||
|
@ -282,6 +285,7 @@ def load_feeds(request):
|
|||
'social_services': social_services,
|
||||
'folders': json.decode(folders.folders),
|
||||
'starred_count': starred_count,
|
||||
'starred_counts': starred_counts,
|
||||
'categories': categories
|
||||
}
|
||||
return data
|
||||
|
@ -1647,7 +1651,6 @@ def mark_story_as_starred(request):
|
|||
user_id=story_values.pop('user_id'),
|
||||
defaults=story_values)
|
||||
if created:
|
||||
logging.user(request, "~FCStarring: ~SB%s (~FM~SB%s~FC~SN)" % (story.story_title[:32], starred_story.user_tags))
|
||||
MActivity.new_starred_story(user_id=request.user.pk,
|
||||
story_title=story.story_title,
|
||||
story_feed_id=feed_id,
|
||||
|
@ -1655,26 +1658,36 @@ def mark_story_as_starred(request):
|
|||
else:
|
||||
starred_story.user_tags = user_tags
|
||||
starred_story.save()
|
||||
|
||||
MStarredStoryCounts.count_tags_for_user(request.user.pk)
|
||||
starred_counts = MStarredStoryCounts.user_counts(request.user.pk)
|
||||
|
||||
if created:
|
||||
logging.user(request, "~FCStarring: ~SB%s (~FM~SB%s~FC~SN)" % (story.story_title[:32], starred_story.user_tags))
|
||||
else:
|
||||
logging.user(request, "~FCUpdating starred:~SN~FC ~SB%s~SN (~FM~SB%s~FC~SN)" % (story.story_title[:32], starred_story.user_tags))
|
||||
|
||||
return {'code': code, 'message': message}
|
||||
return {'code': code, 'message': message, 'starred_counts': starred_counts}
|
||||
|
||||
@ajax_login_required
|
||||
@json.json_view
|
||||
def mark_story_as_unstarred(request):
|
||||
code = 1
|
||||
story_id = request.POST['story_id']
|
||||
starred_counts = None
|
||||
|
||||
starred_story = MStarredStory.objects(user_id=request.user.pk, story_guid=story_id)
|
||||
if not starred_story:
|
||||
starred_story = MStarredStory.objects(user_id=request.user.pk, story_hash=story_id)
|
||||
if starred_story:
|
||||
logging.user(request, "~FCUnstarring: ~SB%s" % (starred_story[0].story_title[:50]))
|
||||
starred_story.delete()
|
||||
MStarredStoryCounts.count_tags_for_user(request.user.pk)
|
||||
starred_counts = MStarredStoryCounts.user_counts(request.user.pk)
|
||||
logging.user(request, "~FCUnstarring: ~SB%s" % (starred_story[0].story_title[:50]))
|
||||
else:
|
||||
code = -1
|
||||
|
||||
return {'code': code}
|
||||
return {'code': code, 'starred_counts': starred_counts}
|
||||
|
||||
@ajax_login_required
|
||||
@json.json_view
|
||||
|
|
|
@ -1965,6 +1965,16 @@ class MStarredStory(mongo.Document):
|
|||
stories = Feed.format_stories(stories_db)
|
||||
|
||||
return stories
|
||||
|
||||
@classmethod
|
||||
def find_stories_by_user_tag(cls, user_tag, user_id, offset=0, limit=25):
|
||||
stories_db = cls.objects(
|
||||
Q(user_id=user_id),
|
||||
Q(user_tags__icontains=user_tag)
|
||||
).order_by('-starred_date')[offset:offset+limit]
|
||||
stories = Feed.format_stories(stories_db)
|
||||
|
||||
return stories
|
||||
|
||||
@classmethod
|
||||
def trim_old_stories(cls, stories=10, days=30, dryrun=False):
|
||||
|
@ -2049,8 +2059,13 @@ class MStarredStoryCounts(mongo.Document):
|
|||
user_tags = sorted([(k, v) for k, v in all_tags.items() if int(v) > 0],
|
||||
key=itemgetter(1),
|
||||
reverse=True)
|
||||
for tag, count in user_tags.items():
|
||||
cls.objects(user_id=user_id, tag=tag).update_one(set__count=count, upsert=True)
|
||||
|
||||
cls.objects(user_id=user_id).delete()
|
||||
for tag, count in dict(user_tags).items():
|
||||
cls.objects.create(user_id=user_id, tag=tag, count=count)
|
||||
|
||||
total_stories_count = MStarredStory.objects(user_id=user_id).count()
|
||||
cls.objects(user_id=user_id, tag="", count=total_stories_count)
|
||||
|
||||
|
||||
class MFetchHistory(mongo.Document):
|
||||
|
|
Loading…
Add table
Reference in a new issue