コード例 #1
0
ファイル: criterion_completer.py プロジェクト: yankyn/ipuyol
 def get_property_string_from_call(self, call):
     if re.match('.*%s\.[a-zA-Z]+\.[a-zA-Z]+$' % get_module_name(self.module), call):
         string = re.findall('%s\.[a-zA-Z]+\.[a-zA-Z]+$' % get_module_name(self.module), call)[0]
         return string
     elif re.match('.*[a-zA-Z]+\.[a-zA-Z]+$', call):
         string = re.findall('[a-zA-Z]+\.[a-zA-Z]+$', call)[0]
         return string
     else:
         raise NotQueryException()
コード例 #2
0
ファイル: criterion_completer.py プロジェクト: yankyn/ipuyol
 def get_property_string_from_call(self, call):
     if re.match(
             '.*%s\.[a-zA-Z]+\.[a-zA-Z]+$' % get_module_name(self.module),
             call):
         string = re.findall(
             '%s\.[a-zA-Z]+\.[a-zA-Z]+$' % get_module_name(self.module),
             call)[0]
         return string
     elif re.match('.*[a-zA-Z]+\.[a-zA-Z]+$', call):
         string = re.findall('[a-zA-Z]+\.[a-zA-Z]+$', call)[0]
         return string
     else:
         raise NotQueryException()
コード例 #3
0
ファイル: join_completer.py プロジェクト: yankyn/ipuyol
    def get_completer(self, arguments, query):

        if not self.validate_argument(arguments):
            raise NotQueryException()

        if ',' in arguments:
            if arguments.count(',') > 1:
                raise NotQueryException()
            parts = arguments.split(',')
            cls_name = parts[0].strip()
            argument = parts[1].strip()
            cls = self._get_cls(cls_name)
            if cls:
                return CriterionJoinCompleter(argument=argument, query=query, cls=cls, module=self.module,
                                              namespace=self.namespace)
            else:
                raise NotQueryException()

        for cls in PuyolLikeQueryAnalyzer(query=query).get_from_clause():
            if arguments.lower() in ('%s.%s' % (get_module_name(self.module), cls.__name__)).lower():
                return RelationshipJoinCompleter(argument=arguments, query=query, cls=cls, module=self.module)

        parts = arguments.split('.')
        if len(parts) > 1:
            cls_name = '.'.join(parts[:-1])
            argument = parts[-1].strip()
            cls = self._get_cls(cls_name)
            if cls:
                return RelationshipJoinCompleter(argument=argument, query=query, cls=cls, module=self.module)

        return ClassJoinCompleter(argument=arguments, query=query,
                                  base_meta_class=self.module_analyzer.get_base_meta_class(self.module),
                                  module=self.module)
コード例 #4
0
ファイル: criterion_completer.py プロジェクト: yankyn/ipuyol
def get_criteria_suggestions_for_class(cls, module):
    mapper = class_mapper(cls)
    attributes = mapper.attrs
    return [
        '%s.%s.%s' % (get_module_name(module), cls.__name__, attr.key)
        for attr in attributes
    ]
コード例 #5
0
ファイル: join_completer.py プロジェクト: yankyn/ipuyol
 def suggest(self):
     module_name = get_module_name(self.module)
     from_clause = self.query_analyzer.get_from_clause()
     if re.match('%s\..*' % module_name, self.argument):
         argument = self.argument.split('.')[-1]
     else:
         argument = self.argument
     return matching_module_classes(argument, self.module, self.base_meta_class, from_clause)
コード例 #6
0
 def suggest(self):
     module_name = get_module_name(self.module)
     from_clause = self.query_analyzer.get_from_clause()
     if re.match('%s\..*' % module_name, self.argument):
         argument = self.argument.split('.')[-1]
     else:
         argument = self.argument
     return matching_module_classes(argument, self.module,
                                    self.base_meta_class, from_clause)
コード例 #7
0
ファイル: criterion_completer.py プロジェクト: yankyn/ipuyol
 def get_mapped_property(self, argument):
     result = None
     if re.match(r'%s\.[a-zA-Z]+\.[a-zA-Z]+' % get_module_name(self.module),
                 argument) and self.evaluate_expression(argument):
         result = self.evaluate_expression(argument)
     if re.match(r'[a-zA-Z]+\.[a-zA-Z]+', argument) and hasattr(self.module,
                                                                argument.split('.')[
                                                                    0]) and self.evaluate_expression(argument):
         result = self.evaluate_expression(argument)
     if result and hasattr(result, 'property') and (isinstance(result.property, StrategizedProperty)):
         return result.property
コード例 #8
0
ファイル: join_completer.py プロジェクト: yankyn/ipuyol
 def _suggest_pk_for_cls(self, argument, cls):
     pk_attr = self.primary_key(cls)
     if pk_attr:
         key = pk_attr.key
     else:
         raise NotQueryException()
     suggestion = '%s.%s.%s' % (get_module_name(self.module), cls.__name__, key)
     if argument.lower() in suggestion.lower():
         return [suggestion]
     else:
         return []
コード例 #9
0
ファイル: criterion_completer.py プロジェクト: yankyn/ipuyol
 def get_mapped_property(self, argument):
     result = None
     if re.match(r'%s\.[a-zA-Z]+\.[a-zA-Z]+' % get_module_name(self.module),
                 argument) and self.evaluate_expression(argument):
         result = self.evaluate_expression(argument)
     if re.match(r'[a-zA-Z]+\.[a-zA-Z]+', argument) and hasattr(
             self.module,
             argument.split('.')[0]) and self.evaluate_expression(argument):
         result = self.evaluate_expression(argument)
     if result and hasattr(result, 'property') and (isinstance(
             result.property, StrategizedProperty)):
         return result.property
コード例 #10
0
 def _suggest_pk_for_cls(self, argument, cls):
     pk_attr = self.primary_key(cls)
     if pk_attr:
         key = pk_attr.key
     else:
         raise NotQueryException()
     suggestion = '%s.%s.%s' % (get_module_name(
         self.module), cls.__name__, key)
     if argument.lower() in suggestion.lower():
         return [suggestion]
     else:
         return []
コード例 #11
0
ファイル: join_completer.py プロジェクト: yankyn/ipuyol
 def _suggest_fk(self, argument, source_classes, target_classes):
     suggestions = []
     for source_class in source_classes:
         foreign_key_properties = self.foreign_keys(source_class)
         for foreign_key_property in foreign_key_properties:
             expression = foreign_key_property.expression
             foreign_key = self._get_fk_for_expression(expression)
             for target_class in target_classes:
                 if foreign_key.references(target_class.__table__):
                     suggestion = '%s.%s.%s' % (
                         get_module_name(self.module), source_class.__name__, foreign_key_property.key)
                     if argument.lower() in suggestion.lower():
                         suggestions.append(suggestion)
     return suggestions
コード例 #12
0
 def _suggest_fk(self, argument, source_classes, target_classes):
     suggestions = []
     for source_class in source_classes:
         foreign_key_properties = self.foreign_keys(source_class)
         for foreign_key_property in foreign_key_properties:
             expression = foreign_key_property.expression
             foreign_key = self._get_fk_for_expression(expression)
             for target_class in target_classes:
                 if foreign_key.references(target_class.__table__):
                     suggestion = '%s.%s.%s' % (get_module_name(
                         self.module), source_class.__name__,
                                                foreign_key_property.key)
                     if argument.lower() in suggestion.lower():
                         suggestions.append(suggestion)
     return suggestions
コード例 #13
0
ファイル: join_completer.py プロジェクト: yankyn/ipuyol
def matching_module_classes(argument, module, base_meta_class, from_clause):
    module_name = get_module_name(module)
    suggestions = []
    for key, potential_join_class in module.__dict__.items():  # All public attributes.
        if argument.lower() in key.lower():  # The argument matches string wise
            if isinstance(potential_join_class, base_meta_class):  # All suggestions that are tables.
                if potential_join_class not in from_clause:  # Is not already joined.
                    # All possible combinations for relationships.
                    # Either the suggestion has a relationship to the from clause.
                    # Or the from clause has a relationship to the suggestion.
                    for cls in from_clause:
                        if (potential_join_class in class_relationships(cls)) or (
                                cls in class_relationships(
                                    potential_join_class)):
                            suggestions.append('%s.%s' % (module_name, key))
    return suggestions
コード例 #14
0
ファイル: join_completer.py プロジェクト: yankyn/ipuyol
 def suggest(self):
     mapper = class_mapper(self.cls)
     from_clause = self.query_analyzer.get_from_clause()
     if not self.cls in from_clause:
         raise NotQueryException()
         # All relationship properties.
     relationships = [attr for attr in mapper.attrs if isinstance(attr, RelationshipProperty)]
     # All relationship properties that are not already joined.
     allowed = [rel for rel in relationships if rel.mapper.entity not in from_clause]
     # And start with the argument.
     suggestions = []
     for rel in allowed:
         suggestion = '%s.%s.%s' % (get_module_name(self.module), self.cls.__name__, rel.key)
         if self.argument in suggestion:
             suggestions.append(suggestion)
     return suggestions
コード例 #15
0
    def get_completer(self, arguments, query):

        if not self.validate_argument(arguments):
            raise NotQueryException()

        if ',' in arguments:
            if arguments.count(',') > 1:
                raise NotQueryException()
            parts = arguments.split(',')
            cls_name = parts[0].strip()
            argument = parts[1].strip()
            cls = self._get_cls(cls_name)
            if cls:
                return CriterionJoinCompleter(argument=argument,
                                              query=query,
                                              cls=cls,
                                              module=self.module,
                                              namespace=self.namespace)
            else:
                raise NotQueryException()

        for cls in PuyolLikeQueryAnalyzer(query=query).get_from_clause():
            if arguments.lower() in (
                    '%s.%s' %
                (get_module_name(self.module), cls.__name__)).lower():
                return RelationshipJoinCompleter(argument=arguments,
                                                 query=query,
                                                 cls=cls,
                                                 module=self.module)

        parts = arguments.split('.')
        if len(parts) > 1:
            cls_name = '.'.join(parts[:-1])
            argument = parts[-1].strip()
            cls = self._get_cls(cls_name)
            if cls:
                return RelationshipJoinCompleter(argument=argument,
                                                 query=query,
                                                 cls=cls,
                                                 module=self.module)

        return ClassJoinCompleter(
            argument=arguments,
            query=query,
            base_meta_class=self.module_analyzer.get_base_meta_class(
                self.module),
            module=self.module)
コード例 #16
0
def matching_module_classes(argument, module, base_meta_class, from_clause):
    module_name = get_module_name(module)
    suggestions = []
    for key, potential_join_class in module.__dict__.items(
    ):  # All public attributes.
        if argument.lower() in key.lower():  # The argument matches string wise
            if isinstance(potential_join_class,
                          base_meta_class):  # All suggestions that are tables.
                if potential_join_class not in from_clause:  # Is not already joined.
                    # All possible combinations for relationships.
                    # Either the suggestion has a relationship to the from clause.
                    # Or the from clause has a relationship to the suggestion.
                    for cls in from_clause:
                        if (potential_join_class in class_relationships(cls)
                            ) or (
                                cls
                                in class_relationships(potential_join_class)):
                            suggestions.append('%s.%s' % (module_name, key))
    return suggestions
コード例 #17
0
 def suggest(self):
     mapper = class_mapper(self.cls)
     from_clause = self.query_analyzer.get_from_clause()
     if not self.cls in from_clause:
         raise NotQueryException()
         # All relationship properties.
     relationships = [
         attr for attr in mapper.attrs
         if isinstance(attr, RelationshipProperty)
     ]
     # All relationship properties that are not already joined.
     allowed = [
         rel for rel in relationships
         if rel.mapper.entity not in from_clause
     ]
     # And start with the argument.
     suggestions = []
     for rel in allowed:
         suggestion = '%s.%s.%s' % (get_module_name(
             self.module), self.cls.__name__, rel.key)
         if self.argument in suggestion:
             suggestions.append(suggestion)
     return suggestions
コード例 #18
0
ファイル: criterion_completer.py プロジェクト: yankyn/ipuyol
def get_criteria_suggestions_for_class(cls, module):
    mapper = class_mapper(cls)
    attributes = mapper.attrs
    return ['%s.%s.%s' % (get_module_name(module), cls.__name__, attr.key) for attr in attributes]
コード例 #19
0
ファイル: orm_line_parser.py プロジェクト: yankyn/ipuyol
 def module_name(self):
     return get_module_name(self.module)