Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store stage in the db #1407

Closed
wants to merge 9 commits into from
Closed

Store stage in the db #1407

wants to merge 9 commits into from

Conversation

fredkingham
Copy link
Contributor

depends on #1384

stores start/stop for stages.

@fredkingham fredkingham changed the title Store episode in the db Store stage in the db Mar 1, 2018
current_stage.updated_by = user
current_stage.save()

if stage_value:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of this if ?
Isn't it redundant b/c the .has_stage() call above?

)
raise ValueError(msg)
self.episode.stage = stage

current_stage = self.episode.stage_set.filter(stopped=None).last()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm slightly nervous about .last() here. There should never be two right ?

started = models.DateTimeField()
stopped = models.DateTimeField(blank=True, null=True)
value = models.CharField(max_length=256)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to have e.g. episode and stopped unique_together?
Will this prevent two stages for a single episode without an end date?

@@ -754,6 +754,12 @@ def category(self):
)[0]
return category(self)

@property
def stage(self):
s = self.stage_set.filter(stopped=None).last()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like I want this to be .get() and error if we can't set it as a constraint on the model...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we use last here because stage it not necessary set so I think this is ok.

opal/models.py Outdated
@@ -865,6 +871,15 @@ def _episode_history_to_dict(self, user):
episode_history = episodes_for_user(episode_history, user)
return [e.to_dict(user, shallow=True) for e in episode_history]

def update_from_dict(self, data, user, force=False, fields=None):
# stage is a related model so episode
# needs to have been saved before we can
Copy link
Member

@davidmiller davidmiller Mar 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment leaves out the last few words that would make it a complete

@davidmiller
Copy link
Member

I notice that there are no docs for this at all...

@fredkingham
Copy link
Contributor Author

@davidmiller so a bunch of changes.

Episodes can have 'no' stages and stages need to be explicitly set.

This is so we can work through different episode flows and sort them out individually.

Instead the current restrictions have been put in place.

  1. You cannot save an episode stage if another is already open.
  2. You cannot set an episode stage to None if the episode set has been previously set.

Change log and documentation have been updated accordingly. Let me know what you think.

opal/models.py Outdated
super(Stage, self).save(*args, **kwargs)
existing = Stage.objects.filter(episode=self.episode)
existing = existing.filter(stopped=None)
if existing.count() > 1:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're relying on transaction.atomic rolling it back and not saving ?
Does a unique_together constraint not work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we can do a unique_together in theory but its a bit of a fudge.

What we want

   unique_together = (('episode', 'value', 'stopped'),)

but really we 'd like

   unique_together = (('episode', 'value', 'stopped' != None),)

Although as they are datetime field they are probably the same thing... I thought this was was a bit nicer as its an explicit check

current_stage.updated_by = user
current_stage.save()

if current_stage and not stage_value:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment through the flow

@fredkingham
Copy link
Contributor Author

moving to v0.10.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants