Example #1
0
class SVG(Image):

    class_id = 'image/svg+xml'
    class_title = MSG(u'Image SVG')

    # Fields
    data = File_Field(required=True, class_handler=SVGFile)
Example #2
0
class Gzip(File):
    class_id = 'application/x-gzip'
    class_title = MSG(u"Gzip")
    class_description = MSG(u'Gzip Compressed')
    class_icon16 = '/ui/ikaaro/icons/16x16/gzip.png'
    class_icon48 = '/ui/ikaaro/icons/48x48/gzip.png'
    # Fields
    data = File_Field(required=True, class_handler=GzipFile)
Example #3
0
class ODS(File):
    class_id = 'application/vnd.oasis.opendocument.spreadsheet'
    class_title = MSG(u'ODS')
    class_description = MSG(u'OpenDocument Spreadsheet')
    class_icon16 = '/ui/ikaaro/icons/16x16/ods.png'
    class_icon48 = '/ui/ikaaro/icons/48x48/ods.png'
    # Fields
    data = File_Field(required=True, class_handler=ODSFile)
Example #4
0
class ZipArchive(Archive):
    class_id = 'application/zip'
    class_title = MSG(u"Zip")
    class_description = MSG(u'Zip Archive')
    class_icon16 = '/ui/ikaaro/icons/16x16/zip.png'
    class_icon48 = '/ui/ikaaro/icons/48x48/zip.png'
    # Fields
    data = File_Field(required=True, class_handler=ZIPFile)
Example #5
0
class TarArchive(Archive):
    class_id = 'application/x-tar'
    class_title = MSG(u"Tar")
    class_description = MSG(u'Tar Archive')
    class_icon16 = '/ui/ikaaro/icons/16x16/tar.png'
    class_icon48 = '/ui/ikaaro/icons/48x48/tar.png'
    # Fields
    data = File_Field(required=True, class_handler=TARFile)
Example #6
0
class Python(Text):

    class_id = 'text/x-python'
    class_title = MSG(u'Python')
    class_icon16 = '/ui/ikaaro/icons/16x16/python.png'
    class_icon48 = '/ui/ikaaro/icons/48x48/python.png'
    # Fields
    data = File_Field(required=True, class_handler=PythonFile)
Example #7
0
class ODP(File):
    class_id = 'application/vnd.oasis.opendocument.presentation'
    class_title = MSG(u'ODP')
    class_description = MSG(u'OpenDocument Presentation')
    class_icon16 = '/ui/ikaaro/icons/16x16/odp.png'
    class_icon48 = '/ui/ikaaro/icons/48x48/odp.png'
    # Fields
    data = File_Field(required=True, class_handler=ODPFile)
Example #8
0
class PDF(File):
    class_id = 'application/pdf'
    class_title = MSG(u'PDF')
    class_description = MSG(u'PDF Document')
    class_icon16 = '/ui/ikaaro/icons/16x16/pdf.png'
    class_icon48 = '/ui/ikaaro/icons/48x48/pdf.png'
    # Fields
    data = File_Field(required=True, class_handler=PDFFile)
Example #9
0
class RTF(File):
    class_id = 'text/rtf'
    class_title = MSG(u"RTF")
    class_description = MSG(u'RTF Document')
    class_icon16 = '/ui/ikaaro/icons/16x16/text.png'
    class_icon48 = '/ui/ikaaro/icons/48x48/text.png'
    # Fields
    data = File_Field(required=True, class_handler=RTFFile)
Example #10
0
class Bzip2(File):
    class_id = 'application/x-bzip2'
    class_title = MSG(u"Bzip2")
    class_description = MSG(u'Bzip2 Compressed')
    class_icon16 = '/ui/ikaaro/icons/16x16/bzip.png'
    class_icon48 = '/ui/ikaaro/icons/48x48/bzip.png'
    # Fields
    data = File_Field(required=True, class_handler=Bzip2File)
Example #11
0
class OOImpress(File):
    class_id = 'application/vnd.sun.xml.impress'
    class_title = MSG(u'OOo Impress')
    class_description = MSG(u'OpenOffice.org Presentation')
    class_icon16 = '/ui/ikaaro/icons/16x16/ooimpress.png'
    class_icon48 = '/ui/ikaaro/icons/48x48/ooimpress.png'
    # Fields
    data = File_Field(required=True, class_handler=SXIFile)
Example #12
0
class OOCalc(File):

    class_id = 'application/vnd.sun.xml.calc'
    class_title = MSG(u'OOo Calc')
    class_description = MSG(u'OpenOffice.org Spreadsheet')
    class_icon16 = '/ui/ikaaro/icons/16x16/oocalc.png'
    class_icon48 = '/ui/ikaaro/icons/48x48/oocalc.png'
    # Fields
    data = File_Field(required=True, class_handler=SXCFile)
Example #13
0
class OOWriter(File):

    class_id = 'application/vnd.sun.xml.writer'
    class_title = MSG(u'OOo Writer')
    class_description = MSG(u'OpenOffice.org Text')
    class_icon16 = '/ui/ikaaro/icons/16x16/oowriter.png'
    class_icon48 = '/ui/ikaaro/icons/48x48/oowriter.png'

    # Fields
    data = File_Field(required=True, class_handler=SXWFile)
Example #14
0
class MSPowerPointX(File):

    class_id = MSPowerPointXFile.class_mimetypes[0]
    class_title = MSG(u'PowerPoint')
    class_description = MSG(u'PowerPoint Presentation')
    class_icon16 = '/ui/ikaaro/icons/16x16/powerpoint.png'
    class_icon48 = '/ui/ikaaro/icons/48x48/powerpoint.png'

    # Fields
    data = File_Field(required=True, class_handler=MSPowerPointXFile)
Example #15
0
class MSExcelX(File):

    class_id = MSExcelXFile.class_mimetypes[0]
    class_title = MSG(u'Excel')
    class_description = MSG(u'Excel Spreadsheet')
    class_icon16 = '/ui/ikaaro/icons/16x16/excel.png'
    class_icon48 = '/ui/ikaaro/icons/48x48/excel.png'

    # Fields
    data = File_Field(required=True, class_handler=MSExcelXFile)
Example #16
0
class MSWordX(File):

    class_id = MSWordXFile.class_mimetypes[0]
    class_title = MSG(u'Word')
    class_description = MSG(u'Word Text')
    class_icon16 = '/ui/ikaaro/icons/16x16/word.png'
    class_icon48 = '/ui/ikaaro/icons/48x48/word.png'

    # Fields
    data = File_Field(required=True, class_handler=MSWordXFile)
Example #17
0
class MSPowerPoint(File):

    class_id = 'application/vnd.ms-powerpoint'
    class_title = MSG(u'PowerPoint')
    class_description = MSG(u'PowerPoint Presentation')
    class_icon16 = '/ui/ikaaro/icons/16x16/powerpoint.png'
    class_icon48 = '/ui/ikaaro/icons/48x48/powerpoint.png'

    # Fields
    data = File_Field(required=True, class_handler=MSPowerPointFile)
Example #18
0
class MSExcel(File):

    class_id = 'application/vnd.ms-excel'
    class_title = MSG(u'Excel')
    class_description = MSG(u'Excel Spreadsheet')
    class_icon16 = '/ui/ikaaro/icons/16x16/excel.png'
    class_icon48 = '/ui/ikaaro/icons/48x48/excel.png'

    # Fields
    data = File_Field(required=True, class_handler=MSExcelFile)
Example #19
0
class MSWord(File):

    class_id = 'application/msword'
    class_title = MSG(u'Word')
    class_description = MSG(u'Word Text')
    class_icon16 = '/ui/ikaaro/icons/16x16/word.png'
    class_icon48 = '/ui/ikaaro/icons/48x48/word.png'

    # Fields
    data = File_Field(required=True, class_handler=MSWordFile)
Example #20
0
class CSS_Edit(Text_Edit):
    """Code editor view using the EditArea instead of a basic textarea or
    the WYSIWYG tinyMCE (that cannot directly edit source, as far as I known
    [Armel]). Mix CSS_Edit and HTMLEditView"""

    title = "Edit CSS file"

    data = File_Field(required=True,
                      class_handler=TextFile,
                      widget=EditAreaWidget)
Example #21
0
class Theme(Folder):

    class_id = 'config-theme'
    class_title = MSG(u'Theme')
    class_description = MSG(u'Allow to customize ikaaro skin')
    class_icon48 = 'icons/48x48/theme.png'

    # Fields
    logo = File_Field(title=MSG(u'Logo'))
    favicon = File_Field(title=MSG(u'Favicon'))
    banner = File_Field(title=MSG(u'Banner'))
    style = TextFile_Field(title=MSG(u'CSS Style'), class_handler=TextFile)

    def init_resource(self, **kw):
        super(Theme, self).init_resource(**kw)
        # Access
        self.set_value('share', 'everybody')
        # CSS file
        path = get_abspath('ui/themes/style.css')
        data = open(path).read()
        self.set_value('style', data)
        # Logo
        path = get_abspath('ui/themes/logo.png')
        data = open(path).read()
        self.set_value('logo', data)
        # Banner
        path = get_abspath('ui/themes/banner.jpg')
        data = open(path).read()
        self.set_value('banner', data)

    # Views
    class_views = [
        'edit', 'browse_content', 'preview_content', 'links', 'backlinks',
        'commit_log'
    ]

    edit = AutoEdit(fields=['favicon', 'logo', 'banner', 'style', 'share'])

    # Configuration
    config_name = 'theme'
    config_group = 'webmaster'
Example #22
0
class PO(Text):

    class_id = 'text/x-gettext-translation'
    class_title = MSG(u'Message Catalog')
    class_icon16 = '/ui/ikaaro/icons/16x16/po.png'
    class_icon48 = '/ui/ikaaro/icons/48x48/po.png'

    # Fields
    data = File_Field(required=True, class_handler=POFile)

    def get_po_handler(self):
        return self.get_value('data')

    # Views
    edit = PO_Edit()
Example #23
0
class Text(File):

    class_id = 'text'
    class_title = MSG(u'Plain Text')
    class_icon16 = '/ui/ikaaro/icons/16x16/text.png'
    class_icon48 = '/ui/ikaaro/icons/48x48/text.png'
    class_views = ['view', 'edit', 'externaledit', 'commit_log']
    # Fields
    data = File_Field(required=True,
                      class_handler=TextFile,
                      widget=MultilineWidget)

    def get_content_type(self):
        return '%s; charset=UTF-8' % super(Text, self).get_content_type()

    # Views
    view = Text_View()
    edit = Text_Edit()
Example #24
0
class Image(File):

    class_id = 'image'
    class_title = MSG(u'Image')
    class_icon16 = '/ui/ikaaro/icons/16x16/image.png'
    class_icon48 = '/ui/ikaaro/icons/48x48/image.png'
    class_views = [
        'view', 'download', 'edit', 'externaledit', 'remove', 'links',
        'backlinks', 'commit_log'
    ]
    # Fields
    data = File_Field(required=True, class_handler=ImageHandler)

    def get_max_width(self):
        # Auto-reduce width on init
        server = get_context().server
        if server is not None:
            return server.config.get_value('max-width')
        return None

    def get_max_height(self):
        # Auto-reduce height on init
        server = get_context().server
        if server is not None:
            return server.config.get_value('max-height')
        return None

    def init_resource(self, **kw):
        super(Image, self).init_resource(**kw)
        # Resize image at max size
        max_width = self.get_max_width()
        max_height = self.get_max_height()
        if max_width or max_height:
            handler = self.get_value('data')
            xsize, ysize = handler.get_size()
            thumb, format = handler.get_thumbnail(
                min(xsize, max_width or xsize), min(ysize, max_height
                                                    or ysize))
            handler.load_state_from_string(thumb)

    # Views
    thumb = DBResource_GetImage(field_name='data')
    view = Image_View()
Example #25
0
class CSV(Text):

    class_id = 'text/comma-separated-values'
    class_title = MSG(u'Comma Separated Values')
    class_views = ['view', 'add_row', 'edit', 'externaledit', 'commit_log']

    # Fields
    data = File_Field(required=True, class_handler=CSVFile, widget=FileWidget)

    def get_csv_handler(self):
        return self.get_value('data')

    def get_columns(self):
        """Returns a list of tuples with the name and title of every column.
        """
        handler = self.get_csv_handler()
        if handler.columns is None:
            row = None
            for row in handler.lines:
                if row is not None:
                    break
            if row is None:
                return []
            return [(str(x), str(x)) for x in range(len(row))]

        columns = []
        for name in handler.columns:
            datatype = handler.schema[name]
            title = getattr(datatype, 'title', None)
            if title is None:
                title = name
            else:
                title = title.gettext()
            columns.append((name, title))

        return columns

    # Views
    edit = File_Edit()
    view = CSV_View()
    add_row = CSV_AddRow()
    edit_row = CSV_EditRow()
Example #26
0
class HTML(Text):

    class_id = 'text/html'
    class_title = MSG(u'HTML File')
    # Fields
    data = File_Field(required=True, class_handler=HTMLFile)
Example #27
0
class XML(Text):

    class_id = 'text/xml'
    class_title = MSG(u'XML File')
    # Fields
    data = File_Field(required=True, class_handler=XMLFile)
Example #28
0
class User(DBResource):

    class_id = 'user'
    class_version = '20081217'
    class_title = MSG(u'User')
    class_icon16 = '/ui/ikaaro/icons/16x16/user.png'
    class_icon48 = '/ui/ikaaro/icons/48x48/user.png'
    class_views = [
        'profile', 'edit_account', 'edit_preferences', 'edit_password',
        'edit_groups'
    ]

    # Fields
    firstname = Text_Field(multilingual=False,
                           indexed=True,
                           stored=True,
                           title=MSG(u'First Name'))
    lastname = Text_Field(multilingual=False,
                          indexed=True,
                          stored=True,
                          title=MSG(u'Last Name'))
    email = UserEmail_Field
    password = Password_Field(multiple=True)
    avatar = File_Field(title=MSG(u'Avatar'))
    user_language = Char_Field
    user_timezone = Char_Field
    user_state = UserState_Field
    groups = UserGroups_Field
    username = Char_Field(indexed=True, stored=True)  # Backwards compatibility

    # Remove some fields
    title = None
    description = None
    subject = None
    text = None

    ########################################################################
    # Indexing
    ########################################################################
    def get_catalog_values(self):
        values = super(User, self).get_catalog_values()

        # email domain
        email = self.get_value('email')
        if email and '@' in email:
            values['email_domain'] = email.split('@', 1)[1]

        # username (overrides default)
        values['username'] = self.get_login_name()

        # groups
        values['groups'] = self.get_value('groups')

        return values

    ########################################################################
    # API / Authentication
    ########################################################################
    def get_user_id(self):
        # Used by itools.web
        return str(self.name)

    def get_password(self):
        password = self.get_property('password')
        return password[-1] if password else None

    def get_auth_token(self):
        # Used by itools.web
        password = self.get_password()
        return password.value if password else None

    def authenticate(self, password):
        my_password = self.get_password()
        if my_password is None:
            return False
        algo = my_password.get_parameter('algo', 'sha1')
        salt = my_password.get_parameter('salt', '')

        password_hashed, salt = get_secure_hash(password, algo, salt)
        return password_hashed == my_password.value

    def _login(self, password, context):
        # We call this method '_login' to avoid a name clash with the login
        # view.

        if not self.authenticate(password):
            error = MSG_LOGIN_WRONG_NAME_OR_PASSWORD
        elif self.get_value('user_state') == 'inactive':
            error = ERROR(
                u'Your account has been canceled, contact the administrator '
                u' if you want to get access again.')
        else:
            error = None
            context.login(self)

        # To activate this feature set the lastlog field
        lastlog = self.get_field('lastlog')
        if lastlog:
            success = error is None
            self.set_value('lastlog', context.timestamp, success=success)

        # Ok
        return error

    def update_pending_key(self):
        state = self.get_property('user_state')
        if state.value == 'pending':
            # TODO Implement expiration
            return state.get_parameter('key')

        key = generate_password(30)
        self.set_value('user_state', 'pending', key=key)
        return key

    ########################################################################
    # API
    ########################################################################
    def get_owner(self):
        return str(self.abspath)

    def get_title(self, language=None):
        firstname = self.get_value('firstname')
        lastname = self.get_value('lastname')
        if firstname:
            if lastname:
                return '%s %s' % (firstname, lastname)
            return firstname
        if lastname:
            return lastname
        return self.get_login_name().decode('utf-8')

    login_name_property = 'email'

    def get_login_name(self):
        return self.get_value(self.login_name_property)

    def get_timezone(self):
        return self.get_value('user_timezone')

    #######################################################################
    # Views
    #######################################################################
    resend_confirmation = User_ResendConfirmation
    confirm_registration = User_ConfirmRegistration
    change_password_forgotten = User_ChangePasswordForgotten
    profile = User_Profile
    edit_account = User_EditAccount
    edit_preferences = User_EditPreferences
    edit_password = User_EditPassword
    edit_groups = AutoEdit(access='is_admin',
                           fields=['groups'],
                           title=MSG(u'Edit groups'))
Example #29
0
class File(Content):

    class_id = 'file'
    class_version = '20090122'
    class_title = MSG(u'File')
    class_description = MSG(
        u'Upload office documents, images, media files, etc.')
    class_icon16 = '/ui/ikaaro/icons/16x16/file.png'
    class_icon48 = '/ui/ikaaro/icons/48x48/file.png'
    class_views = [
        'view', 'edit', 'externaledit', 'remove', 'subscribe', 'links',
        'backlinks', 'commit_log'
    ]

    # Fields
    data = File_Field(required=True, class_handler=FileHandler)
    filename = Char_Field
    owner = Owner_Field

    def get_all_extensions(self):
        format = self.metadata.format
        # FIXME This is a hack, compression encodings are not yet properly
        # supported (to do for the next major version).
        if format == 'application/x-gzip':
            extensions = ['gz', 'tgz']
        elif format == 'application/x-bzip2':
            extensions = ['bz2', 'tbz2']
        else:
            cls = self.data.class_handler
            extensions = [x[1:] for x in guess_all_extensions(format)]
            if cls.class_extension in extensions:
                extensions.remove(cls.class_extension)
            extensions.insert(0, cls.class_extension)
        return extensions

    #######################################################################
    # Versioning & Indexing
    #######################################################################
    def to_text(self):
        data = self.get_value('data')
        return data and data.to_text() or u''

    def get_files_to_archive(self, content=False):
        # Handlers
        files = [x.key for x in self.get_handlers()]
        # Metadata
        metadata = self.metadata.key
        files.append(metadata)
        return files

    #######################################################################
    # User Interface
    #######################################################################
    def get_content_type(self):
        return self.get_value('data').get_mimetype()

    # Views
    new_instance = File_NewInstance
    download = File_Download
    view = File_View
    edit = File_Edit
    externaledit = File_ExternalEdit_View
    external_edit = File_ExternalEdit