Changeset 7533
- Timestamp:
- 05/14/08 00:48:44 (2 months ago)
- Files:
-
- django/branches/newforms-admin (modified) (1 prop)
- django/branches/newforms-admin/django/db/backends/oracle/query.py (modified) (2 diffs)
- django/branches/newforms-admin/django/db/models/base.py (modified) (2 diffs)
- django/branches/newforms-admin/django/db/models/query.py (modified) (2 diffs)
- django/branches/newforms-admin/django/db/models/sql/query.py (modified) (1 diff)
- django/branches/newforms-admin/django/db/models/sql/where.py (modified) (1 diff)
- django/branches/newforms-admin/docs/request_response.txt (modified) (2 diffs)
- django/branches/newforms-admin/tests/modeltests/basic/models.py (modified) (1 diff)
- django/branches/newforms-admin/tests/regressiontests/queries/models.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/newforms-admin
- Property svnmerge-integrated changed from /django/trunk:1-4345,4350-4357,4359-4365,4371-4372,4374-4377,4380-4386,4388,4390-4391,4400-4402,4404-4408,4410,4412-4419,4426-4427,4430-4432,4434,4441,4443-4444,4446-4447,4450,4452-4453,4455-4458,4476,4503,4546,4564-4569,4580-4586,4617,4630,4641-6390,6392-7499 to /django/trunk:1-4345,4350-4357,4359-4365,4371-4372,4374-4377,4380-4386,4388,4390-4391,4400-4402,4404-4408,4410,4412-4419,4426-4427,4430-4432,4434,4441,4443-4444,4446-4447,4450,4452-4453,4455-4458,4476,4503,4546,4564-4569,4580-4586,4617,4630,4641-6390,6392-7532
django/branches/newforms-admin/django/db/backends/oracle/query.py
r7479 r7533 1 1 """ 2 Custom Query class for this backend (a derivative of3 django.db.models.sql.query.Query). 2 Custom Query class for Oracle. 3 Derives from: django.db.models.sql.query.Query 4 4 """ 5 5 … … 13 13 def query_class(QueryClass, Database): 14 14 """ 15 Returns a custom djang .db.models.sql.query.Query subclass that is16 appropr aite for Oracle.15 Returns a custom django.db.models.sql.query.Query subclass that is 16 appropriate for Oracle. 17 17 18 18 The 'Database' module (cx_Oracle) is passed in here so that all the setup django/branches/newforms-admin/django/db/models/base.py
r7479 r7533 235 235 dispatcher.send(signal=signals.post_init, sender=self.__class__, instance=self) 236 236 237 def from_sequence(cls, values):238 """239 An alternate class constructor, primarily for internal use.240 241 Creates a model instance from a sequence of values (which corresponds242 to all the non-many-to-many fields in creation order. If there are more243 fields than values, the remaining (final) fields are given their244 default values.245 246 ForeignKey fields can only be initialised using id values, not247 instances, in this method.248 """249 dispatcher.send(signal=signals.pre_init, sender=cls, args=values,250 kwargs={})251 obj = Empty()252 obj.__class__ = cls253 field_iter = iter(obj._meta.fields)254 for val, field in izip(values, field_iter):255 setattr(obj, field.attname, val)256 for field in field_iter:257 setattr(obj, field.attname, field.get_default())258 dispatcher.send(signal=signals.post_init, sender=cls, instance=obj)259 return obj260 261 from_sequence = classmethod(from_sequence)262 263 237 def __repr__(self): 264 238 return smart_str(u'<%s: %s>' % (self.__class__.__name__, unicode(self))) … … 362 336 dispatcher.send(signal=signals.post_save, sender=self.__class__, 363 337 instance=self, created=(not record_exists), raw=raw) 338 339 save_base.alters_data = True 364 340 365 341 def validate(self): django/branches/newforms-admin/django/db/models/query.py
r7500 r7533 165 165 max_depth, requested=requested) 166 166 else: 167 obj = self.model .from_sequence(row[index_start:])167 obj = self.model(*row[index_start:]) 168 168 for i, k in enumerate(extra_select): 169 169 setattr(obj, k, row[i]) … … 656 656 restricted = requested is not None 657 657 index_end = index_start + len(klass._meta.fields) 658 obj = klass .from_sequence(row[index_start:index_end])658 obj = klass(*row[index_start:index_end]) 659 659 for f in klass._meta.fields: 660 660 if (not f.rel or (not restricted and f.null) or django/branches/newforms-admin/django/db/models/sql/query.py
r7500 r7533 395 395 """ 396 396 qn = self.quote_name_unless_alias 397 result = ['(%s) AS %s' % (col, alias) for alias, col in self.extra_select.iteritems()] 397 qn2 = self.connection.ops.quote_name 398 result = ['(%s) AS %s' % (col, qn2(alias)) for alias, col in self.extra_select.iteritems()] 398 399 aliases = set(self.extra_select.keys()) 399 400 if with_aliases: django/branches/newforms-admin/django/db/models/sql/where.py
r7479 r7533 52 52 elif isinstance(child, tree.Node): 53 53 sql, params = self.as_sql(child, qn) 54 if len(child.children) == 1: 54 if child.negated: 55 format = 'NOT (%s)' 56 elif len(child.children) == 1: 55 57 format = '%s' 56 58 else: 57 59 format = '(%s)' 58 if child.negated:59 format = 'NOT %s' % format60 60 else: 61 61 sql, params = self.make_atom(child, qn) django/branches/newforms-admin/docs/request_response.txt
r7378 r7533 403 403 object. Doing so will raise ``Exception``. 404 404 405 Setting headers 406 ~~~~~~~~~~~~~~~ 407 408 To set a header in your response, just treat it like a dictionary:: 409 410 >>> response = HttpResponse() 411 >>> response['Pragma'] = 'no-cache' 412 413 Telling the browser to treat the response as a file attachment 414 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 415 416 To tell the browser to treat the response as a file attachment, use the 417 ``mimetype`` argument and set the ``Content-Disposition`` header. For example, 418 this is how you might return a Microsoft Excel spreadsheet:: 419 420 >>> response = HttpResponse(my_data, mimetype='application/vnd.ms-excel') 421 >>> response['Content-Disposition'] = 'attachment; filename=foo.xls' 422 423 There's nothing Django-specific about the ``Content-Disposition`` header, but 424 it's easy to forget the syntax, so we've included it here. 425 405 426 Methods 406 427 ------- … … 421 442 header, it can also include the character set encoding, which makes it 422 443 more than just a MIME type specification. If ``mimetype`` is specified 423 (not None), that value is used. Otherwise, ``content_type`` is used. If444 (not ``None``), that value is used. Otherwise, ``content_type`` is used. If 424 445 neither is given, the ``DEFAULT_CONTENT_TYPE`` setting is used. 425 446 django/branches/newforms-admin/tests/modeltests/basic/models.py
r7479 r7533 399 399 >>> Article.objects.get(headline='Article 11') in s 400 400 True 401 402 # The 'select' argument to extra() supports names with dashes in them, as long 403 # as you use values(). 404 >>> Article.objects.filter(pub_date__year=2008).extra(select={'dashed-value': '1'}).values('headline', 'dashed-value') 405 [{'headline': u'Article 11', 'dashed-value': 1}, {'headline': u'Article 12', 'dashed-value': 1}] 406 407 # If you use 'select' with extra() and names containing dashes on a query 408 # that's *not* a values() query, those extra 'select' values will silently be 409 # ignored. 410 >>> articles = Article.objects.filter(pub_date__year=2008).extra(select={'dashed-value': '1', 'undashedvalue': '2'}) 411 >>> articles[0].undashedvalue 412 2 401 413 """ django/branches/newforms-admin/tests/regressiontests/queries/models.py
r7500 r7533 121 121 class CustomManager(models.Manager): 122 122 def get_query_set(self): 123 return super(CustomManager, self).get_query_set().filter(public=True,124 tag__name='t1')123 qs = super(CustomManager, self).get_query_set() 124 return qs.filter(is_public=True, tag__name='t1') 125 125 126 126 class ManagedModel(models.Model): 127 127 data = models.CharField(max_length=10) 128 128 tag = models.ForeignKey(Tag) 129 public = models.BooleanField(default=True)129 is_public = models.BooleanField(default=True) 130 130 131 131 objects = CustomManager() … … 699 699 Updates that are filtered on the model being updated are somewhat tricky to get 700 700 in MySQL. This exercises that case. 701 >>> mm = ManagedModel.objects.create(data='mm1', tag=t1, public=True)701 >>> mm = ManagedModel.objects.create(data='mm1', tag=t1, is_public=True) 702 702 >>> ManagedModel.objects.update(data='mm') 703 703
