mirror of
https://github.com/django/django.git
synced 2025-11-24 21:00:12 +00:00
Replaced and...or... constructs with PEP 308 conditional expressions.
This commit is contained in:
parent
d228c1192e
commit
0fa8d43e74
25 changed files with 37 additions and 39 deletions
|
|
@ -216,7 +216,7 @@ class RelatedFieldListFilter(FieldListFilter):
|
|||
}
|
||||
|
||||
FieldListFilter.register(lambda f: (
|
||||
hasattr(f, 'rel') and bool(f.rel) or
|
||||
bool(f.rel) if hasattr(f, 'rel') else
|
||||
isinstance(f, models.related.RelatedObject)), RelatedFieldListFilter)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ class AdminField(object):
|
|||
classes.append('required')
|
||||
if not self.is_first:
|
||||
classes.append('inline')
|
||||
attrs = classes and {'class': ' '.join(classes)} or {}
|
||||
attrs = {'class': ' '.join(classes)} if classes else {}
|
||||
return self.field.label_tag(contents=mark_safe(contents), attrs=attrs)
|
||||
|
||||
def errors(self):
|
||||
|
|
@ -144,7 +144,7 @@ class AdminReadonlyField(object):
|
|||
# {{ field.name }} must be a useful class name to identify the field.
|
||||
# For convenience, store other field-related data here too.
|
||||
if callable(field):
|
||||
class_name = field.__name__ != '<lambda>' and field.__name__ or ''
|
||||
class_name = field.__name__ if field.__name__ != '<lambda>' else ''
|
||||
else:
|
||||
class_name = field
|
||||
self.field = {
|
||||
|
|
|
|||
|
|
@ -53,4 +53,4 @@ def get_admin_log(parser, token):
|
|||
if tokens[4] != 'for_user':
|
||||
raise template.TemplateSyntaxError(
|
||||
"Fourth argument to 'get_admin_log' must be 'for_user'")
|
||||
return AdminLogNode(limit=tokens[1], varname=tokens[3], user=(len(tokens) > 5 and tokens[5] or None))
|
||||
return AdminLogNode(limit=tokens[1], varname=tokens[3], user=(tokens[5] if len(tokens) > 5 else None))
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ def bookmarklets(request):
|
|||
admin_root = urlresolvers.reverse('admin:index')
|
||||
return render_to_response('admin_doc/bookmarklets.html', {
|
||||
'root_path': admin_root,
|
||||
'admin_url': "%s://%s%s" % (request.is_secure() and 'https' or 'http', request.get_host(), admin_root),
|
||||
'admin_url': "%s://%s%s" % ('https' if request.is_secure() else 'http', request.get_host(), admin_root),
|
||||
}, context_instance=RequestContext(request))
|
||||
|
||||
@staff_member_required
|
||||
|
|
@ -287,7 +287,7 @@ def template_detail(request, template):
|
|||
templates.append({
|
||||
'file': template_file,
|
||||
'exists': os.path.exists(template_file),
|
||||
'contents': lambda: os.path.exists(template_file) and open(template_file).read() or '',
|
||||
'contents': lambda: open(template_file).read() if os.path.exists(template_file) else '',
|
||||
'site_id': settings_mod.SITE_ID,
|
||||
'site': site_obj,
|
||||
'order': list(settings_mod.TEMPLATE_DIRS).index(dir),
|
||||
|
|
|
|||
|
|
@ -237,7 +237,7 @@ class PasswordResetForm(forms.Form):
|
|||
'uid': int_to_base36(user.pk),
|
||||
'user': user,
|
||||
'token': token_generator.make_token(user),
|
||||
'protocol': use_https and 'https' or 'http',
|
||||
'protocol': 'https' if use_https else 'http',
|
||||
}
|
||||
subject = loader.render_to_string(subject_template_name, c)
|
||||
# Email subject *must not* contain newlines
|
||||
|
|
|
|||
|
|
@ -384,7 +384,7 @@ class GEOSGeometry(GEOSBase, ListMixin):
|
|||
@property
|
||||
def wkt(self):
|
||||
"Returns the WKT (Well-Known Text) representation of this Geometry."
|
||||
return wkt_w(self.hasz and 3 or 2).write(self).decode()
|
||||
return wkt_w(3 if self.hasz else 2).write(self).decode()
|
||||
|
||||
@property
|
||||
def hex(self):
|
||||
|
|
@ -395,7 +395,7 @@ class GEOSGeometry(GEOSBase, ListMixin):
|
|||
"""
|
||||
# A possible faster, all-python, implementation:
|
||||
# str(self.wkb).encode('hex')
|
||||
return wkb_w(self.hasz and 3 or 2).write_hex(self)
|
||||
return wkb_w(3 if self.hasz else 2).write_hex(self)
|
||||
|
||||
@property
|
||||
def hexewkb(self):
|
||||
|
|
@ -407,7 +407,7 @@ class GEOSGeometry(GEOSBase, ListMixin):
|
|||
if self.hasz and not GEOS_PREPARE:
|
||||
# See: http://trac.osgeo.org/geos/ticket/216
|
||||
raise GEOSException('Upgrade GEOS to 3.1 to get valid 3D HEXEWKB.')
|
||||
return ewkb_w(self.hasz and 3 or 2).write_hex(self)
|
||||
return ewkb_w(3 if self.hasz else 2).write_hex(self)
|
||||
|
||||
@property
|
||||
def json(self):
|
||||
|
|
@ -427,7 +427,7 @@ class GEOSGeometry(GEOSBase, ListMixin):
|
|||
as a Python buffer. SRID and Z values are not included, use the
|
||||
`ewkb` property instead.
|
||||
"""
|
||||
return wkb_w(self.hasz and 3 or 2).write(self)
|
||||
return wkb_w(3 if self.hasz else 2).write(self)
|
||||
|
||||
@property
|
||||
def ewkb(self):
|
||||
|
|
@ -439,7 +439,7 @@ class GEOSGeometry(GEOSBase, ListMixin):
|
|||
if self.hasz and not GEOS_PREPARE:
|
||||
# See: http://trac.osgeo.org/geos/ticket/216
|
||||
raise GEOSException('Upgrade GEOS to 3.1 to get valid 3D EWKB.')
|
||||
return ewkb_w(self.hasz and 3 or 2).write(self)
|
||||
return ewkb_w(3 if self.hasz else 2).write(self)
|
||||
|
||||
@property
|
||||
def kml(self):
|
||||
|
|
|
|||
|
|
@ -546,7 +546,7 @@ class LayerMapping(object):
|
|||
# Attempting to save.
|
||||
m.save(using=self.using)
|
||||
num_saved += 1
|
||||
if verbose: stream.write('%s: %s\n' % (is_update and 'Updated' or 'Saved', m))
|
||||
if verbose: stream.write('%s: %s\n' % ('Updated' if is_update else 'Saved', m))
|
||||
except SystemExit:
|
||||
raise
|
||||
except Exception as msg:
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ class Sitemap(object):
|
|||
'location': loc,
|
||||
'lastmod': self.__get('lastmod', item, None),
|
||||
'changefreq': self.__get('changefreq', item, None),
|
||||
'priority': str(priority is not None and priority or ''),
|
||||
'priority': str(priority if priority is not None else ''),
|
||||
}
|
||||
urls.append(url_info)
|
||||
return urls
|
||||
|
|
|
|||
|
|
@ -245,7 +245,7 @@ def find(path, all=False):
|
|||
if matches:
|
||||
return matches
|
||||
# No match.
|
||||
return all and [] or None
|
||||
return [] if all else None
|
||||
|
||||
|
||||
def get_finders():
|
||||
|
|
|
|||
|
|
@ -175,11 +175,9 @@ Type 'yes' to continue, or 'no' to cancel: """
|
|||
summary = template % {
|
||||
'modified_count': modified_count,
|
||||
'identifier': 'static file' + ('' if modified_count == 1 else 's'),
|
||||
'action': self.symlink and 'symlinked' or 'copied',
|
||||
'destination': (destination_path and " to '%s'"
|
||||
% destination_path or ''),
|
||||
'unmodified': (collected['unmodified'] and ', %s unmodified'
|
||||
% unmodified_count or ''),
|
||||
'action': 'symlinked' if self.symlink else 'copied',
|
||||
'destination': (" to '%s'" % destination_path if destination_path else ''),
|
||||
'unmodified': (', %s unmodified' % unmodified_count if collected['unmodified'] else ''),
|
||||
'post_processed': (collected['post_processed'] and
|
||||
', %s post-processed'
|
||||
% post_processed_count or ''),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue