本文整理汇总了Python中django.conf.urls.url方法的典型用法代码示例。如果您正苦于以下问题:Python urls.url方法的具体用法?Python urls.url怎么用?Python urls.url使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.conf.urls
的用法示例。
在下文中一共展示了urls.url方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_urls
# 需要导入模块: from django.conf import urls [as 别名]
# 或者: from django.conf.urls import url [as 别名]
def get_urls(self):
urls = super(DocumentSetAdmin, self).get_urls()
extra_urls = patterns('',
url('^(?P<document_set_id>\d+)/answers/$',
self.admin_site.admin_view(self.answers_view),
name="document_set_answers_csv"),
url('^(?P<document_set_id>\d+)/add_documents/$',
self.admin_site.admin_view(self.add_documents_view),
name='document_set_add_documents'),
url('^(?P<document_set_id>\d+)/update_canons/$',
self.admin_site.admin_view(self.update_canons_view),
name='document_set_update_canons'),
url('^(?P<document_set_id>\d+)/reverify_documents/$',
self.admin_site.admin_view(self.reverify_documents_view),
name='document_set_reverify_documents')
)
return extra_urls + urls
示例2: answers
# 需要导入模块: from django.conf import urls [as 别名]
# 或者: from django.conf.urls import url [as 别名]
def answers(self, obj):
field_template = "<li><input type=\"checkbox\" data-change-url=\"%s\" data-field-entry=\"%d\" data-document=\"%d\" data-entry-value=\"%s\" %s><span class=\"%s\">%s</span>: <strong>%s</strong> - <em>%s</em></li>"
rv = '<ul>'
form_fields = obj.form.fields.order_by('id').all()
rv += ''.join([field_template % (reverse('admin:document_set_field_entry_change', args=(obj.document.pk, e.pk,)),
e.pk,
obj.document.pk,
e.value,
'checked' if e.verified else '',
'verify' if f.verify else '',
f.label,
e.value,
e.assigned_canonical_value())
for f, e in zip(form_fields,
obj.fields.order_by('field_id').all())])
rv += '</ul>'
return mark_safe(rv)
示例3: __init__
# 需要导入模块: from django.conf import urls [as 别名]
# 或者: from django.conf.urls import url [as 别名]
def __init__(self, name='xadmin'):
self.name = name
self.app_name = 'xadmin'
self._registry = {} # model_class class -> admin_class class
self._registry_avs = {} # admin_view_class class -> admin_class class
self._registry_settings = {} # settings name -> admin_class class
self._registry_views = []
# url instance contains (path, admin_view class, name)
self._registry_modelviews = []
# url instance contains (path, admin_view class, name)
self._registry_plugins = {} # view_class class -> plugin_class class
self._admin_view_cache = {}
# self.check_dependencies()
self.model_admins_order = 0
示例4: link_reminder
# 需要导入模块: from django.conf import urls [as 别名]
# 或者: from django.conf.urls import url [as 别名]
def link_reminder(self, request, queryset):
slack_users = slackapi.get_user_list()
by_email = {u.email: u.id for u in slack_users}
for sp in queryset.filter(is_active=True, player__slack_user_id='').select_related(
'player').nocache():
uid = by_email.get(sp.player.email)
if uid:
token = LoginToken.objects.create(slack_user_id=uid,
username_hint=sp.player.lichess_username,
expires=timezone.now() + timedelta(days=30))
url = reverse('by_league:login_with_token',
args=[sp.season.league.tag, token.secret_token])
url = request.build_absolute_uri(url)
text = 'Reminder: You need to link your Slack and Lichess accounts. <%s|Click here> to do that now. Contact a mod if you need help.' % url
slackapi.send_message(uid, text)
return redirect('admin:tournament_seasonplayer_changelist')
示例5: password_change
# 需要导入模块: from django.conf import urls [as 别名]
# 或者: from django.conf.urls import url [as 别名]
def password_change(self, request, extra_context=None):
"""
Handles the "change password" task -- both form display and validation.
"""
from django.contrib.admin.forms import AdminPasswordChangeForm
from django.contrib.auth.views import password_change
url = reverse('admin:password_change_done', current_app=self.name)
defaults = {
'current_app': self.name,
'password_change_form': AdminPasswordChangeForm,
'post_change_redirect': url,
'extra_context': dict(self.each_context(request), **(extra_context or {})),
}
if self.password_change_template is not None:
defaults['template_name'] = self.password_change_template
return password_change(request, **defaults)
示例6: get_urls
# 需要导入模块: from django.conf import urls [as 别名]
# 或者: from django.conf.urls import url [as 别名]
def get_urls(self):
from django.conf.urls import url
def wrap(view):
def wrapper(*args, **kwargs):
return self.admin_site.admin_view(view)(*args, **kwargs)
return update_wrapper(wrapper, view)
info = self.model._meta.app_label, self.model._meta.model_name
urlpatterns = [
url(r'^$', wrap(self.changelist_view), name='%s_%s_changelist' % info),
url(r'^add/$', wrap(self.add_view), name='%s_%s_add' % info),
url(r'^(.+)/history/$', wrap(self.history_view), name='%s_%s_history' % info),
url(r'^(.+)/delete/$', wrap(self.delete_view), name='%s_%s_delete' % info),
url(r'^(.+)/$', wrap(self.change_view), name='%s_%s_change' % info),
]
return urlpatterns
示例7: waliki_urls
# 需要导入模块: from django.conf import urls [as 别名]
# 或者: from django.conf.urls import url [as 别名]
def waliki_urls():
base = [url(r'^$', home, name='waliki_home'),
url(r'^_new$', new, name='waliki_new'),
url(r'^_get_slug$', get_slug, name='waliki_get_slug'),
url(r'^_preview$', preview, name='waliki_preview')]
for pattern in page_urls():
base.append(url(r'^', include(pattern)))
base += [url(r'^(?P<slug>' + WALIKI_SLUG_PATTERN + ')/edit$', edit, name='waliki_edit'),
url(r'^(?P<slug>' + WALIKI_SLUG_PATTERN + ')/delete$',
delete, name='waliki_delete'),
url(r'^(?P<slug>' + WALIKI_SLUG_PATTERN + ')/move$',
move, name='waliki_move'),
url(r'^(?P<slug>' + WALIKI_SLUG_PATTERN + ')/raw$',
detail, {'raw': True}, name='waliki_detail_raw'),
url(r'^(?P<slug>' + WALIKI_SLUG_PATTERN + ')$',
detail, name='waliki_detail'),
]
return base
示例8: add_handler
# 需要导入模块: from django.conf import urls [as 别名]
# 或者: from django.conf.urls import url [as 别名]
def add_handler(self, view, url_, actions):
class ActionHandler(view):
pass
for method, method_action in actions.items():
def create_action_method(action):
def action_method(inner_self, *args, **kwargs):
try:
inner_self.view.action = action
inner_self.before_dispatch()
response = inner_self.view.dispatch(action, *args, **kwargs)
return inner_self.write_response(response)
except Exception:
exc_type, exc, traceback = sys.exc_info()
response = inner_self.view.error_response(exc_type, exc, traceback)
return inner_self.write_response(response)
finally:
inner_self.on_finish()
return action_method
func = create_action_method(method_action)
setattr(ActionHandler, method, func)
self.urls.append(url(url_, ActionHandler.as_view()))
示例9: add_route_extra_actions
# 需要导入模块: from django.conf import urls [as 别名]
# 或者: from django.conf.urls import url [as 别名]
def add_route_extra_actions(self, view, route, prefix):
viewset = view.view_cls
for attr in dir(viewset):
method = getattr(viewset, attr)
bind_to_methods = getattr(method, 'bind_to_methods', None)
if bind_to_methods is None:
continue
detail = getattr(method, 'detail', None)
if detail != route['detail']:
continue
extra_actions = dict(map(lambda x: (x, attr), bind_to_methods))
url = '{}{}{}/'.format(prefix, route['path'], attr)
self.add_handler(view, url, extra_actions)
示例10: crud_for_model
# 需要导入模块: from django.conf import urls [as 别名]
# 或者: from django.conf.urls import url [as 别名]
def crud_for_model(model, urlprefix=None):
"""Returns list of ``url`` items to CRUD a model.
"""
model_lower = model.__name__.lower()
if urlprefix is None:
urlprefix = ''
urlprefix += model_lower + '/'
urls = crud_urls(
model,
list_view=CRUDListView.as_view(model=model),
create_view=CRUDCreateView.as_view(model=model),
detail_view=CRUDDetailView.as_view(model=model),
update_view=CRUDUpdateView.as_view(model=model),
delete_view=CRUDDeleteView.as_view(model=model),
url_prefix=urlprefix,
)
return urls
示例11: test_no_oidc_token_expiration_forces_renewal
# 需要导入模块: from django.conf import urls [as 别名]
# 或者: from django.conf.urls import url [as 别名]
def test_no_oidc_token_expiration_forces_renewal(self, mock_random_string):
mock_random_string.return_value = 'examplestring'
request = self.factory.get('/foo')
request.user = self.user
request.session = {}
response = self.middleware.process_request(request)
self.assertEqual(response.status_code, 302)
url, qs = response.url.split('?')
self.assertEqual(url, 'http://example.com/authorize')
expected_query = {
'response_type': ['code'],
'redirect_uri': ['http://testserver/callback/'],
'client_id': ['foo'],
'nonce': ['examplestring'],
'prompt': ['none'],
'scope': ['openid email'],
'state': ['examplestring'],
}
self.assertEqual(expected_query, parse_qs(qs))
示例12: setUp
# 需要导入模块: from django.conf import urls [as 别名]
# 或者: from django.conf.urls import url [as 别名]
def setUp(self):
self.url_patterns = patterns(
'',
url(r'a-view/$', MockApiView.as_view(), name='a test view'),
url(r'b-view$', MockApiView.as_view(), name='a test view'),
url(r'c-view/$', MockApiView.as_view(), name='a test view'),
url(r'a-view/child/?$', MockApiView.as_view()),
url(r'a-view/child2/?$', MockApiView.as_view()),
url(r'another-view/?$', MockApiView.as_view(),
name='another test view'),
url(r'view-with-param/(:?<ID>\d+)/?$', MockApiView.as_view(),
name='another test view'),
url(r'a-view-honky/?$', MockApiView.as_view(), name='a test view'),
)
self.urlparser = UrlParser()
示例13: test_format_api_patterns_url_import
# 需要导入模块: from django.conf import urls [as 别名]
# 或者: from django.conf.urls import url [as 别名]
def test_format_api_patterns_url_import(self):
urls = patterns('', url(r'api/base/path/', include(self.url_patterns)))
apis = self.urlparser.get_apis(urls)
self.assertEqual(len(self.url_patterns), len(apis))
示例14: test_format_api_patterns_excluded_namesapce
# 需要导入模块: from django.conf import urls [as 别名]
# 或者: from django.conf.urls import url [as 别名]
def test_format_api_patterns_excluded_namesapce(self):
urls = patterns(
'',
url(r'api/base/path/',
include(self.url_patterns, namespace='exclude'))
)
apis = self.urlparser.format_api_patterns(
url_patterns=urls, exclude_namespaces='exclude')
self.assertEqual([], apis)
示例15: test_format_api_patterns_url_import_with_routers
# 需要导入模块: from django.conf import urls [as 别名]
# 或者: from django.conf.urls import url [as 别名]
def test_format_api_patterns_url_import_with_routers(self):
class MockApiViewSet(ModelViewSet):
serializer_class = CommentSerializer
model = User
queryset = User.objects.all()
class AnotherMockApiViewSet(ModelViewSet):
serializer_class = CommentSerializer
model = User
queryset = User.objects.all()
router = DefaultRouter()
router.register(r'other_views', MockApiViewSet, base_name='test_base_name')
router.register(r'more_views', AnotherMockApiViewSet, base_name='test_base_name')
urls_app = patterns('', url(r'^', include(router.urls)))
urls = patterns(
'',
url(r'api/', include(urls_app)),
url(r'test/', include(urls_app))
)
apis = self.urlparser.get_apis(urls)
self.assertEqual(
4, sum(api['path'].find('api') != -1 for api in apis))
self.assertEqual(
4, sum(api['path'].find('test') != -1 for api in apis))