def __call__(self, context=None):
     query = self.constructQuery(context)
     results = query.all()
     terms = []
     trusted=removeSecurityProxy(context)
     ministry_id = getattr(trusted, self.value_field, None)
     for ob in results:
         obj = translate_obj(ob)
         terms.append(
             vocabulary.SimpleTerm(
                 value = getattr(obj, 'group_id'), 
                 token = getattr(obj, 'group_id'),
                 title = "%s - %s" % (getattr(obj, 'short_name'),
                         getattr(obj, 'full_name'))
             ))
     if ministry_id:
         if query.filter(domain.Group.group_id == ministry_id).count() == 0:
             session = Session()
             ob = session.query(domain.Group).get(ministry_id)
             obj = translate_obj(ob)
             terms.append(
                 vocabulary.SimpleTerm(
                     value = getattr(obj, 'group_id'), 
                     token = getattr(obj, 'group_id'),
                     title = "%s - %s" % (getattr(obj, 'short_name'),
                             getattr(obj, 'full_name'))
             ))            
     return vocabulary.SimpleVocabulary(terms)
Example #2
0
 def __call__(self, context=None):
     query = self.constructQuery(context)
     results = query.all()
     terms = []
     trusted = removeSecurityProxy(context)
     ministry_id = getattr(trusted, self.value_field, None)
     for ob in results:
         obj = translate_obj(ob)
         terms.append(
             vocabulary.SimpleTerm(
                 value=getattr(obj, 'group_id'),
                 token=getattr(obj, 'group_id'),
                 title="%s - %s" %
                 (getattr(obj, 'short_name'), getattr(obj, 'full_name'))))
     if ministry_id:
         if query.filter(domain.Group.group_id == ministry_id).count() == 0:
             session = Session()
             ob = session.query(domain.Group).get(ministry_id)
             obj = translate_obj(ob)
             terms.append(
                 vocabulary.SimpleTerm(
                     value=getattr(obj, 'group_id'),
                     token=getattr(obj, 'group_id'),
                     title="%s - %s" % (getattr(
                         obj, 'short_name'), getattr(obj, 'full_name'))))
     return vocabulary.SimpleVocabulary(terms)
Example #3
0
    def reindexAll(klass, connection, flush_threshold=500):
        instances = Session().query(klass.domain_model).all()
        resolver = ContentResolver()
        log.warning("Bulk Indexing %r"%klass)
        count = 0
        for i in instances:
            for lang in languages():
                count += 1
                doc_id = resolver.id(i, language=lang.value)
                translated = translation.translate_obj(i, lang.value)
                translated.language = lang.value
                indexer = klass(translated)
                create = False
                doc = indexer.document(connection)
                doc.id = doc_id
                doc.fields.append(xappy.Field('resolver', resolver.scheme))
                #print "*****************"
                #print doc.id
                #print translated.__class__.__name__
                #for field in doc.fields:
                #    print field.name, "=", field.value
                connection.replace(doc)
    
                if count % flush_threshold == 0:
                    log.warning("Flushing %s %s Records"%(flush_threshold, klass))

        # flush the remainder
        connection.flush()
Example #4
0
 def __call__(self):
     ob = translate_obj(self.context, self.request.locale.id.language)
     akomantoso_element = self.create_base_structure()
     akomantoso_element.appendChild(self.create_body_structure(ob))
     self.response.appendChild(akomantoso_element)
     self.request.response.setHeader("Content-Type", "text/xml")
     return self.response.toxml("utf-8")
Example #5
0
 def getBatch(self, start=0, limit=20):
     order_by = self.getSort()
     context = proxy.removeSecurityProxy(self.context)
     query=get_query(self.context, self.request)
     # fetch the nodes from the container
     filter_by = dateFilter(self.request)
     if filter_by:
         if ("start_date" in  context._class.c 
             and "end_date" in  context._class.c):
             # apply date range resrictions
             query=query.filter(filter_by)
     #query = query.limit(limit).offset(start)
     ud_filter = self.getFilter()
     if ud_filter != "":
         query=query.filter(ud_filter)
     if order_by:
         query = query.order_by(order_by)
     nodes = self._get_secured_batch(query, start, limit)
     t_nodes = []
     for node in nodes:
         try:
             t_nodes.append(translate_obj(node))
         except (AssertionError,): # node is not ITranslatable 
             t_nodes.append(node)
     batch = self._jsonValues(t_nodes, self.fields, self.context,
         self._get_anno_getters_by_field_name(self.context))
     return batch
Example #6
0
 def results(self):
     for data in self.context:
         translated_type = translate_obj(data.type)
         yield {'title': data.file_title,
                'url': './files/obj-%i/download' % data.attached_file_id,
                'name': data.file_name,
                'type': translated_type.attached_file_type_name,
                'menu': self.generate_file_manipulation_menu(data)}
Example #7
0
 def translate_objects(self, nodes, lang=None):
     """Translate container items if context domain is translatable
     """
     if not mfaces.ITranslatable.implementedBy(self.domain_model):
         return nodes
     # !+ lang should always be valid here... make not optional, assert?
     if lang is None:
         lang = translation.get_request_language(request=self.request)
     return [ translation.translate_obj(node, lang) for node in nodes ]
Example #8
0
 def translate_objects(self, nodes, lang=None):
     """ Translate container items if translatable
     """
     if lang is None:
         lang = translation.get_request_language(request=self.request)
     for index, node in enumerate(nodes):
         if ITranslatable.providedBy(node):
             nodes[index] = translation.translate_obj(node, lang)
     return nodes
Example #9
0
 def translate_objects(self, nodes, lang=None):
     """Translate container items if context domain is translatable
     """
     if not mfaces.ITranslatable.implementedBy(self.domain_model):
         return nodes
     # !+ lang should always be valid here... make not optional, assert?
     if lang is None:
         lang = translation.get_request_language(request=self.request)
     return [translation.translate_obj(node, lang) for node in nodes]
Example #10
0
 def update(self):
     # should only ever be called for contexts with these interfaces
     assert (IWorkspaceContainer.providedBy(self.context) or 
             IWorkspaceSectionContext.providedBy(self.context))
     self.sections = getMenu("workspace_context_navigation", 
                                             self.context, self.request)
     # get a translated copy of original workspace object
     workspace = translate_obj(
             misc.get_parent_with_interface(self, IWorkspaceContainer))
     self.workspace_title = workspace.full_name
Example #11
0
    def __call__(self):
        self.request.response.setHeader('Content-Type', 'application/rss+xml')

        for item in self.values:
            #Trying to translate item to the current language
            i18n_item = translate_obj(item, self.request.locale.id.language)
            item_url = self.get_item_url(item)
            self.channel_element.appendChild(
                self.generate_item(self.get_title(i18n_item), item_url,
                                   self.get_date(i18n_item), item_url))
        return self.response.toxml("utf-8")
Example #12
0
    def update(self):
        # should only ever be called for contexts with these interfaces
        assert IWorkspaceContainer.providedBy(self.context) or IWorkspaceSectionContext.providedBy(self.context)
        self.sections = getMenu("workspace_context_navigation", self.context, self.request)
        # Append a trailing slash to each workspace viewlet navigation entry so
        # that the right context is always maintained when using this navigation.
        for section in self.sections:
            section["url"] = url.set_url_context(section["url"])

        # get a translated copy of original workspace object
        workspace = translate_obj(misc.get_parent_with_interface(self, IWorkspaceContainer))
        self.workspace_title = workspace.full_name
Example #13
0
 def object_translate(self, ob, event):
     # !+TRANSLATION_VERSION(mr, feb-2013) the audited values for the (head) 
     # object are those for the newly submitted translation BUT a "translation"
     # should really be bound to a specific *version* of the object, not to head.
     translated_ob = translate_obj(ob, event.language)
     translated_ob.language = event.language
     # !+TRANSLATE_DESCRIPTION(mr, feb-2013) this should really be passed
     # on such that is is picked up by the change description formattter,
     # and not persisted on the xp change.note (intended primarily for 
     # manual notes coming from the user).
     note = "fields: %s" % (", ".join(event.translated_attribute_names))
     return self._object_changed("translate", translated_ob, note=note)
Example #14
0
    def __call__(self):
        self.request.response.setHeader('Content-Type', 'application/rss+xml')

        for item in self.values:
            #Trying to translate item to the current language
            i18n_item = translate_obj(item, self.request.locale.id.language)
            item_url = self.get_item_url(item)
            self.channel_element.appendChild(self.generate_item(self.get_title(i18n_item),
                                                                item_url,
                                                                self.get_date(i18n_item),
                                                                item_url))
        return self.response.toxml("utf-8")
Example #15
0
 def object_translate(self, ob, event):
     # !+TRANSLATION_VERSION(mr, feb-2013) the audited values for the (head)
     # object are those for the newly submitted translation BUT a "translation"
     # should really be bound to a specific *version* of the object, not to head.
     translated_ob = translate_obj(ob, event.language)
     translated_ob.language = event.language
     # !+TRANSLATE_DESCRIPTION(mr, feb-2013) this should really be passed
     # on such that is is picked up by the change description formattter,
     # and not persisted on the xp change.note (intended primarily for
     # manual notes coming from the user).
     note = "fields: %s" % (", ".join(event.translated_attribute_names))
     return self._object_changed("translate", translated_ob, note=note)
Example #16
0
 def translate_objects(self, nodes, lang=None):
     """ (nodes:[ITranslatable]) -> [nodes]
     """
     if lang is None:
         lang = translation.get_request_language()
     t_nodes = []
     for node in nodes:
         try:
             t_nodes.append(translation.translate_obj(node, lang))
         except (AssertionError,): # node is not ITranslatable
             debug.log_exc_info(sys.exc_info(), log_handler=log.warn)
             t_nodes.append(node)
     return t_nodes
Example #17
0
 def translate_objects(self, nodes, lang=None):
     """ (nodes:[ITranslatable]) -> [nodes]
     """
     if lang is None:
         lang = translation.get_request_language()
     t_nodes = []
     for node in nodes:
         try:
             t_nodes.append(translation.translate_obj(node, lang))
         except (AssertionError, ):  # node is not ITranslatable
             debug.log_exc_info(sys.exc_info(), log_handler=log.warn)
             t_nodes.append(node)
     return t_nodes
Example #18
0
 def __call__(self, context=None):
     query = self.constructQuery(context)
     results = query.all()
     terms = []
     title_field = self.title_field or self.token_field
     for ob in results:
         obj = translate_obj(ob)
         terms.append(vocabulary.SimpleTerm(
                 value = getattr(obj, self.value_field), 
                 token = getattr(obj, self.token_field),
                 title = getattr(obj, title_field),
         ))
     return vocabulary.SimpleVocabulary(terms)
Example #19
0
 def __call__(self, context=None):
     query = self.constructQuery(context)
     results = query.all()
     terms = []
     for ob in results:
         obj = translate_obj(ob)
         terms.append(
             vocabulary.SimpleTerm(
                 value = getattr(obj, 'user_role_type_id'), 
                 token = getattr(obj, 'user_role_type_id'),
                 title = getattr(obj, 'user_role_name'),
                ))
     return vocabulary.SimpleVocabulary(terms)
Example #20
0
 def __call__(self, context=None):
     query = self.constructQuery(context)
     results = query.all()
     terms = []
     title_field = self.title_field or self.token_field
     for ob in results:
         obj = translate_obj(ob)
         terms.append(vocabulary.SimpleTerm(
                 value = getattr(obj, self.value_field), 
                 token = getattr(obj, self.token_field),
                 title = getattr(obj, title_field) ,
         ))
     return vocabulary.SimpleVocabulary(terms)
Example #21
0
 def __call__(self, context=None):
     query = self.constructQuery(context)
     results = query.all()
     terms = []
     for ob in results:
         obj = translate_obj(ob)
         terms.append(
             vocabulary.SimpleTerm(
                 value=getattr(obj, 'user_role_type_id'),
                 token=getattr(obj, 'user_role_type_id'),
                 title=getattr(obj, 'user_role_name'),
             ))
     return vocabulary.SimpleVocabulary(terms)
Example #22
0
 def __call__(self, context=None):
     query = self.constructQuery(context)
     results = query.all()
     terms = []
     for ob in results:
         obj = translate_obj(ob)
         terms.append(
             vocabulary.SimpleTerm(
                 value=obj.group_sitting_type_id,
                 token=obj.group_sitting_type,
                 title="%s (%s-%s)" %
                 (obj.group_sitting_type, obj.start_time, obj.end_time),
             ))
     return vocabulary.SimpleVocabulary(terms)
Example #23
0
 def __call__(self, context=None):
     query = self.constructQuery(context)
     results = query.all()
     terms = []
     title_field = self.title_field or self.token_field
     title_getter = self.title_getter or (lambda ob: getattr(ob, title_field))
     for ob in results:
         if ITranslatable.providedBy(ob):
             ob = translate_obj(ob)
         terms.append(vocabulary.SimpleTerm(
                 value = getattr(ob, self.value_field), 
                 token = getattr(ob, self.token_field),
                 title = title_getter(ob),
         ))
     return vocabulary.SimpleVocabulary(terms)
Example #24
0
    def update(self):
        # should only ever be called for contexts with these interfaces
        assert (IWorkspaceContainer.providedBy(self.context) or
                IWorkspaceSectionContext.providedBy(self.context))
        self.sections = getMenu("workspace_context_navigation",
                                                self.context, self.request)
        # Append a trailing slash to each workspace viewlet navigation entry so 
        # that the right context is always maintained when using this navigation.
        for section in self.sections:
            section["url"] = url.set_url_context(section["url"])

        # get a translated copy of original workspace object
        workspace = translate_obj(
                misc.get_parent_with_interface(self, IWorkspaceContainer))
        self.workspace_title = workspace.full_name
Example #25
0
 def __call__(self, context=None):
     query = self.constructQuery(context)
     results = query.all()
     terms = []
     for ob in results:
         obj = translate_obj(ob)
         terms.append(vocabulary.SimpleTerm(
                 value = obj.group_sitting_type_id, 
                 token = obj.group_sitting_type,
                 title = "%s (%s-%s)" % (
                     obj.group_sitting_type, 
                     obj.start_time, 
                     obj.end_time),
             ))
     return vocabulary.SimpleVocabulary(terms)
Example #26
0
 def __call__(self, context=None):
     query = self.constructQuery(context)
     results = query.all()
     terms = []
     title_field = self.title_field or self.token_field
     title_getter = self.title_getter or (lambda ob: getattr(ob, title_field))
     for ob in results:
         if ITranslatable.providedBy(ob):
             ob = translate_obj(ob)
         terms.append(vocabulary.SimpleTerm(
                 value = getattr(ob, self.value_field), 
                 token = getattr(ob, self.token_field),
                 title = title_getter(ob),
         ))
     return vocabulary.SimpleVocabulary(terms)
Example #27
0
 def __call__(self, context=None):
     while not IBungeniGroup.providedBy(context):
         context = context.__parent__
         if not context:
             raise NotImplementedError("Context does not implement IBungeniGroup")
     query = self.constructQuery(context)
     results = query.all()
     terms = []
     for ob in results:
         obj = translate_obj(ob)
         terms.append(vocabulary.SimpleTerm(
                 value = obj.title_type_id, 
                 token = obj.title_type_id,
                 title = obj.title_name,
             ))
     return vocabulary.SimpleVocabulary(terms)
Example #28
0
 def translate_objects(self, nodes, lang=None):
     """ (nodes:[ITranslatable]) -> [nodes]
     """
     if lang is None:
         lang = translation.get_request_language()
     t_nodes = []
     for node in nodes:
         try:
             t_nodes.append(translation.translate_obj(node, lang))
         except (AssertionError,):  # node is not ITranslatable
             debug.log_exc_info(sys.exc_info(), log_handler=log.warn)
             # if a node is not translatable then we assume that NONE of
             # the nodes are translatable, so we simply break out,
             # returning the untranslated nodes as is
             return nodes
     return t_nodes
Example #29
0
 def results(self):
     session = Session()
     for data in self.context:
         file_type = session.query(AttachedFileType)\
                            .filter(AttachedFileType.attached_file_type_id == data.attached_file_type_id)\
                            .first()
         if file_type is None:
             file_type_name = ' - '
         else:
             file_type_name = translate_obj(file_type).attached_file_type_name
         yield {'title': data.file_title,
                'url': self.base_url + '/files/obj-%i/versions/obj-%i' \
                       % (data.content_id, data.version_id),
                'name': data.file_name,
                'type': file_type_name,
                'menu': self.generate_file_manipulation_menu(data)}
Example #30
0
 def translate_objects(self, nodes, lang=None):
     """ (nodes:[ITranslatable]) -> [nodes]
     """
     if lang is None:
         lang = translation.get_request_language()
     t_nodes = []
     for node in nodes:
         try:
             t_nodes.append(translation.translate_obj(node, lang))
         except (AssertionError, ):  # node is not ITranslatable
             debug.log_exc_info(sys.exc_info(), log_handler=log.warn)
             # if a node is not translatable then we assume that NONE of
             # the nodes are translatable, so we simply break out,
             # returning the untranslated nodes as is
             return nodes
     return t_nodes
Example #31
0
 def __call__(self, context=None):
     while not IBungeniGroup.providedBy(context):
         context = context.__parent__
         if not context:
             raise NotImplementedError(
                 "Context does not implement IBungeniGroup")
     query = self.constructQuery(context)
     results = query.all()
     terms = []
     for ob in results:
         obj = translate_obj(ob)
         terms.append(
             vocabulary.SimpleTerm(
                 value=obj.title_type_id,
                 token=obj.title_type_id,
                 title=obj.title_name,
             ))
     return vocabulary.SimpleVocabulary(terms)
Example #32
0
    def process( self, connection ):
        if interfaces.DEBUG_LOG: log.info("Modifying %r"%self.document_id )        
        instance = self.resolve()
#        if not instance or instance == interfaces.OP_REQUEUE:
#            return instance        
        if ITranslatable.providedBy(instance):
            for lang in languages():
                translated_instance = translation.translate_obj(instance, lang=lang.value)
                translated_instance.language = lang.value
                doc = interfaces.IIndexer( translated_instance ).document( connection )
                doc.id = self.get_resolver().id(instance, language=lang.value)       
                doc.fields.append( xappy.Field('resolver', self.resolver_id ) )
                print doc.id
                connection.replace(doc)
        else:
            doc = interfaces.IIndexer( instance ).document( connection )
            doc.id = self.document_id        
            doc.fields.append( xappy.Field('resolver', self.resolver_id ) )
            connection.replace(doc)
Example #33
0
 def process(self, connection):
     if interfaces.DEBUG_LOG: log.info("Modifying %r" % self.document_id)
     instance = self.resolve()
     #        if not instance or instance == interfaces.OP_REQUEUE:
     #            return instance
     if ITranslatable.providedBy(instance):
         for lang in languages():
             translated_instance = translation.translate_obj(
                 instance, lang=lang.value)
             translated_instance.language = lang.value
             doc = interfaces.IIndexer(translated_instance).document(
                 connection)
             doc.id = self.get_resolver().id(instance, language=lang.value)
             doc.fields.append(xappy.Field('resolver', self.resolver_id))
             print doc.id
             connection.replace(doc)
     else:
         doc = interfaces.IIndexer(instance).document(connection)
         doc.id = self.document_id
         doc.fields.append(xappy.Field('resolver', self.resolver_id))
         connection.replace(doc)
Example #34
0
 def getBatch( self, start=0, limit=20):
     order_by = self.getSort()
     context = proxy.removeSecurityProxy( self.context )
     query=get_query(self.context, self.request)
     # fetch the nodes from the container
     filter_by = dateFilter( self.request )
     if filter_by:
         if ('start_date' in  context._class.c 
             and 'end_date' in  context._class.c):
             # apply date range resrictions
             query=query.filter(filter_by)
     #query = query.limit( limit ).offset( start )
     ud_filter = self.getFilter()
     if ud_filter != '':
         query=query.filter(ud_filter)
     if order_by:
         query = query.order_by( order_by )
     nodes = self._get_secured_batch(query, start, limit)
     t_nodes = []
     for node in nodes:
         t_nodes.append(translate_obj(node))
     batch = self._jsonValues( t_nodes, self.fields, self.context )
     return batch
Example #35
0
 def getBatch(self, start=0, limit=20):
     order_by = self.getSort()
     context = proxy.removeSecurityProxy(self.context)
     query = get_query(self.context, self.request)
     # fetch the nodes from the container
     filter_by = dateFilter(self.request)
     if filter_by:
         if ('start_date' in context._class.c
                 and 'end_date' in context._class.c):
             # apply date range resrictions
             query = query.filter(filter_by)
     #query = query.limit( limit ).offset( start )
     ud_filter = self.getFilter()
     if ud_filter != '':
         query = query.filter(ud_filter)
     if order_by:
         query = query.order_by(order_by)
     nodes = self._get_secured_batch(query, start, limit)
     t_nodes = []
     for node in nodes:
         t_nodes.append(translate_obj(node))
     batch = self._jsonValues(t_nodes, self.fields, self.context)
     return batch
Example #36
0
 def __init__(self, context, target_lang):
     self.context = context # IBungeniContent
     self.target_lang = target_lang
     self.translated_context = translation.translate_obj(
         context, lang=target_lang) # domain.ObjectTranslation
Example #37
0
 def get_title(self, item):
     return "%s %s" % (translate_obj(
         item.head,
         self.request.locale.id.language).short_title, _(u"changes from"))
Example #38
0
 def get_title(self, item):
     return "%s %s" % (
         translate_obj(item.head,
                       self.request.locale.id.language).short_title,
         _(u"changes from"))
Example #39
0
 def get_title(self, item):
     return "%s %s %s" % (translate_obj(item.origin, self.request.locale.id.language).short_name,
                          _(u"changes from"),
                          self.format_date(item.date_audit))
Example #40
0
def get_translated_group_label(group):
    """Get a translated display text to refer to the group.
    """
    g = translate_obj(group)
    return "%s - %s" % (g.short_name, g.full_name)
Example #41
0
 def get_title(self, item):
     return "%s %s %s" % (translate_obj(item.origin, self.request.locale.id.language).short_name,
                          _(u"changes from"),
                          self.format_date(item.date_audit))
Example #42
0
 def __init__(self, context, request):
     self.i18n_context = translate_obj(context, request.locale.id.language)
     super(TimelineRSSView, self).__init__(context, request)