Skip to content

Commit

Permalink
Fix missing test data for video logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Bach committed Dec 9, 2019
1 parent 1aff2dc commit eadd414
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def generate_fake_video_logs(facility_user=None, topics=topics, start_date=datet
latest_activity_timestamp=date_completed,
)
try:
vlog.save() # avoid userlog issues
vlog.save(generated_test_data=True) # avoid userlog issues
except Exception as e:
logging.error("Error saving video log: %s" % e)
continue
Expand Down
11 changes: 6 additions & 5 deletions kalite/main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def save(self, *args, **kwargs):
self.video_id = video.get("id",
self.youtube_id) if video else self.youtube_id # for unknown videos, default to the youtube_id

if not kwargs.get("imported", False):
if not kwargs.pop("generated_test_data", False) and not kwargs.get("imported", False):
self.full_clean()

try:
Expand Down Expand Up @@ -413,17 +413,18 @@ def update_user_activity(cls, user, activity_type="login", update_datetime=None,
if not user:
raise ValidationError("A valid user must always be specified.")
if not update_datetime: # must be done outside the function header (else becomes static)
# Set in the past
update_datetime = datetime.now()
activity_type = cls.get_activity_int(activity_type)

cur_log = cls.get_latest_open_log_or_None(user=user, activity_type=activity_type)
if cur_log:
# How could you start after you updated??
if cur_log.start_datetime > update_datetime:
raise ValidationError("Update time must always be later than the login time.")
if update_datetime < cur_log.start_datetime:
raise ValidationError("Update time must always be later than the latest open log. Open log: {} - Event time: {}".format(cur_log.start_datetime, update_datetime))
else:
# No unstopped starts. Start should have been called first!
logging.warn("%s: Had to create a user log entry on an UPDATE(%d)! @ %s" % (user.username, activity_type, update_datetime))
# logging.warn("%s: Had to create a user log entry on an UPDATE(%d)! @ %s" % (user.username, activity_type, update_datetime))
cur_log = cls.begin_user_activity(user=user, activity_type=activity_type, start_datetime=update_datetime, suppress_save=True)

logging.debug("%s: UPDATE activity (%d) @ %s" % (user.username, activity_type, update_datetime))
Expand Down Expand Up @@ -453,7 +454,7 @@ def end_user_activity(cls, user, activity_type="login", end_datetime=None, suppr
if cur_log:
# How could you start after you ended??
if cur_log.start_datetime > end_datetime:
raise ValidationError("Update time must always be later than the login time.")
raise ValidationError("End time must always be later than the start time.")
else:
# No unstopped starts. Start should have been called first!
logging.warn("%s: Had to BEGIN a user log entry, but ENDING(%d)! @ %s" % (user.username, activity_type, end_datetime))
Expand Down

0 comments on commit eadd414

Please sign in to comment.