Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
MOOC packages by hacklab
django-courses
Commits
40492ba6
Commit
40492ba6
authored
Oct 01, 2020
by
Matheus Miranda
Browse files
create command to generate_activities_actions
parent
ec8d0edd
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
0 deletions
+41
-0
courses/reports/management/__init__.py
courses/reports/management/__init__.py
+0
-0
courses/reports/management/commands/__init__.py
courses/reports/management/commands/__init__.py
+0
-0
courses/reports/management/commands/generate_activities_actions.py
...eports/management/commands/generate_activities_actions.py
+41
-0
No files found.
courses/reports/management/__init__.py
0 → 100644
View file @
40492ba6
courses/reports/management/commands/__init__.py
0 → 100644
View file @
40492ba6
courses/reports/management/commands/generate_activities_actions.py
0 → 100644
View file @
40492ba6
from
django.core.management.base
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'
@
transaction
.
atomic
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 answer.id 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
action_obj
.
save
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment