コード例 #1
0
ファイル: sites.py プロジェクト: flamingtarball/bambu-tools
	def docs_app_view(self, request, app_label):
		from django.template.response import TemplateResponse
		
		apis = []
		app_title = app_label.replace('_', ' ').capitalize()
		
		for model in self._registry.keys():
			if model._meta.app_label == app_label:
				opts = model._meta
				api = self._registry[model]
				
				apis.append(
					{
						'title': unicode(opts.verbose_name_plural.capitalize()),
						'doc': helpers.trim_indent(api.__doc__),
						'url': '%s/' % opts.module_name
					}
				)
				
				if hasattr(api, 'app_label_verbose'):
					app_title = api.app_label_verbose
				
		if not any(apis):
			raise Http404('App not found.')
		
		return TemplateResponse(
			request,
			(
				'api/doc/%s/index.html' % app_label,
				'api/doc/app_index.html'
			),
			{
				'title_parts': (
					app_title,
					'Developer resources'
				),
				'breadcrumb_trail': (
					('../', u'Developer resources'),
					('', app_title)
				),
				'resources': self._docs_list(),
				'name': app_title,
				'apis': apis,
				'apps_supported': not self.auth.app_model is None,
				'body_classes': ('api', 'api-docs-app')
			}
		)
コード例 #2
0
ファイル: sites.py プロジェクト: iselu/bambu-tools
    def docs_index_view(self, request):
        from django.template.response import TemplateResponse

        return TemplateResponse(
            request, 'api/doc/index.html', {
                'title_parts': (DOCS_TITLE, ),
                'breadcrumb_trail': (('', DOCS_TITLE), ),
                'resources':
                self._docs_list(),
                'auth': {
                    'name': self.auth.verbose_name,
                    'doc': helpers.trim_indent(self.auth.__doc__)
                },
                'apps_supported':
                not self.auth.app_model is None
                and getattr(settings, 'API_APPS_MANAGEABLE', True),
                'body_classes': ('api', 'api-docs-index')
            })
コード例 #3
0
ファイル: sites.py プロジェクト: iselu/bambu-tools
    def docs_app_view(self, request, app_label):
        from django.template.response import TemplateResponse

        apis = []
        app_title = app_label.replace('_', ' ').capitalize()

        for model in self._registry.keys():
            if model._meta.app_label == app_label:
                opts = model._meta
                api = self._registry[model]

                apis.append({
                    'title':
                    unicode(opts.verbose_name_plural.capitalize()),
                    'doc':
                    helpers.trim_indent(api.__doc__),
                    'url':
                    '%s/' % opts.module_name
                })

                if hasattr(api, 'app_label_verbose'):
                    app_title = api.app_label_verbose

        if not any(apis):
            raise Http404('App not found.')

        return TemplateResponse(
            request,
            ('api/doc/%s/index.html' % app_label, 'api/doc/app_index.html'), {
                'title_parts': (app_title, DOCS_TITLE),
                'breadcrumb_trail': (('../', DOCS_TITLE), ('', app_title)),
                'resources':
                self._docs_list(),
                'name':
                app_title,
                'apis':
                apis,
                'apps_supported':
                not self.auth.app_model is None
                and getattr(settings, 'API_APPS_MANAGEABLE', True),
                'body_classes': ('api', 'api-docs-app'),
                'app_label':
                app_label
            })
コード例 #4
0
ファイル: sites.py プロジェクト: flamingtarball/bambu-tools
	def docs_index_view(self, request):
		from django.template.response import TemplateResponse
		
		return TemplateResponse(
			request,
			'api/doc/index.html',
			{
				'title_parts': ('Developer resources',),
				'breadcrumb_trail': (
					('', u'Developer resources'),
				),
				'resources': self._docs_list(),
				'auth': {
					'name': self.auth.verbose_name,
					'doc': helpers.trim_indent(self.auth.__doc__)
				},
				'apps_supported': not self.auth.app_model is None,
				'body_classes': ('api', 'api-docs-index')
			}
		)
