diff --git a/kalite/coachreports/management/commands/generaterealdata.py b/kalite/coachreports/management/commands/generaterealdata.py index b97939a9a5..de1b20c817 100644 --- a/kalite/coachreports/management/commands/generaterealdata.py +++ b/kalite/coachreports/management/commands/generaterealdata.py @@ -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 diff --git a/kalite/main/models.py b/kalite/main/models.py index 309e395029..b03a693def 100755 --- a/kalite/main/models.py +++ b/kalite/main/models.py @@ -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: @@ -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)) @@ -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)) diff --git a/kalite/topic_tools/content_models.py b/kalite/topic_tools/content_models.py index 0fddd5e6f7..2c16eb5690 100644 --- a/kalite/topic_tools/content_models.py +++ b/kalite/topic_tools/content_models.py @@ -135,7 +135,7 @@ def wrapper(*args, **kwargs): except OperationalError as e: logging.error( - "Content DB error: Perhaps content database file found? " + "Content DB error: Perhaps content database file not found? " "Exception: {e}".format(e=str(e)) ) raise