app/soc/modules/ghop/models/task.py
changeset 2703 7117c43ccf1b
parent 2679 0ede2f3adbc1
child 2788 78d02dcd8eb0
equal deleted inserted replaced
2702:028f6adffde7 2703:7117c43ccf1b
    35 import soc.models.role
    35 import soc.models.role
    36 import soc.models.student
    36 import soc.models.student
    37 import soc.models.user
    37 import soc.models.user
    38 
    38 
    39 import soc.modules.ghop.models.program
    39 import soc.modules.ghop.models.program
       
    40 
    40 
    41 
    41 class TaskTag(Tag):
    42 class TaskTag(Tag):
    42   """Model for storing all Task tags.
    43   """Model for storing all Task tags.
    43   """
    44   """
    44   
    45   
    47                                required=True,
    48                                required=True,
    48                                collection_name='task_type_tags')
    49                                collection_name='task_type_tags')
    49   
    50   
    50   @classmethod
    51   @classmethod
    51   def __key_name(cls, scope_path, tag_name):
    52   def __key_name(cls, scope_path, tag_name):
       
    53     """Create the key_name from program key_name as scope_path and tag_name.
       
    54     """
    52     return scope_path + '/' + tag_name
    55     return scope_path + '/' + tag_name
    53 
    56 
    54   @classmethod
    57   @classmethod
    55   def get_by_name(cls, tag_name):
    58   def get_by_name(cls, tag_name):
       
    59     """Get the list of tag objects that has the given tag_name.
       
    60     """
    56     tags = db.Query(cls).filter('tag =', tag_name).fetch(1000)
    61     tags = db.Query(cls).filter('tag =', tag_name).fetch(1000)
    57     return tags
    62     return tags
    58 
    63 
    59   @classmethod
    64   @classmethod
    60   def get_or_create(cls, program, tag_name):
    65   def get_or_create(cls, program, tag_name):
    61     "Get the Tag object that has the tag value given by tag_value."
    66     """Get the Tag object that has the tag value given by tag_value.
       
    67     """
    62     tag_key_name = cls.__key_name(program.key().name(), tag_name)
    68     tag_key_name = cls.__key_name(program.key().name(), tag_name)
    63     existing_tag = cls.get_by_key_name(tag_key_name)
    69     existing_tag = cls.get_by_key_name(tag_key_name)
    64     if existing_tag is None:
    70     if existing_tag is None:
    65       # The tag does not yet exist, so create it.
    71       # the tag does not yet exist, so create it.
    66       def create_tag_txn():
    72       def create_tag_txn():
    67         new_tag = cls(key_name=tag_key_name, tag=tag_name, scope=program)
    73         new_tag = cls(key_name=tag_key_name, tag=tag_name, scope=program)
    68         new_tag.put()
    74         new_tag.put()
    69         return new_tag
    75         return new_tag
    70       existing_tag = db.run_in_transaction(create_tag_txn)
    76       existing_tag = db.run_in_transaction(create_tag_txn)
    71     return existing_tag
    77     return existing_tag
    72 
    78 
       
    79 
    73 class TaskTypeTag(TaskTag):
    80 class TaskTypeTag(TaskTag):
    74   "Model for storing of task type tags."
    81   """Model for storing of task type tags.
       
    82   """
    75 
    83 
    76   pass
    84   pass
    77 
    85 
    78 
    86 
    79 class TaskDifficultyTag(TaskTag):
    87 class TaskDifficultyTag(TaskTag):
    80   "Model for storing of task difficulty level tags."
    88   """Model for storing of task difficulty level tags.
       
    89   """
    81 
    90 
    82   pass
    91   pass
    83 
    92 
    84 
    93 
    85 class GHOPTask(Taggable, soc.models.linkable.Linkable):
    94 class GHOPTask(Taggable, soc.models.linkable.Linkable):