Fixing various mongo data calls.

This commit is contained in:
Samuel Clay 2020-06-29 20:17:00 -04:00
parent 3fa55aff17
commit db665fa4a3
3 changed files with 22 additions and 13 deletions

View file

@ -1,6 +1,7 @@
#add homepage user from settings #add homepage user from settings
#add popular user #add popular user
from settings import HOMEPAGE_USERNAME import datetime
from django.conf import settings
from apps.profile.models import create_profile from apps.profile.models import create_profile
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
@ -8,7 +9,15 @@ from django.core.management.base import BaseCommand
class Command(BaseCommand): class Command(BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
instance = User.objects.create(username=HOMEPAGE_USERNAME) def _create(username):
instance.save() try:
create_profile(None, instance, None) User.objects.get(username=username)
print("User {0} created".format(HOMEPAGE_USERNAME)) print("User {0} exists".format(username))
except User.DoesNotExist:
instance = User.objects.create(username=username, last_login=datetime.datetime.now())
instance.save()
create_profile(None, instance, None)
print("User {0} created".format(username))
_create(settings.HOMEPAGE_USERNAME)
_create('popular')

View file

@ -9,7 +9,7 @@ class PostToService(Task):
def run(self, shared_story_id, service): def run(self, shared_story_id, service):
try: try:
shared_story = MSharedStory.objects.get(id=shared_story_id) shared_story = MSharedStory.objects.get(id=ObjectId(shared_story_id))
shared_story.post_to_service(service) shared_story.post_to_service(service)
except MSharedStory.DoesNotExist: except MSharedStory.DoesNotExist:
logging.debug(" ---> Shared story not found (%s). Can't post to: %s" % (shared_story_id, service)) logging.debug(" ---> Shared story not found (%s). Can't post to: %s" % (shared_story_id, service))
@ -35,13 +35,13 @@ class EmailFirstShare(Task):
class EmailCommentReplies(Task): class EmailCommentReplies(Task):
def run(self, shared_story_id, reply_id): def run(self, shared_story_id, reply_id):
shared_story = MSharedStory.objects.get(id=shared_story_id) shared_story = MSharedStory.objects.get(id=ObjectId(shared_story_id))
shared_story.send_emails_for_new_reply(reply_id) shared_story.send_emails_for_new_reply(ObjectId(reply_id))
class EmailStoryReshares(Task): class EmailStoryReshares(Task):
def run(self, shared_story_id): def run(self, shared_story_id):
shared_story = MSharedStory.objects.get(id=shared_story_id) shared_story = MSharedStory.objects.get(id=ObjectId(shared_story_id))
shared_story.send_email_for_reshare() shared_story.send_email_for_reshare()
class SyncTwitterFriends(Task): class SyncTwitterFriends(Task):

View file

@ -659,10 +659,10 @@ def mark_story_as_shared(request):
if post_to_services: if post_to_services:
for service in post_to_services: for service in post_to_services:
if service not in shared_story.posted_to_services: if service not in shared_story.posted_to_services:
PostToService.delay(shared_story_id=shared_story.id, service=service) PostToService.delay(shared_story_id=str(shared_story.id), service=service)
if shared_story.source_user_id and shared_story.comments: if shared_story.source_user_id and shared_story.comments:
EmailStoryReshares.apply_async(kwargs=dict(shared_story_id=shared_story.id), EmailStoryReshares.apply_async(kwargs=dict(shared_story_id=str(shared_story.id)),
countdown=settings.SECONDS_TO_DELAY_CELERY_EMAILS) countdown=settings.SECONDS_TO_DELAY_CELERY_EMAILS)
EmailFirstShare.apply_async(kwargs=dict(user_id=request.user.pk)) EmailFirstShare.apply_async(kwargs=dict(user_id=request.user.pk))
@ -812,8 +812,8 @@ def save_comment_reply(request):
story_feed_id=feed_id, story_feed_id=feed_id,
story_title=shared_story.story_title) story_title=shared_story.story_title)
EmailCommentReplies.apply_async(kwargs=dict(shared_story_id=shared_story.id, EmailCommentReplies.apply_async(kwargs=dict(shared_story_id=str(shared_story.id),
reply_id=reply.reply_id), reply_id=str(reply.reply_id)),
countdown=settings.SECONDS_TO_DELAY_CELERY_EMAILS) countdown=settings.SECONDS_TO_DELAY_CELERY_EMAILS)
if format == 'html': if format == 'html':