def get_attributes(self):
        if self.reverse:
            attributes = self.extra_attributes
            attributes_dict = self.get_field_attrs_for(attributes)
            
            # Grab the ReferenceProperty field on the related model so that
            # we can figureout what the inverse field name should be.
            related_field = getattr(self.field._model, self.field._prop_name)
            attributes_dict.update(
                isMaster = False,
                key = related_field.collection_name,
                inverse = lcamelize(getattr(related_field, \
                  'verbose_name', '')) or lcamelize(related_field.name),
            )
            
        else:
            attributes_dict = \
              super(AppEngineRelationshipTransformer, self).get_attributes()

            attributes_dict.update(
                isMaster = True,
                inverse = lcamelize(self.field.collection_name),
            )
        
        return attributes_dict
Beispiel #2
0
    def get_attributes(self):
        if self.reverse:
            attributes = self.extra_attributes
            attributes_dict = self.get_field_attrs_for(attributes)
            attributes_dict.update(
                isMaster = False,
                #remove the _set after the field to successfully create nested Elements
                key = self.field.related.get_accessor_name(),
                #key = self.field.related.opts.object_name.lower(),
                #isNested - important for nestedRecords
                isNested = True,
                nested = True,
                inverse = lcamelize(self.field.verbose_name) or \
                  lcamelize(self.field.name),
            )
            
        else:
            attributes_dict = \
              super(DjangoRelationshipTransformer, self).get_attributes()

            attributes_dict.update(
                isMaster = True,
                inverse = lcamelize(self.field.related.get_accessor_name()),
            )
        
        return attributes_dict
 def get_name(self):
     if self.reverse:
         # Grab the ReferenceProperty field on the related model.
         related_field = getattr(self.field._model, self.field._prop_name)
         return lcamelize(related_field.collection_name)
     
     return super(AppEngineRelationshipTransformer, self).get_name()
Beispiel #4
0
 def get_name(self):
     if self.reverse:
         # Get the camlized related_name for the field, since there is no
         # field name to use from the reverse side of the relationship.
         return lcamelize(self.field.related.get_accessor_name())
     
     return super(DjangoRelationshipTransformer, self).get_name()
Beispiel #5
0
 def get_field_attrs_for(self, li):
     """Helper function to get the specified field attributes."""
     attributes_dict = {}
     
     # Loop over the list to find corresponding Python and SproutCore
     # attribute names.
     for l in li:
         if not hasattr(l, '__iter__'):
             l = [l]
             
         if len(l) == 1:
             pyname, scname = l[0], lcamelize(l[0])
             ignore = NOT_PROVIDED
         elif len(l) == 2:
             pyname, scname = l[0], l[1]
             ignore = NOT_PROVIDED
         elif len(l) == 3:
             pyname, scname, ignore = l[0], l[1], l[2]
     
         # Get the attribute's value, ignoring it if it doesn't exist or is
         # equal to the provided ignore value.
         try:
             attr = getattr(self.field, pyname)
             if callable(attr):
                 attr = attr()
             if attr != ignore:
                 attributes_dict[scname] = attr
         except AttributeError:
             print "%s has no attribute named '%s'" % (self.field, pyname)
         except TypeError, e:
             print "Unabled to call method '%s' on %s: %s" % \
               (pyname, self.field, e)
         except:
Beispiel #6
0
    def get_attributes(self):
        if self.reverse:
            attributes = self.extra_attributes
            attributes_dict = self.get_field_attrs_for(attributes)
            attributes_dict.update(
                isMaster = False,
                key = self.field.related.get_accessor_name(),
                inverse = lcamelize(self.field.verbose_name) or \
                  lcamelize(self.field.name),
            )
            
        else:
            attributes_dict = \
              super(DjangoRelationshipTransformer, self).get_attributes()

            attributes_dict.update(
                isMaster = True,
                inverse = lcamelize(self.field.related.get_accessor_name()),
            )
        
        return attributes_dict
Beispiel #7
0
    def get_meta(self, model):
        ops = model._meta
        meta_dict= dict(
            transformedFrom = 'Django',
            modelClass = '.'.join([ops.app_label, ops.module_name]),
            verboseName = ops.verbose_name.title(),
            verboseNamePlural = ops.verbose_name_plural.title(),
        )

        attributes = [
            'get_latest_by',
            'ordering',
            'order_with_respect_to',
            'unique_together',
        ]
        
        for attr in attributes:
            value = getattr(ops, attr, None)
            if value is not None:
                meta_dict[lcamelize(attr)] = value
        
        return meta_dict
    def get_field_attrs_for(self, li):
        """Helper function to get the specified field attributes."""        
        attributes_dict = {}

        # Loop over the list to find corresponding Python and SproutCore
        # attribute names.
        for l in li:
            if not hasattr(l, '__iter__'):
                l = [l]
                
            if len(l) == 1:
                pyname, scname = l[0], lcamelize(l[0])
                ignore = self.ignore
            elif len(l) == 2:
                pyname, scname = l[0], l[1]
                ignore = self.ignore
            elif len(l) == 3:
                pyname, scname, ignore = l[0], l[1], l[2]
        
            # Get the attribute's value, ignoring it if it doesn't exist or is
            # equal to the provided ignore value.
            try:
                attr = getattr(self.field, pyname)
                if callable(attr):
                    attr = attr()
                if attr != ignore:
                    attributes_dict[scname] = attr

            # TODO: how do we want to log this problem, since it occurs at
            # runtime, instead of beforehand. Possibly with smart defaults?
            except AttributeError:
                print "%s has no attribute named '%s'" % (self.field, pyname)
            except TypeError, e:
                print "Unabled to call method '%s' on %s: %s" % \
                  (pyname, self.field, e)
            except:
 def get_name(self):
     return lcamelize(getattr(self.field, 'verbose_name', '')) or \
       lcamelize(self.field.name)
Beispiel #10
0
 def get_name(self):
     return lcamelize(self.field.verbose_name) or \
       lcamelize(self.field.name)