コード例 #5
0
ファイル: sites.py プロジェクト: iselu/bambu-tools
    def docs_model_view(self, request, app_label, model):
        from django.template.response import TemplateResponse
        from django.http import Http404

        model_parts = model.split('/')
        model = get_model(app_label, model_parts.pop(0))

        if not model:
            raise Http404('Model not found.')

        api = self._registry.get(model)
        if not api:
            raise Http404('API for model not found.')

        if any(model_parts):
            found = False
            while any(model_parts):
                submodel = model_parts.pop(0)
                for inline in api.inline_instances:
                    if inline.model._meta.module_name == submodel:
                        model = inline.model
                        api = inline
                        found = True
                        break

            if not found:
                raise Http404('Submodel %s not found in %s.' %
                              (submodel, model._meta.module_name))

        opts = model._meta
        api_title = unicode(opts.verbose_name_plural.capitalize())
        app_title = getattr(api, 'app_label_verbose',
                            app_label.replace('_', ' ').capitalize())

        inlines = []
        for inline in api.inline_instances:
            inlines.append({
                'name': inline.rel_name.capitalize(),
                'doc': helpers.trim_indent(inline.__doc__),
                'urls': self._docs_urls(inline),
                'url': inline.model._meta.module_name + '/',
                'verbose_name': inline.model._meta.verbose_name,
                'verbose_name_plural': inline.model._meta.verbose_name_plural,
                'formats': inline.allowed_formats
            })

        return TemplateResponse(
            request,
            ('api/doc/%s/%s.html' % (app_label, model._meta.module_name),
             'api/doc/%s/model.html' % app_label, 'api/doc/model.html'), {
                 'title_parts': (api_title, app_title, DOCS_TITLE),
                 'breadcrumb_trail':
                 (('../../', DOCS_TITLE), ('../', app_title), ('', api_title)),
                 'doc':
                 helpers.trim_indent(api.__doc__),
                 'name':
                 api_title,
                 'resources':
                 self._docs_list(),
                 'inlines':
                 inlines,
                 'urls':
                 self._docs_urls(api),
                 'verbose_name':
                 opts.verbose_name,
                 'verbose_name_plural':
                 opts.verbose_name_plural,
                 'formats':
                 api.allowed_formats,
                 'apps_supported':
                 not self.auth.app_model is None
                 and getattr(settings, 'API_APPS_MANAGEABLE', True),
                 'body_classes': ('api', 'api-docs-model'),
                 'app_label':
                 app_label,
                 'model':
                 model._meta.module_name
             })
コード例 #6
0
ファイル: sites.py プロジェクト: flamingtarball/bambu-tools
	def docs_model_view(self, request, app_label, model):
		from django.template.response import TemplateResponse
		from django.http import Http404
		
		model = get_model(app_label, model)
		if not model:
			raise Http404('Model not found.')
		
		api = self._registry.get(model)
		if not api:
			raise Http404('API for model not found.')
		
		opts = model._meta
		api_title = unicode(opts.verbose_name_plural.capitalize())
		app_title = getattr(api, 'app_label_verbose',
			app_label.replace('_', ' ').capitalize()
		)
		
		inlines = []
		for inline in api.inline_instances:
			inlines.append(
				{
					'name': inline.rel_name.capitalize(),
					'doc': helpers.trim_indent(inline.__doc__),
					'urls': self._docs_urls(inline),
					'verbose_name': inline.model._meta.verbose_name,
					'verbose_name_plural': inline.model._meta.verbose_name_plural,
					'formats': inline.allowed_formats
				}
			)
		
		return TemplateResponse(
			request,
			(
				'api/doc/%s/%s.html' % (app_label, model),
				'api/doc/%s/model.html' % app_label,
				'api/doc/model.html'
			),
			{
				'title_parts': (
					api_title,
					app_title,
					'Developer resources'
				),
				'breadcrumb_trail': (
					('../../', u'Developer resources'),
					('../', app_title),
					('', api_title)
				),
				'doc': helpers.trim_indent(api.__doc__),
				'name': api_title,
				'resources': self._docs_list(),
				'inlines': inlines,
				'urls': self._docs_urls(api),
				'verbose_name': opts.verbose_name,
				'verbose_name_plural': opts.verbose_name_plural,
				'formats': api.allowed_formats,
				'apps_supported': not self.auth.app_model is None,
				'body_classes': ('api', 'api-docs-model')
			}
		)