Ticket #1335: docs_db-api.txt.diff

File docs_db-api.txt.diff, 7.5 KB (added by eric@…, 19 years ago)

db-api.txt documentation fix for startswith

  • django/models/auth.py

     
    22from django.models import core
    33from django.utils.translation import gettext_lazy as _
    44
     5
    56class Permission(meta.Model):
    67    name = meta.CharField(_('name'), maxlength=50)
    78    package = meta.ForeignKey(core.Package, db_column='package')
     
    2930    def __repr__(self):
    3031        return self.name
    3132
    32 class User(meta.Model):
     33
     34class UserUv2Constants(object):
     35    """Constants for the UserUv2 class.
     36    """
     37    TYPE_DISTRIBUTOR = "D"
     38    TYPE_ADMINISTRATOR = "A"
     39    TYPE_PROCESSOR = "P"
     40
     41
     42class UserUv2(UserUv2Constants):
     43    """Base class for adding our custom fields to the django user model.
     44    This model is inherited by django.models.auth.User
     45    """
     46    def get_payee(self):
     47        """Returns this user's Payee object.
     48        Returns None if this user is not associated with a payee.
     49        """
     50        try:
     51            from django.models.uv2 import payees
     52            return payees.get_object(u__id__exact=self.id)
     53        except:
     54            return None
     55
     56    def get_person(self):
     57        """Returns this user's Person object.
     58        Returns None if this user is not associated with a person.
     59        """
     60        try:
     61            from django.models.uv2 import persons
     62            return persons.get_object(u__id__exact=self.id)
     63        except:
     64            return None
     65
     66    def get_address(self):
     67        """Returns this user's Address object.
     68        Returns None if this user is not associated with an address.
     69        """
     70        try:
     71            from django.models.uv2 import addresses
     72            return addresses.get_object(u__id__exact=self.id)
     73        except:
     74            return None
     75
     76    def get_type(self):
     77        """Returns the type of user this is.
     78        Looks up the type in our persons table.
     79        Returns None if this user is not associated with a person.
     80        """
     81        try:
     82            p = self.get_person()
     83            return p.type
     84        except:
     85            return None
     86
     87    def is_distributor(self):
     88        """Returns true if this user is a uv2 Distributor.
     89        Returns None if this user is not associated with a person.
     90        """
     91        try:
     92            return self.get_type() == self.TYPE_DISTRIBUTOR
     93        except:
     94            return None
     95   
     96    def is_processor(self):
     97        """Returns true if this user is a uv2 Processor.
     98        Returns None if this user is not associated with a person.
     99        """
     100        try:
     101            return self.get_type() == self.TYPE_PROCESSOR
     102        except:
     103            return None
     104   
     105   
     106    def is_administrator(self):
     107        """Returns true if this user is a uv2 Administrator.
     108        Returns None if this user is not associated with a person.
     109        """
     110        try:
     111            return self.get_type() == self.TYPE_ADMINISTRATOR
     112        except:
     113            return None
     114   
     115   
     116    class META:
     117        no_table = True
     118
     119
     120class User(meta.Model, UserUv2):
    33121    username = meta.CharField(_('username'), maxlength=30, unique=True, validator_list=[validators.isAlphaNumeric])
    34122    first_name = meta.CharField(_('first name'), maxlength=30, blank=True)
    35123    last_name = meta.CharField(_('last name'), maxlength=30, blank=True)
     
    66154
    67155    def __repr__(self):
    68156        return self.username
     157        #return "User is a distributor: %s" % self.is_distributor()
    69158
    70159    def get_absolute_url(self):
    71160        return "/users/%s/" % self.username
  • django/core/meta/__init__.py

     
    625625        # attribute order.
    626626        fields.sort(lambda x, y: x.creation_counter - y.creation_counter)
    627627
     628        # Should this class generate database tables (Default is Yes)?
     629        # This has the ultimate effect of keeping this class out of the _MODELS
     630        # list.
     631        create_table = not (meta_attrs.pop('no_table', False))
     632
    628633        # If this model is a subclass of another model, create an Options
    629634        # object by first copying the base class's _meta and then updating it
    630635        # with the overrides from this class.
     
    889894            # contain this list:
    890895            # [<class 'django.models.polls.Poll'>, <class 'django.models.polls.Choice'>]
    891896            # Don't do this if replaces_module is set.
    892             app_package.__dict__.setdefault('_MODELS', []).append(new_class)
     897            # Exclude models where the user has set 'no_table = True'
     898            if create_table:
     899                app_package.__dict__.setdefault('_MODELS', []).append(new_class)
    893900
    894901        # Cache the app label.
    895902        opts.app_label = app_label
     
    938945    def __repr__(self):
    939946        return '<%s object>' % self.__class__.__name__
    940947
     948
    941949############################################
    942950# HELPER FUNCTIONS (CURRIED MODEL METHODS) #
    943951############################################
     
    10271035        if opts.has_auto_field and not pk_set:
    10281036            setattr(self, opts.pk.attname, db.get_last_insert_id(cursor, opts.db_table, opts.pk.column))
    10291037    db.db.commit()
     1038   
     1039    # Update the auto_now and auto_now_add fields to the values just inserted
     1040    # into the database
     1041    i = 0
     1042    for f in non_pks:
     1043        if isinstance(f, DateField):
     1044            if f.auto_now or (f.auto_now_add and not record_exists):
     1045                setattr(self, f.attname, db_values[i])
     1046        i += 1
     1047
    10301048    # Run any post-save hooks.
    10311049    if hasattr(self, '_post_save'):
    10321050        self._post_save()
  • django/core/template/loader.py

     
    103103        context_instance = Context(dictionary)
    104104    return t.render(context_instance)
    105105
     106def render_to_file(template_name, file_path, mode='w', dictionary=None, context_instance=None):
     107    """
     108    Loads the given template_name and renders it, with the given dictionary as
     109    context, to a file on disk.  The template_name may be a string to load a
     110    single template using get_template, or it may be a tuple to use
     111    select_template to find one of the templates in the list.  file_path defines
     112    the file that will be written to disk.  mode defaults to 'w' which will
     113    create the file if it doesn't exist and will overwrite the file if it does
     114    exist.
     115    """
     116    f = open(file_path, mode)
     117    f.write(render_to_string(template_name, dictionary, context_instance))
     118    f.close()
     119
    106120def select_template(template_name_list):
    107121    "Given a list of template names, returns the first that can be loaded."
    108122    for template_name in template_name_list:
  • docs/db-api.txt

     
    173173    in           In a given list: ``polls.get_list(id__in=[1, 3, 4])`` returns
    174174                 a list of polls whose IDs are either 1, 3 or 4.
    175175    startswith   Case-sensitive starts-with:
    176                  ``polls.get_list(question_startswith="Would")``. (PostgreSQL
     176                 ``polls.get_list(question__startswith="Would")``. (PostgreSQL
    177177                 and MySQL only. SQLite doesn't support case-sensitive LIKE
    178178                 statements; ``startswith`` will act like ``istartswith`` for
    179179                 SQLite.)
Back to Top