Skip to content

Commit

Permalink
* Shots now have a new attribute called scenes, holding Scene ins…
Browse files Browse the repository at this point in the history
…tances. It

  is created to group same shots occurring in the same scenes.

* Added a new class called ``Scene`` to manage Shots with another property.
  • Loading branch information
eoyilmaz committed Mar 25, 2013
1 parent 0ee80ff commit c21c411
Show file tree
Hide file tree
Showing 15 changed files with 1,028 additions and 191 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG
Expand Up @@ -81,8 +81,8 @@ Stalker Changes
* Shots can now be created without a Sequence instance. The sequence
attribute is just used to group the Shots.

* Shots now have a new attribute called scenes, holding Scene instances. It
is created to group same shots occurring in the same scenes.
* Shots now have a new attribute called ``scenes``, holding Scene instances.
It is created to group same shots occurring in the same scenes.

* In tests all the Warnings are now properly handled as Warnings.

Expand All @@ -95,6 +95,8 @@ Stalker Changes
stalker.conf.defaults.TICKET_STATUS_ORDER for the order of the ticket
statuses.

* Added a new class called ``Scene`` to manage Shots with another property.

0.2.0.a6
--------

Expand Down
1 change: 1 addition & 0 deletions stalker/__init__.py
Expand Up @@ -27,6 +27,7 @@
from stalker.models.note import Note
from stalker.models.project import Project
from stalker.models.repository import Repository
from stalker.models.scene import Scene
from stalker.models.sequence import Sequence
from stalker.models.shot import Shot
from stalker.models.status import Status, StatusList
Expand Down
2 changes: 1 addition & 1 deletion stalker/db/__init__.py
Expand Up @@ -73,7 +73,7 @@ def __init_db__():
class_names = [
'Asset', 'Group', 'Permission', 'User', 'Department',
'SimpleEntity', 'Entity', 'ImageFormat', 'Link', 'Message', 'Note',
'Project', 'Repository', 'Sequence', 'Shot',
'Project', 'Repository', 'Scene', 'Sequence', 'Shot',
'Status', 'StatusList', 'Structure', 'Tag', 'Booking', 'Task',
'FilenameTemplate', 'Ticket', 'TicketLog', 'Type', 'Version',
]
Expand Down
31 changes: 19 additions & 12 deletions stalker/models/project.py
Expand Up @@ -358,20 +358,27 @@ def assets(self):
def sequences(self):
"""returns the sequences related to this project
"""
# use joins over the session.query
# sequences are tasks, use self.tasks
from stalker.models.sequence import Sequence

sequences = []
for task in self.tasks:
if isinstance(task, Sequence):
sequences.append(task)
return sequences

@property
def shots(self):
"""returns the shots related to this project
"""
# shots are tasks, use self.tasks
from stalker.models.shot import Shot

if DBSession is not None:
return Sequence.query\
.join(Sequence.project)\
.filter(Project.name == self.name)\
.all()
else:
warnings.warn("There is no database setup, the sequences can not "
"be queried from this state, please use "
"stalker.db.setup() to setup a database",
RuntimeWarning)
return []
shots = []
for task in self.tasks:
if isinstance(task, Shot):
shots.append(task)
return shots

def __eq__(self, other):
"""the equality operator
Expand Down
79 changes: 79 additions & 0 deletions stalker/models/scene.py
@@ -0,0 +1,79 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2009-2012, Erkan Ozgur Yilmaz
#
# This module is part of Stalker and is released under the BSD 2
# License: http://www.opensource.org/licenses/BSD-2-Clause

from sqlalchemy import Column, Integer, ForeignKey
from sqlalchemy.orm import relationship, validates
from stalker import User, Entity
from stalker.models.mixins import CodeMixin, ProjectMixin

from stalker.log import logging_level
import logging
logger = logging.getLogger(__name__)
logger.setLevel(logging_level)

class Scene(Entity, ProjectMixin, CodeMixin):
"""Stores data about Scenes.
Scenes are grouping the Shots according to their view to the world, that is
shots taking place in the same set configuration can be grouped together by
using Scenes.
You can not replace :class:`~stalker.models.sequence.Sequence`\ s with
Scenes, because Scene instances doesn't have some key features that
:class:`~stalker.models.sequence.Sequence`\ s have.
A Scene needs to be tied to a :class:`~stalker.models.project.Project`
instance, so it is not possible to create a Scene without a one.
"""

__project_doc__ = """The :class:`~stalker.models.project.Project` instance that this Sequence belongs to.
A :class:`~stalker.models.sequence.Sequence` can not be created without a
:class:`~stalker.models.project.Project` instance.
"""
__auto_name__ = False
__tablename__ = "Scenes"
__mapper_args__ = {"polymorphic_identity": "Scene"}
scene_id = Column("id", Integer, ForeignKey("Entities.id"),
primary_key=True)

shots = relationship(
"Shot",
secondary='Shot_Scenes',
back_populates="scenes",
doc="""The :class:`~stalker.models.shot.Shot`\ s that is related with this Scene.
It is a list of :class:`~stalker.models.shot.Shot` instances.
"""
)

def __init__(self, shots=None, **kwargs):
super(Scene, self).__init__(**kwargs)

# call the mixin __init__ methods
CodeMixin.__init__(self, **kwargs)
ProjectMixin.__init__(self, **kwargs)

if shots is None:
shots = []

self.shots = shots

@validates("shots")
def _validate_shots(self, key, shot):
"""validates the given shot value
"""
from stalker.models.shot import Shot
if not isinstance(shot, Shot):
raise TypeError('%s.shots needs to be all '
'stalker.models.shot.Shot instances, not %s' %
(self.__class__.__name__, shot.__class__.__name__))
return shot

def __eq__(self, other):
"""the equality operator
"""
return isinstance(other, Scene) and super(Scene, self).__eq__(other)
56 changes: 24 additions & 32 deletions stalker/models/sequence.py
Expand Up @@ -8,31 +8,30 @@
from sqlalchemy.orm import relationship, validates
from stalker import User
from stalker.models.task import Task
from stalker.models.mixins import (StatusMixin, ScheduleMixin, ReferenceMixin,
CodeMixin)
from stalker.models.mixins import (ReferenceMixin, CodeMixin)

from stalker.log import logging_level
import logging
logger = logging.getLogger(__name__)
logger.setLevel(logging_level)

class Sequence(Task, ReferenceMixin, StatusMixin, ScheduleMixin, CodeMixin):
class Sequence(Task, ReferenceMixin, CodeMixin):
"""Stores data about Sequences.
Sequences are holders of the :class:`~stalker.models.shot.Shot` objects.
They organize the conceptual data with another level of complexity.
Sequences are a way of grouping the Shots according to their temporal
position to each other.
The Sequence class updates the
:attr:`~stalker.models.project.Project.sequence` attribute in the
:class:`~stalker.models.project.Project` class when the Sequence is
initialized.
Initialization
--------------
A Sequence instance needs to be initialized with a
:class:`~stalker.models.project.Project` instance.
:param lead: The lead of this Sequence. The default value is None.
:type lead: :class:`~stalker.User`
"""

# __project_backref_attrname__ = "sequences_ossuruk"

__project_doc__ = """The :class:`~stalker.models.project.Project` instance that this Sequence belongs to.
A :class:`~stalker.models.sequence.Sequence` can not be created without a
Expand All @@ -59,24 +58,21 @@ class Sequence(Task, ReferenceMixin, StatusMixin, ScheduleMixin, CodeMixin):

shots = relationship(
"Shot",
primaryjoin="Shots.c.sequence_id==Sequences.c.id",
back_populates="_sequence",
secondary='Shot_Sequences',
back_populates="sequences",
doc="""The :class:`~stalker.models.shot.Shot`\ s assigned to this Sequence.
It is a list of :class:`~stalker.models.shot.Shot` instances.
"""
)

def __init__(self,
lead=None,
**kwargs
):
def __init__(self, lead=None, **kwargs):
super(Sequence, self).__init__(**kwargs)

# call the mixin __init__ methods
ReferenceMixin.__init__(self, **kwargs)
StatusMixin.__init__(self, **kwargs)
ScheduleMixin.__init__(self, **kwargs)
#StatusMixin.__init__(self, **kwargs)
#ScheduleMixin.__init__(self, **kwargs)
CodeMixin.__init__(self, **kwargs)

self.lead = lead
Expand All @@ -86,30 +82,26 @@ def __init__(self,
def _validate_lead(self, key, lead):
"""validates the given lead_in value
"""

if lead is not None:
if not isinstance(lead, User):
raise TypeError("lead should be instance of "
"stalker.models.user.User")

raise TypeError("%s.lead should be instance of "
"stalker.models.user.User, not %s" %
(self.__class__.__name__,
lead.__class__.__name__))
return lead

@validates("shots")
def _validate_shots(self, key, shot):
"""validates the given shot value
"""

from stalker.models.shot import Shot

if not isinstance(shot, Shot):
raise TypeError("every item in the shots list should be an "
"instance of stalker.models.shot.Shot")

raise TypeError('%s.shots should be all '
'stalker.models.shot.Shot instances, not %s')
return shot

def __eq__(self, other):
"""the equality operator
"""

return super(Sequence, self).__eq__(other) and\
isinstance(other, Sequence)
return isinstance(other, Sequence) and \
super(Sequence, self).__eq__(other)

0 comments on commit c21c411

Please sign in to comment.