# Path: exe/engine/field.py
# class TextAreaField(FieldWithResources):
#     """
#     A Generic iDevice is built up of these fields.  Each field can be
#     rendered as an XHTML element
# 
#     Note that TextAreaFields can now hold any number of image resources,
#     which will typically be inserted by way of tinyMCE.
#     """
#     persistenceVersion = 1
# 
#     # these will be recreated in FieldWithResources' TwistedRePersist:
#     nonpersistant      = ['content', 'content_wo_resourcePaths']
# 
#     def __init__(self, name, instruc="", content=""):
#         """
#         Initialize 
#         """
#         FieldWithResources.__init__(self, name, instruc, content)
# 
#     def upgradeToVersion1(self):
#         """
#         Upgrades to somewhere before version 0.25 (post-v0.24) 
#         to reflect that TextAreaField now inherits from FieldWithResources,
#         and will need its corresponding fields populated from content.
#         """ 
#         self.content_w_resourcePaths = self.content 
#         self.content_wo_resourcePaths = self.content
#         # NOTE: we don't need to actually process any of those contents for 
#         # image paths, either, since this is an upgrade from pre-images!
# 
# class FeedbackField(FieldWithResources):
#     """
#     A Generic iDevice is built up of these fields.  Each field can be
#     rendered as an XHTML element
#     """
# 
#     persistenceVersion = 2
# 
#     # these will be recreated in FieldWithResources' TwistedRePersist:
#     nonpersistant      = ['content', 'content_wo_resourcePaths']
# 
#     def __init__(self, name, instruc=""):
#         """
#         Initialize 
#         """
#         FieldWithResources.__init__(self, name, instruc)
# 
#         self._buttonCaption = x_(u"Click Here")
# 
#         self.feedback      = ""
#         # Note: now that FeedbackField extends from FieldWithResources,
#         # the above feedback attribute will likely be used much less than
#         # the following new content attribute, but remains in case needed.
#         self.content      = ""
#     
#     # Properties
#     buttonCaption = lateTranslate('buttonCaption')
# 
#     def upgradeToVersion1(self):
#         """
#         Upgrades to version 0.14
#         """
#         self.buttonCaption = self.__dict__['buttonCaption']
# 
#     def upgradeToVersion2(self):
#         """
#         Upgrades to somewhere before version 0.25 (post-v0.24) 
#         to reflect that FeedbackField now inherits from FieldWithResources,
#         and will need its corresponding fields populated from content.
#         [see also the related (and likely redundant) upgrades to FeedbackField 
#          in: idevicestore.py's  __upgradeGeneric() for readingActivity, 
#          and: genericidevice.py's upgradeToVersion9() for the same]
#         """ 
#         self.content = self.feedback 
#         self.content_w_resourcePaths = self.feedback 
#         self.content_wo_resourcePaths = self.feedback
#         # NOTE: we don't need to actually process any of those contents for 
#         # image paths, either, since this is an upgrade from pre-images!


from exe.engine         import persist
from exe.engine.idevice import Idevice
from exe.engine.field   import TextAreaField, FeedbackField
from nevow.flat         import flatten
        from exe.engine.freetextidevice       import FreeTextIdevice
        from exe.engine.multimediaidevice     import MultimediaIdevice
        from exe.engine.reflectionidevice     import ReflectionIdevice
        from exe.engine.casestudyidevice      import CasestudyIdevice
        from exe.engine.truefalseidevice      import TrueFalseIdevice
        from exe.engine.wikipediaidevice      import WikipediaIdevice
        from exe.engine.attachmentidevice     import AttachmentIdevice
        from exe.engine.titleidevice          import TitleIdevice
        from exe.engine.galleryidevice        import GalleryIdevice
        from exe.engine.clozeidevice          import ClozeIdevice
        from exe.engine.flashwithtextidevice  import FlashWithTextIdevice        
        from exe.engine.externalurlidevice    import ExternalUrlIdevice
        from exe.engine.imagemagnifieridevice import ImageMagnifierIdevice
        from exe.engine.multichoiceidevice    import MultichoiceIdevice        
        from exe.engine.rssidevice            import RssIdevice 
        from exe.engine.multiselectidevice    import MultiSelectIdevice
        from exe.engine.appletidevice         import AppletIdevice
        from exe.engine.flashmovieidevice     import FlashMovieIdevice
        from exe.engine.quiztestidevice       import QuizTestIdevice
        from exe.engine.genericidevice import GenericIdevice
        from exe.engine.genericidevice import GenericIdevice
import imp
import sys
import logging
            self.__upgradeGeneric()
        else:
            self.__createGeneric()


        # generate new ids for these iDevices, to avoid any clashes
        for idevice in self.generic:
            idevice.id = self.getNewIdeviceId()

    def __upgradeGeneric(self):
        """
        Upgrades/removes obsolete generic idevices from before
        """
        # We may have two reading activites,
        # one problably has the wrong title, 
        # the other is redundant
        readingActivitiesFound = 0
        for idevice in self.generic:
            if idevice.class_ == 'reading':
                if readingActivitiesFound == 0:
                    # Rename the first one we find
                    idevice.title = x_(u"Reading Activity")
                    # and also upgrade its feedback field from using a simple
                    # string, to a subclass of TextAreaField.
                    # While this will have been initially handled by the
                    # field itself, and if not, then by the genericidevice's
                    # upgrade path, this is included here as a possibly
                    # painfully redundant safety check due to the extra
                    # special handing of generic idevices w/ generic.dat
                    for field in idevice.fields:

