Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1""" 

2 

3Abstract 

4--------- 

5 

6The apps within a project often require the creation of AJAX views. These may be ad hoc or part of a more organized 

7structure. SuperDjango's AJAX app provides a simple interface for registering AJAX views across a project. 

8 

9Install 

10------- 

11 

12Update project settings: 

13 

14.. code-block:: python 

15 

16 # settings.py 

17 INSTALLED_APPS = [ 

18 # ... 

19 "superdjango.interfaces.ajax.apps.AutoConfig", 

20 # ... 

21 ] 

22 

23 # Default module name is ajax. 

24 SUPERDJANGO_AJAX_MODULE_NAME = "ajax" 

25 

26If you wish to manually manage an AJAX registry, use ``superdjango.ajax.apps.DefaultConfig`` instead. 

27 

28Utilize the URLs: 

29 

30.. code-block:: python 

31 

32 # main/urls.py 

33 from superdjango.interfaces.ajax import ajax 

34 

35 urlpatterns = [ 

36 # ... 

37 path('ajax/', include(ajax.get_urls())), 

38 # ... 

39 ] 

40 

41Usage 

42----- 

43 

44Create your AJAX views as normal, utilizing a viewset to capture the views within your app: 

45 

46.. code-block:: python 

47 

48 # views.py 

49 from superdjango.views import GenericView, JSONMixin, ViewSet 

50 

51 class SomeAjaxCall(JSONMixin, GenericView): 

52 # ... 

53 

54 class SomeOtherAjaxCall(JSONMixin, GenericView): 

55 # ... 

56 

57 class MyAjaxViewSet(ViewSet): 

58 views = [ 

59 SomeAjaxCall, 

60 SomeOtherAjaxCall, 

61 ] 

62 

63 # ajax.py 

64 from superdjango.ajax import ajax 

65 from .views import MyAjaxViewSet 

66 

67 ajax.register("myapp", MyAjaxViewSet) 

68 

69You could, of course, home your AJAX views in the ``views.py`` of your app instead of the ``ajax.py``. 

70 

71""" 

72from django.conf import settings 

73from django.utils.module_loading import autodiscover_modules 

74from .interfaces import ajax 

75 

76__author__ = "Shawn Davis <shawn@superdjango.com>" 

77__maintainer__ = "Shawn Davis <shawn@superdjango.com>" 

78__version__ = "0.5.0-x" 

79 

80__all__ = ( 

81 "ajax", 

82) 

83 

84API_MODULE_NAME = getattr(settings, "SUPERDJANGO_AJAX_MODULE_NAME", "ajax") 

85 

86 

87def autodiscover(): 

88 """Automatically find (and load) ``ajax.py`` files located in installed Django apps.""" 

89 autodiscover_modules(API_MODULE_NAME) 

90 

91 

92default_app_config = "superdjango.interfaces.ajax.apps.DefaultConfig"