def statistics_catalogs(context): """ Report statistics for catalogs for the specified language and project """ # Try to find if the user is specified if 'user' in context: report = report_catalogs(language = context.get('language'), project = context.get('project'), user = context['user'])[0] if report is None: # Not authorized context['fallback'] = {'type': 'deny', 'message': str(_('You are not allowed to access the catalogs in this language and project.'))} elif len(report['items']) == 0: # Empty list context['fallback'] = {'type': 'important', 'message': str(_('There are no catalogs in this language and project.'))} else: # Update the context context.update(report) context['units_switch'] = units_switch # Return the context return context
def catalogs(request, language_code=None, project_code=None, format="csv", recursive=None): """ Return statistics for catalogs for the specified language and project """ # Try to find the language try: language = Language.objects.get(code=language_code) except: # Language code inexistent, return 404 return page_not_found(request, _("There is no language with %s code.") % language_code) # Try to find the project try: project = Project.objects.get(code=project_code) except: # Project code inexistent, return 404 return page_not_found(request, _("There is no project with %s code.") % project_code) # Create the report data data = report_catalogs(language=language, project=project, user=request.user) # Create the generator and return the result generator = ReportGenerator(request, data) return generator.build(format, subject="%s %s" % (language.name, project.name))