# Path: exe/engine/field.py
# class TextAreaField(FieldWithResources):
#     """
#     A Generic iDevice is built up of these fields.  Each field can be
#     rendered as an XHTML element
# 
#     Note that TextAreaFields can now hold any number of image resources,
#     which will typically be inserted by way of tinyMCE.
#     """
#     persistenceVersion = 1
# 
#     # these will be recreated in FieldWithResources' TwistedRePersist:
#     nonpersistant      = ['content', 'content_wo_resourcePaths']
# 
#     def __init__(self, name, instruc="", content=""):
#         """
#         Initialize 
#         """
#         FieldWithResources.__init__(self, name, instruc, content)
# 
#     def upgradeToVersion1(self):
#         """
#         Upgrades to somewhere before version 0.25 (post-v0.24) 
#         to reflect that TextAreaField now inherits from FieldWithResources,
#         and will need its corresponding fields populated from content.
#         """ 
#         self.content_w_resourcePaths = self.content 
#         self.content_wo_resourcePaths = self.content
#         # NOTE: we don't need to actually process any of those contents for 
#         # image paths, either, since this is an upgrade from pre-images!
# 
# class FeedbackField(FieldWithResources):
#     """
#     A Generic iDevice is built up of these fields.  Each field can be
#     rendered as an XHTML element
#     """
# 
#     persistenceVersion = 2
# 
#     # these will be recreated in FieldWithResources' TwistedRePersist:
#     nonpersistant      = ['content', 'content_wo_resourcePaths']
# 
#     def __init__(self, name, instruc=""):
#         """
#         Initialize 
#         """
#         FieldWithResources.__init__(self, name, instruc)
# 
#         self._buttonCaption = x_(u"Click Here")
# 
#         self.feedback      = ""
#         # Note: now that FeedbackField extends from FieldWithResources,
#         # the above feedback attribute will likely be used much less than
#         # the following new content attribute, but remains in case needed.
#         self.content      = ""
#     
#     # Properties
#     buttonCaption = lateTranslate('buttonCaption')
# 
#     def upgradeToVersion1(self):
#         """
#         Upgrades to version 0.14
#         """
#         self.buttonCaption = self.__dict__['buttonCaption']
# 
#     def upgradeToVersion2(self):
#         """
#         Upgrades to somewhere before version 0.25 (post-v0.24) 
#         to reflect that FeedbackField now inherits from FieldWithResources,
#         and will need its corresponding fields populated from content.
#         [see also the related (and likely redundant) upgrades to FeedbackField 
#          in: idevicestore.py's  __upgradeGeneric() for readingActivity, 
#          and: genericidevice.py's upgradeToVersion9() for the same]
#         """ 
#         self.content = self.feedback 
#         self.content_w_resourcePaths = self.feedback 
#         self.content_wo_resourcePaths = self.feedback
#         # NOTE: we don't need to actually process any of those contents for 
#         # image paths, either, since this is an upgrade from pre-images!


# Path: exe/engine/idevicestore.py
from exe.engine         import persist
from exe.engine.idevice import Idevice
from exe.engine.field   import TextAreaField, FeedbackField
from nevow.flat         import flatten
        from exe.engine.freetextidevice       import FreeTextIdevice
        from exe.engine.multimediaidevice     import MultimediaIdevice
        from exe.engine.reflectionidevice     import ReflectionIdevice
        from exe.engine.casestudyidevice      import CasestudyIdevice
        from exe.engine.truefalseidevice      import TrueFalseIdevice
        from exe.engine.wikipediaidevice      import WikipediaIdevice
        from exe.engine.attachmentidevice     import AttachmentIdevice
        from exe.engine.titleidevice          import TitleIdevice
        from exe.engine.galleryidevice        import GalleryIdevice
        from exe.engine.clozeidevice          import ClozeIdevice
        from exe.engine.flashwithtextidevice  import FlashWithTextIdevice        
        from exe.engine.externalurlidevice    import ExternalUrlIdevice
        from exe.engine.imagemagnifieridevice import ImageMagnifierIdevice
        from exe.engine.multichoiceidevice    import MultichoiceIdevice        
        from exe.engine.rssidevice            import RssIdevice 
        from exe.engine.multiselectidevice    import MultiSelectIdevice
        from exe.engine.appletidevice         import AppletIdevice
        from exe.engine.flashmovieidevice     import FlashMovieIdevice
        from exe.engine.quiztestidevice       import QuizTestIdevice
        from exe.engine.genericidevice import GenericIdevice
        from exe.engine.genericidevice import GenericIdevice
import imp
import sys
import logging

            self.__upgradeGeneric()
        else:
            self.__createGeneric()


        # generate new ids for these iDevices, to avoid any clashes
        for idevice in self.generic:
            idevice.id = self.getNewIdeviceId()

    def __upgradeGeneric(self):
        """
        Upgrades/removes obsolete generic idevices from before
        """
        # We may have two reading activites,
        # one problably has the wrong title, 
        # the other is redundant
        readingActivitiesFound = 0
        for idevice in self.generic:
            if idevice.class_ == 'reading':
                if readingActivitiesFound == 0:
                    # Rename the first one we find
                    idevice.title = x_(u"Reading Activity")
                    # and also upgrade its feedback field from using a simple
                    # string, to a subclass of TextAreaField.
                    # While this will have been initially handled by the
                    # field itself, and if not, then by the genericidevice's
                    # upgrade path, this is included here as a possibly
                    # painfully redundant safety check due to the extra
                    # special handing of generic idevices w/ generic.dat
                    for field in idevice.fields:

                        if isinstance(field, FeedbackField):