Exemple #1
0
def upload_message_bank(request, domain):
    if request.method == "POST":
        form = MessageBankForm(request.POST, request.FILES)
        if form.is_valid():
            current_bank = get_message_bank(domain)
            message_id_map = {}
            for message in current_bank:
                message_id_map[message.fri_id.upper()] = message

            # The message bank is supposed to be static, and is intended
            # to be a one-time upload. So to prevent any issues with
            # overwriting messages or deleting messages by accident, this
            # api will only add new messages to the message bank.
            # If more specialized functionality is needed later on, a new
            # UI should be built.
            for message in form.cleaned_data["message_bank_file"]:
                msg_id = message["msg_id"]
                text = message["text"]
                if msg_id.upper() not in message_id_map:
                    msg = FRIMessageBankMessage(
                        domain = domain,
                        risk_profile = msg_id[0].upper(),
                        message = text,
                        fri_id = msg_id,
                    )
                    msg.save()
            messages.success(request, _("Message Bank Uploaded."))
        else:
            messages.error(request, form._errors["message_bank_file"].as_text())
    else:
        messages.error(request, _("ERROR: POST Expected."))
    return HttpResponseRedirect(reverse(CustomProjectReportDispatcher.name(), args=[domain, MessageBankReport.slug]))
Exemple #2
0
def get_possible_reports(domain_name):
    from corehq.apps.reports.dispatcher import (ProjectReportDispatcher,
                                                CustomProjectReportDispatcher)
    from corehq.apps.data_interfaces.dispatcher import DataInterfaceDispatcher

    # todo: exports should be its own permission at some point?
    report_map = (ProjectReportDispatcher().get_reports(domain_name) +
                  CustomProjectReportDispatcher().get_reports(domain_name) +
                  DataInterfaceDispatcher().get_reports(domain_name))
    reports = []
    domain = Domain.get_by_name(domain_name)
    for heading, models in report_map:
        for model in models:
            if getattr(model, 'parent_report_class', None):
                report_to_check_if_viewable = model.parent_report_class
            else:
                report_to_check_if_viewable = model

            if report_to_check_if_viewable.show_in_navigation(
                    domain=domain_name, project=domain):
                reports.append({
                    'path': model.__module__ + '.' + model.__name__,
                    'name': model.name
                })

    for slug, name, is_visible in get_extra_permissions():
        if is_visible(domain):
            reports.append({'path': slug, 'name': name})
    return reports
Exemple #3
0
def upload_message_bank(request, domain):
    if request.method == "POST":
        form = MessageBankForm(request.POST, request.FILES)
        if form.is_valid():
            current_bank = get_message_bank(domain)
            message_id_map = {}
            for message in current_bank:
                message_id_map[message.fri_id.upper()] = message

            # The message bank is supposed to be static, and is intended
            # to be a one-time upload. So to prevent any issues with
            # overwriting messages or deleting messages by accident, this
            # api will only add new messages to the message bank.
            # If more specialized functionality is needed later on, a new
            # UI should be built.
            for message in form.cleaned_data["message_bank_file"]:
                msg_id = message["msg_id"]
                text = message["text"]
                if msg_id.upper() not in message_id_map:
                    msg = FRIMessageBankMessage(
                        domain=domain,
                        risk_profile=msg_id[0].upper(),
                        message=text,
                        fri_id=msg_id,
                    )
                    msg.save()
            messages.success(request, _("Message Bank Uploaded."))
        else:
            messages.error(request,
                           form._errors["message_bank_file"].as_text())
    else:
        messages.error(request, _("ERROR: POST Expected."))
    return HttpResponseRedirect(
        reverse(CustomProjectReportDispatcher.name(),
                args=[domain, MessageBankReport.slug]))
Exemple #4
0
def get_possible_reports(domain_name):
    from corehq.apps.reports.dispatcher import (ProjectReportDispatcher, CustomProjectReportDispatcher)

    # todo: exports should be its own permission at some point?
    report_map = (ProjectReportDispatcher().get_reports(domain_name) +
                  CustomProjectReportDispatcher().get_reports(domain_name))
    reports = []
    domain_obj = Domain.get_by_name(domain_name)
    for heading, models in report_map:
        for model in models:
            if getattr(model, 'parent_report_class', None):
                report_to_check_if_viewable = model.parent_report_class
            else:
                report_to_check_if_viewable = model

            if report_to_check_if_viewable.show_in_user_roles(domain=domain_name, project=domain_obj):
                path = model.__module__ + '.' + model.__name__
                reports.append({
                    'path': path,
                    'name': model.name,
                    'slug': path.replace('.', '_'),
                })

    for slug, name, is_visible in get_extra_permissions():
        if is_visible(domain_obj):
            reports.append({
                'path': slug,
                'name': name,
                'slug': slug.replace('.', '_'),
            })
    return reports
Exemple #5
0
 def template_context(self):
     result = {
         "fri_message_bank_url":
         reverse(CustomProjectReportDispatcher.name(),
                 args=[self.domain, MessageBankReport.slug]),
         "fri_chat_actions": [
             self._open_chat_action(case._id)
             for case in self.interactive_participants
         ],
     }
Exemple #6
0
def get_possible_reports(domain):
    from corehq.apps.reports.dispatcher import (ProjectReportDispatcher,
                                                CustomProjectReportDispatcher)
    from corehq.apps.adm.dispatcher import ADMSectionDispatcher
    reports = []
    report_map = ProjectReportDispatcher().get_reports(domain) + \
                 CustomProjectReportDispatcher().get_reports(domain) +\
                 ADMSectionDispatcher().get_reports(domain)
    for heading, models in report_map:
        for model in models:
            reports.append({
                'path': model.__module__ + '.' + model.__name__,
                'name': model.name
            })
    return reports
Exemple #7
0
    def sidebar_items(self):
        context = {
            'request': self._request,
            'domain': self.domain,
        }
        
        tools = [(_("Tools"), [
            {'title': _('My Saved Reports'),
             'url': reverse('saved_reports', args=[self.domain]),
             'icon': 'icon-tasks'}
        ])]

        project_reports = ProjectReportDispatcher.navigation_sections(
            context)
        custom_reports = CustomProjectReportDispatcher.navigation_sections(
            context)

        return tools + project_reports + custom_reports
Exemple #8
0
def get_possible_reports(domain_name):
    from corehq.apps.reports.dispatcher import (ProjectReportDispatcher, CustomProjectReportDispatcher)
    from corehq.apps.data_interfaces.dispatcher import DataInterfaceDispatcher

    # todo: exports should be its own permission at some point?
    report_map = (ProjectReportDispatcher().get_reports(domain_name) +
                  CustomProjectReportDispatcher().get_reports(domain_name) +
                  DataInterfaceDispatcher().get_reports(domain_name))
    reports = []
    domain = Domain.get_by_name(domain_name)
    for heading, models in report_map:
        for model in models:
            if model.show_in_navigation(domain=domain_name, project=domain):
                reports.append({
                    'path': model.__module__ + '.' + model.__name__,
                    'name': model.name
                })
    return reports
Exemple #9
0
    def sidebar_items(self):
        context = {
            'request': self._request,
            'domain': self.domain,
        }
        
        tools = [(_("Tools"), [
            {'title': _('My Saved Reports'),
             'url': reverse('saved_reports', args=[self.domain]),
             'icon': 'icon-tasks'}
        ])]

        project_reports = ProjectReportDispatcher.navigation_sections(
            context)
        custom_reports = CustomProjectReportDispatcher.navigation_sections(
            context)

        return tools + project_reports + custom_reports
Exemple #10
0
    def sidebar_items(self):
        context = {"request": self._request, "domain": self.domain}

        tools = [
            (
                _("Tools"),
                [
                    {
                        "title": _("My Saved Reports"),
                        "url": reverse("saved_reports", args=[self.domain]),
                        "icon": "icon-tasks",
                    }
                ],
            )
        ]

        project_reports = ProjectReportDispatcher.navigation_sections(context)
        custom_reports = CustomProjectReportDispatcher.navigation_sections(context)

        return tools + project_reports + custom_reports
Exemple #11
0
# from .filters.urls import urlpatterns as filter_urls
from corehq.apps.example_reports.testreport import TestReport
from corehq.apps.reports.views import AddSavedReportConfigView
from corehq.apps.userreports.reports.view import ConfigurableReport
from corehq.apps.userreports.views import (
    CreateNewReportBuilderView,
    ConfigureBarChartReportBuilderView,
    ConfigureTableReportBuilderView,
    ConfigurePieChartReportBuilderView,
)
from .filters import urls as filter_urls


custom_report_urls = patterns('',
    CustomProjectReportDispatcher.url_pattern(),
)

urlpatterns = patterns('corehq.apps.reports.views',
    TestReport.url_pattern(),
    ConfigurableReport.url_pattern(),
    url(r'^builder/create/$', CreateNewReportBuilderView.as_view(), name="create_new_report_builder"),
    url(r'^builder/configure/bar/$', ConfigureBarChartReportBuilderView.as_view(), name="configure_bar_chart_report_builder"),
    url(r'^builder/configure/pie/$', ConfigurePieChartReportBuilderView.as_view(), name="configure_pie_chart_report_builder"),
    url(r'^builder/configure/table/$', ConfigureTableReportBuilderView.as_view(), name="configure_table_report_builder"),
    url(r'^$', "default", name="reports_home"),
    url(r'^saved/', "saved_reports", name="saved_reports"),
    url(r'^saved_reports', 'old_saved_reports'),

    url(r'^case_data/(?P<case_id>[\w\-]+)/$', 'case_details', name="case_details"),
    url(r'^case_data/(?P<case_id>[\w\-]+)/attachments/$', 'case_attachments', name="single_case_attachments"),
Exemple #12
0
from corehq.apps.domain.decorators import login_and_domain_required as protect
from corehq.apps.reports.dispatcher import ReportDispatcher, ProjectReportDispatcher, CustomProjectReportDispatcher

dodoma_reports = patterns('corehq.apps.reports.dodoma',
    url('^household_verification_json$', 'household_verification_json'),
    url('^household_verification/$', 'household_verification'),
)

_phonelog_context = {
    'report': {
        'name': "Device Logs",
    }
}

custom_report_urls = patterns('',
    url(CustomProjectReportDispatcher.pattern(), CustomProjectReportDispatcher.as_view(),
        name=CustomProjectReportDispatcher.name())
)

phonelog_reports = patterns('',
    url(r'^$', 'phonelog.views.devices', name="phonelog_devices", kwargs={
        'template': 'reports/phonelog/devicelist.html',
        'context': _phonelog_context
    }),
    url(r'^(?P<device>[\w\-]+)/$', 'phonelog.views.device_log', name="device_log", kwargs={
        'template': 'reports/phonelog/devicelogs.html',
        'context': _phonelog_context
    }),
    url(r'^(?P<device>[\w\-]+)/raw/$', 'phonelog.views.device_log_raw', name="device_log_raw", kwargs={
        'template': 'reports/phonelog/devicelogs_raw.html',
        'context': _phonelog_context
Exemple #13
0
dodoma_reports = patterns(
    'corehq.apps.reports.dodoma',
    url('^household_verification_json$', 'household_verification_json'),
    url('^household_verification/$', 'household_verification'),
)

_phonelog_context = {
    'report': {
        'name': "Device Logs",
    }
}

custom_report_urls = patterns(
    '',
    CustomProjectReportDispatcher.url_pattern(),
)

phonelog_reports = patterns(
    '',
    url(r'^$',
        'phonelog.views.devices',
        name="phonelog_devices",
        kwargs={
            'template': 'reports/phonelog/devicelist.html',
            'context': _phonelog_context
        }),
    url(r'^(?P<device>[\w\-]+)/$',
        'phonelog.views.device_log',
        name="device_log",
        kwargs={
def _domain_has_custom_report(domain):
    from corehq.apps.reports.dispatcher import CustomProjectReportDispatcher
    return bool(CustomProjectReportDispatcher().get_reports(domain.name))
Exemple #15
0
 def next_report_class(self):
     return CustomProjectReportDispatcher().get_report(
         self.domain, self.next_report_slug)
Exemple #16
0
from corehq.apps.reports.util import get_installed_custom_modules
from corehq.apps.reports.dispatcher import ProjectReportDispatcher, CustomProjectReportDispatcher, BasicReportDispatcher

# from .filters.urls import urlpatterns as filter_urls
from .filters import urls as filter_urls


dodoma_reports = patterns(
    "corehq.apps.reports.dodoma",
    url("^household_verification_json$", "household_verification_json"),
    url("^household_verification/$", "household_verification"),
)

_phonelog_context = {"report": {"name": "Device Logs"}}

custom_report_urls = patterns("", CustomProjectReportDispatcher.url_pattern())

phonelog_reports = patterns(
    "",
    url(
        r"^$",
        "phonelog.views.devices",
        name="phonelog_devices",
        kwargs={"template": "reports/phonelog/devicelist.html", "context": _phonelog_context},
    ),
    url(
        r"^(?P<device>[\w\-]+)/$",
        "phonelog.views.device_log",
        name="device_log",
        kwargs={"template": "reports/phonelog/devicelogs.html", "context": _phonelog_context},
    ),
Exemple #17
0
 def template_context(self):
     result = {
         "fri_message_bank_url" : reverse(CustomProjectReportDispatcher.name(), args=[self.domain, MessageBankReport.slug]),
         "fri_chat_actions" : [self._open_chat_action(case._id) for case in self.interactive_participants],
     }
     return result