def __init__(self, **kwargs): View.__init__(self, **kwargs) self.result = {"status": "error", "data": {}, "error": ""} self.item = list( filter(lambda x: x.startswith("api_"), dir(self))) # 过滤dir(self)当中所有以“api_”开头的方法 ,通过get函数的内部去调试 self.dict = CMDBApi.__dict__ # 获取该类所有的方法名称和方法本身
def test_save_syntax_highlighting_disabled(self): """Testing AccountSettingsForm.save() with diffviewer_syntax_highlighting disabled """ view = View() user = User.objects.get(username='******') profile = user.get_profile() profile.syntax_highlighting = True profile.save(update_fields=('syntax_highlighting', )) request = self._build_request(user) page = AccountSettingsPage(view, request, user) settings = {'diffviewer_syntax_highlighting': False} with self.siteconfig_settings(settings): form = AccountSettingsForm(page, request, user, data={ 'syntax_highlighting': False, 'timezone': profile.timezone, }) self.assertTrue(form.is_valid()) form.save() profile = Profile.objects.get(pk=profile.pk) self.assertTrue(profile.syntax_highlighting)
def dispatch(self, request, *args, **kwargs): if request.user.is_authenticated: if request.user.is_admin: return View.dispatch(self, request, *args, **kwargs) else: return HttpResponseRedirect('client_side:home') else: return HashAuthView.dispatch(self, request, *args, **kwargs)
def dispatch(self, request, *args, **kwargs): if request.user.is_authenticated: if request.user.is_admin: return View.dispatch(self, request, *args, **kwargs) else: return Response(status=status.HTTP_403_FORBIDDEN) else: return HashAuthView.dispatch(self, request, *args, **kwargs)
def serialize_for_json(self, request, response): """Return a JSON-serializable representation of the response.""" # Test if response is already serializable. If so, keep it as is try: json.dumps(response) except TypeError as e: pass else: return response # If response is a dictionary, serialize its values if isinstance(response, dict): for key in response: response[key] = self.serialize_for_json(request, response[key]) return response # If response is a Django Model, try to delegate to its API view. if isinstance(response, Model): View = RESTAPI.get_view_by_model(response.__class__) if View is not None: return self.serialize_for_json(request, View().describe_entity(request, response)) # Try serializing it as an iterable object try: it = iter(response) except TypeError: pass else: return [self.serialize_for_json(request, elem) for elem in it] # Try serializing it as an object with a describe function if callable(getattr(response, 'describe', None)): response = self.serialize_for_json(request, response.describe()) # Test the serialization again, if it fails cast it to a string try: json.dumps(response) except TypeError as e: return str(response) else: return response
def __init__(self): View.__init__(self) self.DMHYFunction = DMHYFunction()
from django.urls import include, path from django.views.generic.base import View urlpatterns = [ path(r"edc_data_manager/", include("edc_data_manager.urls")), path(r"edc_pharmacy/", include("edc_pharmacy.urls")), path(r"edc_lab/", include("edc_lab.urls")), path(r"edc_locator/", include("edc_locator.urls")), path(r"edc_device/", include("edc_device.urls")), path(r"edc_adverse_event/", include("edc_adverse_event.urls")), path(r"edc_visit_schedule/", include("edc_visit_schedule.urls")), path(r"edc_navbar/", include("edc_navbar.urls")), path(r"edc_navbar/", include("edc_consent.urls")), path(r"edc_navbar/", include("edc_protocol.urls")), path(r"edc_adverse_event/", include("edc_adverse_event.urls")), path(r"edc_dashboard/", include("edc_dashboard.urls")), path(r"edc_export/", include("edc_export.urls")), path(r"", View.as_view(), name="navbar_one_url"), path(r"", View.as_view(), name="navbar_two_url"), path(r"", View.as_view(), name="logout"), path(r"", View.as_view(), name="administration_url"), path(r"", View.as_view(), name="home_url"), ]
from django.conf.urls import patterns, url from django.views.generic.base import View urlpatterns = patterns('', url(r'^$', View.as_view(), name="landing"), url(r'^(?P<page>[\w-]+)$', View.as_view(), name="wiki-page"), url(r'^(?P<category>[\w-]+)/(?P<page>[\w-]+)$', View.as_view(), name="wiki-category-page"), )
from django.conf.urls import url from django.views.generic.base import View urlpatterns = [ url(r'^test/$', View.as_view(), name='a_namespaced_url'), ]
def dispatch(self, request, *args, **kwargs): return View.dispatch(self, request, *args, **kwargs)
def dispatch(self, request, *args, **kwargs): self.setup(request) return View.dispatch(self, request, *args, **kwargs)
def __init__(self, **kwargs): View.__init__(self, **kwargs) self.boundary = "--BOUNDARY--==--%s" % str(uuid.uuid4())
from django.urls.conf import path, re_path from django.views.generic.base import View from edc_dashboard import url_names from .admin import edc_model_wrapper_admin app_name = "edc_model_wrapper" urlpatterns = [ path("admin/", edc_model_wrapper_admin.urls), re_path(r"^listboard/(?P<f2>.)/(?P<f3>.)/", View.as_view(), name="listboard_url"), re_path( r"^listboard/(?P<example_identifier>.)/(?P<example_log>.)/", View.as_view(), name="listboard_url", ), re_path(r"^listboard/", View.as_view(), name="listboard_url"), ] url_names.register("listboard_url", "listboard_url", "edc_model_wrapper")
from django.conf.urls import url, include from django.views.generic.base import View urlpatterns = [ url(r'^unnamed_path/$', View.as_view()), url(r'^named_path/$', View.as_view(), name='a_url_name'), url(r'^namespaced_path/', include('fdjangodog.tests.namespaced_urls', namespace="a_namespace")), ]
def dispatch(self, request, *args, **kwargs): """ Handle Cross-Site Request Forgery """ return View.dispatch(self, request, *args, **kwargs)
from django.test import TestCase from django.test.utils import override_settings from django.conf.urls import url, include from django.views.generic.base import View from django.test.client import RequestFactory from django.http import QueryDict from django.template import Template, RequestContext from ..builtins import (get_item, active_path, active_query, query, query_toggle, percentage, currency, intcurrency, humanize_time, active_query_by_key, query_by_key, query_toggle_by_key, to_json) nested_patterns = [ url(r'^$', View.as_view(), name="view"), url(r'^bar/$', View.as_view(), name="sub-view"), url(r'^baz/$', View.as_view(), name="sub-view-2"), url(r'^baz/(?P<id>[0-9]+)/$', View.as_view(), name="sub-view-id") ] urlpatterns = [url(r'^foo/', include(nested_patterns, namespace="namespace"))] class GetItemTestCase(TestCase): def test_get_item(self): dictionary = {'a': 1, 'b': 2} self.assertEquals(get_item(dictionary, 'a'), 1) self.assertEquals(get_item(dictionary, 'b'), 2) @override_settings(ROOT_URLCONF=__name__)
def dispatch(self, request, *args, **kwargs): if request.method.lower() not in ['post', 'get']: return self.xml_response_for_json( self.error_response(msg='Method Not Allowed')) return View.dispatch(self, request, *args, **kwargs)
from django.urls import path from django.views.generic.base import View from django.conf import settings if settings.APP_NAME == 'edc_navbar': # needed for tests app_name = 'edc_navbar' urlpatterns = [ path(r'one/', View.as_view(), name='navbar_one_url'), path(r'two/', View.as_view(), name='navbar_two_url'), path(r'logout', View.as_view(), name='logout_url'), path(r'administration', View.as_view(), name='administration_url'), path(r'', View.as_view(), name='home_url'), ]
def dispatch(self, request, *args, **kwargs): self.service = None return View.dispatch(self, request, *args, **kwargs)
from django.conf.urls import include, patterns, url from django.contrib import admin from django.contrib.staticfiles.urls import staticfiles_urlpatterns from django.views.generic.base import View from urlographer.views import route admin.autodiscover() urlpatterns = patterns( '', url(r'^admin/', include(admin.site.urls)), (r'^test_page/$', View.as_view()), (r'^.*$', route), ) urlpatterns += staticfiles_urlpatterns()
from django.conf.urls import patterns, url, include from django.conf import settings from django.views.generic.base import View urlpatterns = patterns("", url(r"^Ticket/Display.html\?id=(?P<id>\d+)$", View.as_view(), name="ticket-detail"))
from django.views.generic.base import View from django.urls.conf import re_path app_name = 'edc_model_wrapper' urlpatterns = [ re_path(r'^listboard/(?P<f2>.)/(?P<f3>.)/', View.as_view(), name='listboard_url'), re_path(r'^listboard/(?P<example_identifier>.)/(?P<example_log>.)/', View.as_view(), name='listboard_url'), re_path(r'^listboard/', View.as_view(), name='listboard_url') ]
) from datamap.views.plotting import ( BokehJS, ) from datamap.views.field import ( FieldListView, FieldAllowableListView, FieldByConceptListView, FieldAllowableByConceptListView, FieldView, AddFieldView, EditFieldView, ) urlpatterns = patterns( '', url(r'^(?P<dm>\d+)/field/(?P<pk>\d+)/$', FieldView.as_view(), name='datamap_field'), url(r'^(?P<dm>\d+)/field/edit/(?P<pk>\d+)/$', EditFieldView.as_view(), name='datamap_field_edit'), url(r'^(?P<dm>\d+)/field/edit/$', AddFieldView.as_view(), name='datamap_field_add'), url(r'^(?P<pk>\d+)/$', DatamapView.as_view(), name='datamap',), url(r'^edit/(?P<pk>\d+)/$', DatamapEditView.as_view(), name='datamap_edit',), # nopep8 url(r'^edit/$', DatamapAddView.as_view(), name='datamap_add',), url(r'^bokeh/$', View.as_view(), name='bokeh',), url(r'^bokeh/(?P<uuid>.+).embed.js', BokehJS.as_view(), name='bokehjs',), url(r'^field/$', FieldListView.as_view(), name='field_list',), url(r'^field/(?P<pk>\d+)/$', FieldByConceptListView.as_view(), name='field_by_concept',), url(r'^fieldallowable/$', FieldAllowableListView.as_view(), name='field_allowable_list',), url(r'^fieldallowable/(?P<pk>\d+)/$', FieldAllowableByConceptListView.as_view(), name='field_allowable_by_concept',), url(r'^$', DatamapListView.as_view(), name='datamap_list',), )
def _register_installed_apps_views(self, apps, with_app=False): ''' Set the routes for all of the installed apps (except the django.* installed apps). Will search through each module in the installed app and will look for a view class. If a views.py module is found, any functions found in the module will also be given a routing table by default. Each route will, by default, be of the value <module_name>.<view_name>. If you are worried about view names overlapping between apps, then use the with_app flag set to true and routes will be of the variety of <app_name>.<module_name>.<view_name>. The path after the base route will provide positional arguments to the url class for anything between the forward slashes (ie. /). For example, say you have view inside a module called foo, your route table would include a route as follows: ^foo/view_name/(?([^/]*)/)* Note that view functions that are not class-based must be included in the top-level directory of an app in a file called views.py if they are to be included. This does not make use of the Django app loader, so it is safe to put models in files outside of the models.py, as long as those views are class-based. Note that class-based views must also not require any parameters in the initialization of the view. To prevent select views from not being registered in this manner, set the register_route variable on the view to False. All functions within a views.py module are also added with this view. That means that any decorators will also have their own views. If this is not desired behavior, then set the settings.REGISTER_VIEWS_PY_FUNCS to False. @param apps: the INSTALLED_APPS setting in the settings for your Django app. @param with_app: set to true if you want the app name to be included in the route ''' view_inst = View() def add_func(app, mod, funcName, func): r = "{}/{}/([^\s#?]*)".format(mod, funcName) if with_app: r = "{}/{}".format(app, r.lstrip('/')) self.add(r.lower(), func, add_ending=False) def load_views(mod, mod_name, parent_mod_name=""): if parent_mod_name: name_mod = parent_mod_name + '/' + mod_name else: name_mod = mod_name for klass in inspect.getmembers(mod, inspect.isclass): try: try: inst = klass[1]() except AttributeError: continue #object is perhaps a model object if isinstance(inst, View) and type(inst) != type( view_inst): #we do not want to add the View class if not hasattr(inst, 'register_route') or ( hasattr(inst, 'register_route') and inst.register_route): add_func(app, name_mod, klass[0], klass[1].as_view()) if hasattr(inst, 'routes'): self.add_view(klass[1]) except TypeError as e: #not a View class if init requires input. if "'function' object is not subscriptable" in str(e): raise ValueError("Attempting to do something wrong") if 'string indices must be integers' in str(e): raise TypeError from e except ValueError as e: print(e) if mod_name == "views" and (hasattr(settings, 'REGISTER_VIEWS_PY_FUNCS') and settings.REGISTER_VIEWS_PY_FUNCS): for func in inspect.getmembers(mod, inspect.isfunction): add_func(app, name_mod, func[0], func[1]) def load_module(mod, pkg, path=""): ''' Load the module and get all of the modules in it. ''' print("The module and pkg of the load_module:", mod, pkg, path) loaded_app = il.import_module('.' + mod, pkg) for finder, mname, ispkg in pkgutil.walk_packages( [loaded_app.__path__[0]]): if ispkg: load_module(mname, loaded_app.__package__, path + '/' + mod) views_mod = il.import_module('.' + mname, loaded_app.__package__) load_views( views_mod, mname, path + '/' + mod) #Check if the module itself has any view classes for app in settings.INSTALLED_APPS: app_name = app.split('.')[-1] # print() # print("the app: " + app_name) if 'django' != app.split('.')[0]: #only do it for non-django apps loaded_app = il.import_module(app) # print("Loaded app path: ", loaded_app.__path__[0]) for finder, mname, ispkg in pkgutil.walk_packages( [loaded_app.__path__[0]]): if ispkg: load_module(mname, loaded_app.__package__) else: mod = il.import_module('.' + mname, loaded_app.__package__) load_views(mod, mname)
DatamapView.as_view(), name='datamap', ), url( r'^edit/(?P<pk>\d+)/$', DatamapEditView.as_view(), name='datamap_edit', ), # nopep8 url( r'^edit/$', DatamapAddView.as_view(), name='datamap_add', ), url( r'^bokeh/$', View.as_view(), name='bokeh', ), url( r'^bokeh/(?P<uuid>.+).embed.js', BokehJS.as_view(), name='bokehjs', ), url( r'^field/$', FieldListView.as_view(), name='field_list', ), url( r'^field/(?P<pk>\d+)/$', FieldByConceptListView.as_view(),