Commit 40492ba6 authored by Matheus Miranda's avatar Matheus Miranda
Browse files

create command to generate_activities_actions

parent ec8d0edd
from import BaseCommand, CommandError
from django.contrib.auth import get_user_model
from django.db import transaction
from django.utils.timesince import timesince as djtimesince
from actstream import action
from actstream.models import user_stream, Action, actor_stream
from base64 import urlsafe_b64encode as ub64
from hashlib import sha1
from time import time
from courses_learning_objects.models import Answer, LearningObject
from discussion.models import Forum
User = get_user_model()
class Command(BaseCommand):
help = 'Create Actions objects for past activities'
def handle(self, *args, **options):
answered_actions_ids = Action.objects.filter(verb='answered').values_list('id', flat=True)
# Create any missing Answer action
for answer in Answer.objects.all():
activity_id = answer.activity_id
user = answer.user
verb = 'answered'
#if in answered_actions_ids:
# continue
timesince = djtimesince(answer.timestamp).encode('utf8').replace(b'\xc2\xa0', b' ').decode('utf8')
action_tuple = action.send(user, verb=verb, action_object=answer, target=answer.activity, timesince=timesince)
action_obj = action_tuple[0][1]
action_obj.timestamp = answer.timestamp
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment