コード例 #1
0
ファイル: views.py プロジェクト: hforge/itws
    def action(self, resource, context, form):
        # Get the container
        container = resource
        name = self.get_new_resource_name(form)

        # Make the resource
        cls = get_resource_class(self.add_cls.class_id)
        child = container.make_resource(name, cls)
        # Set properies
        resource_schema = self.add_cls.class_schema
        for key in self.get_schema(resource, context):
            datatype = resource_schema[key]
            if getattr(datatype, 'multilingual', False) is True:
                language = container.get_edit_languages(context)[0]
                value = Property(form[key], lang=language)
            else:
                value = form[key]
            child.metadata.set_property(key, value)
        # Other set properties
        self.post_action(resource, child, context, form)
        # Ok
        if self.goto_come_back is True:
            goto = None
        else:
            goto = str(resource.get_pathto(child))
            if self.goto_view:
                goto = '%s/;%s' % (goto, self.goto_view)
        return context.come_back(messages.MSG_NEW_RESOURCE, goto=goto)
コード例 #2
0
ファイル: bar_aware_views.py プロジェクト: hforge/itws
    def action(self, resource, context, form):
        name = form['name']
        title = form['title']
        order = form['order']

        # Create the resource
        class_id = form['class_id']
        cls = get_resource_class(class_id)
        container = self._get_container(resource, context)
        child = container.make_resource(name, cls)

        # We order the resource in table if needed
        if order != 'do-not-order':
            self.order_item(order, name, form, resource, context)

        # The metadata
        metadata = child.metadata
        language = resource.get_edit_languages(context)[0]
        title = Property(title, lang=language)
        metadata.set_property('title', title)

        # Workflow
        if isinstance(child, WorkflowAware):
            child.set_property('state', form['state'])

        # Calcul Goto
        goto = self._get_box_goto(child, context)

        return context.come_back(messages.MSG_NEW_RESOURCE, goto=goto)
コード例 #3
0
ファイル: views.py プロジェクト: TZM/zmgc
    def action(self, resource, context, form):
        title = form["title"].strip()
        name = form["name"]
        name = checkid(title)
        if name is None:
            raise FormError, messages.MSG_BAD_NAME
        vhosts = []
        # We add the default vhost entry
        site_url = "%s.projects.zmgc.net" % name
        vhosts.append(site_url)
        url = "%s" % form["vhosts"]
        # XXX We need to check the domain name is valid
        vhosts.append(url)
        vhosts = [x for x in vhosts if x]

        # Create the resource
        class_id = "project"
        cls = get_resource_class(class_id)
        container = resource.get_resource("/projects")
        # check if name is taken
        if container.get_resource(name, soft=True) is not None:
            item = container.get_resource(name, soft=True)
            return context.come_back(MSG_EXISTANT_PROJECT)
        item = container.make_resource(name, cls)
        # The metadata
        metadata = item.metadata
        language = resource.get_edit_languages(context)[0]
        metadata.set_property("title", Property(title, lang=language))
        metadata.set_property("vhosts", vhosts)
        metadata.set_property("website_is_open", "community")
        # TODO we need to make this based on the URL of the

        # go to the user's profile page
        goto = "/projects/%s" % item.name
        return context.come_back(MSG_NEW_RESOURCE, goto=goto)
コード例 #4
0
ファイル: mission_views.py プロジェクト: hforge/crm
 def set_value(self, resource, context, name, form):
     if name == 'tags':
         proxy = TagsAware_Edit
         return proxy.set_value(self, resource, context, name, form)
     elif name in ('attachment', 'alert_time'):
         return False
     if name == 'alert_date':
         alert_date = form[name]
         if alert_date:
             alert_time = form['alert_time'] or time(9, 0)
             value = datetime.combine(alert_date, alert_time)
         else:
             status = form['crm_m_status']
             if status not in ('finished', 'nogo'):
                 context.message = ERR_ALERT_MANDATORY
                 return True
             value = None
         resource.set_property('crm_m_alert', value)
         return False
     elif name == 'crm_m_nextaction':
         value = form[name]
         if not value:
             status = form['crm_m_status']
             if status not in ('finished', 'nogo'):
                 context.message = ERR_NEXTACTION_MANDATORY
                 return True
         resource.set_property('crm_m_nextaction', value)
         return False
     elif name == 'comment':
         value = form[name]
         # Attachment
         attachment = form['attachment']
         if attachment is None:
             if not value:
                 return False
         else:
             filename, mimetype, body = attachment
             # Find a non used name
             attachment = checkid(filename)
             attachment, extension, language = FileName.decode(attachment)
             attachment = generate_name(attachment, resource.get_names())
             # Add attachment
             cls = get_resource_class(mimetype)
             resource.make_resource(attachment, cls, body=body,
                 filename=filename, extension=extension,
                 format=mimetype)
             if not value:
                 value = DUMMY_COMMENT
         user = context.user
         author = user.name if user else None
         value = Property(value, date=context.timestamp, author=author,
                 attachment=attachment)
         resource.metadata.set_property(name, value)
         context.database.change_resource(resource)
         return False
     proxy = DBResource_Edit
     return proxy.set_value(self, resource, context, name, form)
コード例 #5
0
ファイル: metadata.py プロジェクト: matrixorz/ikaaro
def get_datatype(format, name):
    if format is None:
        return String

    cls = get_resource_class(format)
    if cls is None:
        return String

    return cls.get_property_datatype(name)
コード例 #6
0
ファイル: metadata.py プロジェクト: staverne/ikaaro
def get_datatype(format, name):
    if format is None:
        return String

    cls = get_resource_class(format)
    if cls is None:
        return String

    return cls.get_property_datatype(name)
コード例 #7
0
ファイル: base.py プロジェクト: nkhine/ztm-ikaaro
 def items(self):
     items = []
     for option in self.options():
         class_id = option['name']
         cls = get_resource_class(class_id)
         items.append({'class_id': class_id,
                       'selected': option['selected'],
                       'title': option['value'],
                       'icon': '/ui/' + cls.class_icon16,
                       'description': cls.class_description})
     return items
コード例 #8
0
ファイル: views.py プロジェクト: hforge/itws
    def action_default(self, resource, context, form):
        name = form['name']
        title = form['title']

        # Create the resource
        class_id = context.query['type']
        cls = get_resource_class(class_id)
        child = cls.make_resource(cls, resource, name)
        # The metadata
        metadata = child.metadata
        language = resource.get_content_language(context)
        metadata.set_property('title', title, language=language)

        goto = self._get_goto(resource, context, form)
        return context.come_back(messages.MSG_NEW_RESOURCE, goto=goto)
コード例 #9
0
ファイル: base.py プロジェクト: nkhine/ztm-ikaaro
    def get_search_types(self, resource, context):
        # FIXME get_search_types and get_items compute almost the same query
        # The only difference is that get_items take into account search_template
        # (type filter and text filter)

        root = context.root
        # Get the container
        container = self._get_container(resource, context)
        container_abspath = container.get_canonical_path()

        # 1. Build the query of all objects to search
        if self.search_on_current_folder_recursive:
            query = get_base_path_query(str(container_abspath))
        else:
            query = PhraseQuery('parent_path', str(container_abspath))

        # Exclude '/theme/'
        if isinstance(resource, WebSite):
            theme_path = container_abspath.resolve_name('theme')
            theme = get_base_path_query(str(theme_path), True)
            query = AndQuery(query, NotQuery(theme))

        if self.ignore_internal_resources:
            query = AndQuery(query, PhraseQuery('is_content', True))

        if self.ignore_box_aware:
            query = AndQuery(query, NotQuery(PhraseQuery('box_aware', True)))

        # 2. Compute children_formats
        children_formats = set()
        for child in root.search(query).get_documents():
            children_formats.add(child.format)

        # 3. Do not show two options with the same title
        formats = {}
        for type in children_formats:
            cls = get_resource_class(type)
            title = cls.class_title.gettext()
            formats.setdefault(title, []).append(type)

        # 4. Build the namespace
        types = []
        for title, type in formats.items():
            type = ','.join(type)
            types.append({'name': type, 'value': title})
        types.sort(key=lambda x: x['value'].lower())

        return types
コード例 #10
0
ファイル: enumerates.py プロジェクト: hforge/itws
    def get_options(cls):
        context = get_context()
        root = context.root
        resource = context.resource
        view = context.view
        # Get the container
        container = view._get_container(resource, context)
        container_abspath = container.get_canonical_path()

        # 1. Build the query of all objects to search
        if view.search_on_current_folder_recursive:
            query = get_base_path_query(str(container_abspath))
        else:
            query = get_base_path_query(str(container_abspath), depth=1)

        # Exclude '/theme/'
        if isinstance(resource, WebSite):
            theme_path = container_abspath.resolve_name('theme')
            theme = get_base_path_query(str(theme_path), True)
            query = AndQuery(query, NotQuery(theme))

        if view.ignore_internal_resources:
            query = AndQuery(query, PhraseQuery('is_content', True))

        if view.ignore_box_aware:
            query = AndQuery(query, NotQuery(PhraseQuery('box_aware', True)))

        # 2. Compute children_formats
        children_formats = set()
        for child in root.search(query).get_documents():
            children_formats.add(child.format)

        # 3. Do not show two options with the same title
        formats = {}
        for type in children_formats:
            cls = get_resource_class(type)
            title = cls.class_title.gettext()
            formats.setdefault(title, []).append(type)

        # 4. Build the namespace
        types = []
        for title, type in formats.items():
            type = ','.join(type)
            types.append({'name': type, 'value': title})
        types.sort(key=lambda x: x['value'].lower())

        return types
コード例 #11
0
ファイル: letter_views.py プロジェクト: hforge/newsletter
    def action(self, resource, context, form):
        # Get the container
        root = resource.get_root()
        container = form['container']
        # Make the resource
        class_id = context.query['type']
        cls = get_resource_class(class_id)
        # Banner relative to here
        prefix = container.get_pathto(resource)
        banner = prefix.resolve2(form['banner'])
        child = container.make_resource(form['name'], cls)

        # Set properties
        language = container.get_edit_languages(context)[0]
        for key in ['title', 'email_subject']:
            value = Property(form[key], lang=language)
            child.metadata.set_property(key, value)

        # Build HTML template
        if banner:
            banner = resource.get_resource(banner)
            banner = child.get_pathto(banner)
        namespace = {'page_uri': './;download',
                     'banner': banner,
                     'title': form['email_subject']}
        template = root.get_resource('/ui/mailing/LetterTemplate.xml')
        handler = child.get_handler(language=language)
        handler.set_changed()
        handler.events = list(stl(template, namespace))
        # Build Text template
        txt = MSG(u'Type your text email here').gettext(language=language)
        value = Property(txt, lang=language)
        child.metadata.set_property('email_text', value)
        # Ok
        goto = str(resource.get_pathto(child))
        return context.come_back(messages.MSG_NEW_RESOURCE, goto=goto)
コード例 #12
0
ファイル: utils.py プロジェクト: hforge/itws
def get_registered_tags_aware_classes():
    return [ get_resource_class(class_id)
             for class_id in tags_aware_registry ]
コード例 #13
0
ファイル: tracker.py プロジェクト: Ramel/tchacker
 def update_20090705(self):
     """
     Encode the unencoded MOV or AVI file, and add the thumb, erase the
     original file.
     """
     from pprint import pprint
     from datetime import datetime
     from tempfile import mkdtemp
     from issue import Tchack_Issue
     from ikaaro.file import Video
     from ikaaro.exceptions import ConsistencyError
     from itools import vfs
     from itools.vfs import FileName
     from itools.core import guess_extension
     from itools.uri import get_uri_path
     from videoencoding import VideoEncodingToFLV
     from ikaaro.registry import get_resource_class
     
     for issue in self.search_resources(cls=Tchack_Issue):
     
         history = issue.get_history()
     
         for record in history.get_records():
         
             filename = record.file
             comment = record.comment
             is_video = False
             if not comment and not filename:
                 continue
             if filename:
                 file = issue.get_resource(filename)
                 is_video = isinstance(file, Video)
             
                 if not is_video:
                     continue
                 if is_video:
                     name = file.name
                     filename, ext, lang = FileName.decode(name)
                     if ext is None:
                         mimetype = file.get_content_type()
                         ext = guess_extension(mimetype)[1:]
                     if(mimetype == 'video/x-msvideo'
                         or mimetype == 'video/quicktime'):
                         pprint("The file %s.%s will be encoded in FLV, \
                             replaced by, then erased." % (filename, ext))
                         
                         handler_path = get_uri_path(issue.handler.uri)
                         
                         dirname = mkdtemp('videoencoding', 'ikaaro')
                         tempdir = vfs.open(dirname)
                         
                         # Paste the file in the tempdir
                         tmp_uri= "file:///%s/%s" % (dirname, filename)
                         vfs.copy(file.handler.uri, tmp_uri)
                         
                         # Encode to 512 of width
                         encoded = VideoEncodingToFLV(file).encode_avi_to_flv(
                              dirname, filename, name, 512)
                         
                         if encoded is not None:
                             flvfilename, flvmimetype,
                             flvbody, flvextension = encoded['flvfile']
                             thumbfilename, thumbmimetype,
                             thumbbody, thumbextension = encoded['flvthumb']
                         # Create the video FLV and thumbnail PNG resources
                         video = get_resource_class(flvmimetype)
                         thumbnail = get_resource_class(thumbmimetype)
                         # Remove the original files
                         if vfs.exists(file.handler.uri):
                             vfs.remove(file.handler.uri)
                         if vfs.exists(file.metadata.uri):
                             vfs.remove(file.metadata.uri)
                         
                         video.make_resource(video, issue, name,
                             body=flvbody, filename=flvfilename,
                             extension=flvextension, format=flvmimetype)
                         thumbnail.make_resource(thumbnail, issue, thumbfilename,
                             body=thumbbody, filename=thumbfilename,
                             extension=thumbextension, format=thumbmimetype)
                         
                         # Clean the temporary folder
                         vfs.remove(dirname)
                         
                         pprint("====================")
                     pprint("xxxxxxxxxxxxxxxx")
コード例 #14
0
ファイル: views.py プロジェクト: TZM/zmgc
 def action(self, resource, context, form):
     # User id
     user = context.user
     # Check to see if the user is an Administrator for another chapter.
     user_get_chapters = user.get_chapters()
     # this returns a document
     # A user may be part of many chapters, we want to make sure
     # they are only administrators for one chapter.
     #for x in user.get_chapters():
     #    if user.name in x.get_members_classified_by_role()['admins']:
     #        # Give admin rights to a new member then proceed
     #        # otherwise the chapter may end up without an administrator
     #        # so we take the user to the browse user's interface.
     #        goto = '/chapters/%s/;browse_users' % x.name
     #        return context.come_back(MSG_EXISTING_CHAPTER_ADMIN, goto=goto)      
     title = form['title'].strip()
     name = form['name']
     name = checkid(title)
     if name is None:
         raise FormError, messages.MSG_BAD_NAME
     vhosts = []
     # We add the default vhost entry
     site_url = ('%s.zmgc.net' % name)
     vhosts.append(site_url)
     url = ('%s' % form['vhosts'])
     # XXX We need to check the domain name is valid
     vhosts.append(clean_website_url(url))
     vhosts = [ x for x in vhosts if x ]
     print vhosts
     # Create the resource
     class_id = 'chapter'
     cls = get_resource_class(class_id)
     container = resource.get_resource('/chapters')
     # check if name is taken
     if container.get_resource(name, soft=True) is not None:
         chapter = container.get_resource(name, soft=True)
         return context.come_back(MSG_EXISTANT_CHAPTER)
     # what if the form is all field, but thu user decides to change to different region?
     county = form['county']
     if county is not None:
         if 'switch' in county.rsplit('#'):
             return self.GET
     # We are now ready to make the chapter resource
     chapter = container.make_resource(name, cls)
     # The metadata
     metadata = chapter.metadata
     language = resource.get_edit_languages(context)[0]
     metadata.set_property('title', Property(title, lang=language))
     metadata.set_property('vhosts', vhosts)
     metadata.set_property('website_is_open', 'community')
     county = context.get_form_value('county').split('#')
     # set chapter location
     selected_region = context.get_form_value('county').split('#')
     metadata.set_property('country', selected_region[0])
     metadata.set_property('region', selected_region[1])
     metadata.set_property('county', selected_region[2])
     
     # Link the User to the newly created Chapter and make them the Administrator
     print chapter.class_roles[-1], 'chapter.class_roles[-1]'
     chapter.set_user_role(user.name, chapter.class_roles[-1])
     # Add the user to the Phoenix site as a 'Member'
     phoenix_site_root = user.get_phoenix_site_root()
     phoenix_site_root.set_user_role(user.name, phoenix_site_root.class_roles[1])
     
     # Now we add the forum, wiki specific for this chapter website.
     blog = chapter.make_resource('blog', Blog)
     calendar = chapter.make_resource('calendar', Calendar)
     forums = chapter.make_resource('forums', Forums)
     wiki = chapter.make_resource('wiki', WikiFolder)
     tracker = chapter.make_resource('tracker', Tracker)
     # TODO send an email with details
     email = user.get_property('email')
     print email
     #if email:
     #    user.send_chapter_confirmation(context, email, chapter)
     # FIXME: we want to take the member to the new site.
     goto = '/chapters/%s/;control_panel' % chapter.name
     return context.come_back(MSG_NEW_CHAPTER, goto=goto)
コード例 #15
0
ファイル: views.py プロジェクト: hforge/itws
 def add_cls(self):
     context = get_context()
     class_id = context.query['type']
     return get_resource_class(class_id)
コード例 #16
0
ファイル: utils.py プロジェクト: hforge/crm
def get_crm(resource):
    cls_crm = get_resource_class('crm')
    crm = resource
    while not isinstance(crm, cls_crm):
        crm = crm.parent
    return crm