我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用django.template.defaultfilters.title()。
def get_context_data(self, **kwargs): opts = self.model._meta app_label = opts.app_label model_name = opts.model_name kwargs.update({ 'mode': self.mode, 'opts': opts, 'has_add_permission': self.has_add_permission(), 'has_change_permission': self.has_edit_permission(), 'has_delete_permission': self.has_delete_permission(), 'to_field_var': TO_FIELD_VAR, 'is_popup_var': IS_POPUP_VAR, 'app_label': app_label, 'model_name': model_name, 'title': _(self.mode_title), # 'to_field': to_field, # errors=helpers.AdminErrorList(form, formsets), # preserved_filters=self.get_preserved_filters(request), 'is_popup': (IS_POPUP_VAR in self.request.POST or IS_POPUP_VAR in self.request.GET) }) return super(ControllerMixin, self).get_context_data(**kwargs)
def is_proper_title(value): if value and value != title(value): raise ValidationError('Incorrect title')
def get_label(self): from cms.utils.placeholder import get_placeholder_conf name = get_placeholder_conf("name", self.slot, default=title(self.slot)) name = _(name) return name
def title(value): ''' A slightly better title template filter. Same as Django's builtin `~django.template.defaultfilters.title` filter, but operates on individual words and leaves words unchanged if they already have a capital letter. ''' def title_word(w): return w if RE_UPPERCASE.search(w) else old_title(w) return re.sub('(\S+)', lambda m: title_word(m.group(0)), value)
def get_title(self): if self.mode == 'list': return _('all {}'.format(self.controller.opts.verbose_name_plural)) else: obj = getattr(self, 'object', None) return ('{} {}'.format(title(self.mode_title), obj) if obj else title('{} {}'.format(self.mode_title, self.controller.opts.verbose_name)))
def handle(self, *args, **options): members_xml = requests.get('{prefix}{key}/'.format(prefix=API_PREFIX, key=settings.UNION_API_KEY)) members_root = fromstring(members_xml.text.encode('utf-8')) active_members = [] # Add any new members for member in members_root: try: if member.find('UniqueID').text: current_member = User.objects.get(username=member.find('UniqueID').text) active_members.append(current_member.id) except User.DoesNotExist: # Create the user and then email their password to them password = User.objects.make_random_password() new_user = User.objects.create_user(username=member.find('UniqueID').text, email=member.find('EmailAddress').text, password=password) new_user.first_name = title(member.find('FirstName').text.encode('utf-8')) new_user.last_name = title(member.find('LastName').text.encode('utf-8')) new_user.save() send_signup_mail(new_user, password) active_members.append(new_user.id) # Handle special cases with Ex-exec, exec and staff/superuser status for member in User.objects.all(): if member.groups.filter(name__in=['Ex-exec', 'Exec']).exists(): if member not in active_members: active_members.append(member.id) elif member.is_staff or member.is_superuser: if member not in active_members: active_members.append(member.id) # Ensure all accounts that are to be activate are so activated = User.objects.filter(id__in=active_members).all() activated.update(is_active=True) # Deactivate old accounts deactivated = User.objects.exclude(id__in=active_members).all() deactivated.update(is_active=False)