示例#1
0
    def save(self, domain):
        domain.restrict_superusers = self.cleaned_data.get('restrict_superusers', False)
        try:
            secure_submissions = self.cleaned_data.get(
                'secure_submissions', False)
            apps_to_save = []
            if secure_submissions != domain.secure_submissions:
                for app in get_apps_in_domain(domain.name):
                    if app.secure_submissions != secure_submissions:
                        app.secure_submissions = secure_submissions
                        apps_to_save.append(app)
            domain.secure_submissions = secure_submissions
            domain.save()

            if apps_to_save:
                apps = [app for app in apps_to_save if isinstance(app, Application)]
                remote_apps = [app for app in apps_to_save if isinstance(app, RemoteApp)]
                if apps:
                    Application.bulk_save(apps)
                if remote_apps:
                    RemoteApp.bulk_save(remote_apps)

            return True
        except Exception:
            return False
示例#2
0
 def app_to_module_options(self):
     return {
         app._id: [{
             'text': trans(module.name, app.langs),
             'value': module.unique_id,
         } for module in app.modules]
         for app in get_apps_in_domain(self.domain)
     }
示例#3
0
 def module_to_form_options(self):
     return {
         module.unique_id: [{
             'text': trans(form.name, app.langs),
             'value': form.unique_id,
         } for form in module.get_forms()]
         for app in get_apps_in_domain(self.domain)
         for module in app.modules
     }
示例#4
0
 def get_context_data(self, **kwargs):
     return {
         "has_apps": len(get_apps_in_domain(self.domain)) > 0,
         "domain": self.domain,
         "report": {
             "title": _("Create New Report")
         },
         "tiles": self.tiles,
     }
示例#5
0
 def app_to_case_type_options(self):
     return {
         app._id: [{
             'text': case_type,
             'value': case_type,
         } for case_type in set(
             module.case_type for module in app.modules if module.case_type
         )]
         for app in get_apps_in_domain(self.domain)
     }
示例#6
0
    def save(self, request, domain):
        try:
            if self.can_use_custom_logo:
                logo = self.cleaned_data['logo']
                if logo:

                    input_image = Image.open(io.BytesIO(logo.read()))
                    input_image.load()
                    input_image.thumbnail(LOGO_SIZE)
                    # had issues trying to use a BytesIO instead
                    tmpfilename = "/tmp/%s_%s" % (uuid.uuid4(), logo.name)
                    input_image.save(tmpfilename, 'PNG')

                    with open(tmpfilename) as tmpfile:
                        domain.put_attachment(tmpfile, name=LOGO_ATTACHMENT)
                elif self.cleaned_data['delete_logo']:
                    domain.delete_attachment(LOGO_ATTACHMENT)

            domain.call_center_config.enabled = self.cleaned_data.get('call_center_enabled', False)
            if domain.call_center_config.enabled:
                domain.internal.using_call_center = True
                domain.call_center_config.case_owner_id = self.cleaned_data.get('call_center_case_owner', None)
                domain.call_center_config.case_type = self.cleaned_data.get('call_center_case_type', None)

            global_tz = self.cleaned_data['default_timezone']
            if domain.default_timezone != global_tz:
                domain.default_timezone = global_tz
                users = WebUser.by_domain(domain.name)
                users_to_save = []
                for user in users:
                    dm = user.get_domain_membership(domain.name)
                    if not dm.override_global_tz and dm.timezone != global_tz:
                        dm.timezone = global_tz
                        users_to_save.append(user)
                if users_to_save:
                    WebUser.bulk_save(users_to_save)

            secure_submissions = self.cleaned_data.get(
                'secure_submissions', False)
            apps_to_save = []
            if secure_submissions != domain.secure_submissions:
                for app in get_apps_in_domain(domain.name):
                    if app.secure_submissions != secure_submissions:
                        app.secure_submissions = secure_submissions
                        apps_to_save.append(app)
            domain.secure_submissions = secure_submissions
            domain.save()
            if apps_to_save:
                ApplicationBase.bulk_save(apps_to_save)
            return True
        except Exception:
            return False
示例#7
0
 def __init__(self, domain, *args, **kwargs):
     self.helper = FormHelper()
     self.helper.form_method = 'post'
     self.helper.add_input(Submit('submit', _('Save Changes')))
     super(ConfigurableDataSourceFromAppForm, self).__init__(*args, **kwargs)
     apps = get_apps_in_domain(domain, full=True, include_remote=False)
     self.fields['app_id'] = forms.ChoiceField(
         label=_('Application'),
         choices=[(app._id, app.name) for app in apps]
     )
     self.fields['case_type'] = forms.ChoiceField(
         choices=[(ct, ct) for ct in set([c for app in apps for c in app.get_case_types() if c])]
     )
示例#8
0
    def __init__(self, domain, *args, **kwargs):
        super(CreateCaseExportForm, self).__init__(*args, **kwargs)
        apps = get_apps_in_domain(domain)
        self.fields['application'].choices = ([
            ('', _('Select Application...')),
        ] if len(apps) > 1 else []) + [
            (app._id, app.name) for app in apps
        ]
        self.fields['case_type'].choices = [
            (module.case_type, module.case_type)
            for app in apps if hasattr(app, 'modules')
            for module in app.modules
            if module.case_type
        ]

        self.helper = FormHelper()
        self.helper.form_id = "create-export-form"
        self.helper.form_class = "form-horizontal"

        self.helper.layout = crispy.Layout(
            crispy.Fieldset(
                _('Select Case Type'),
                crispy.Field(
                    'application',
                    data_bind='value: appId',
                ),
                crispy.Div(
                    crispy.Field(
                        'case_type',
                        data_bind=(
                            "options: caseTypeOptions, "
                            "optionsText: 'text', "
                            "optionsValue: 'value', "
                            "value: case_type"
                        ),
                    ),
                    data_bind="visible: appId",
                ),
            ),
            crispy.Div(
                FormActions(
                    crispy.ButtonHolder(
                        crispy.Submit(
                            'create_export',
                            _('Next'),
                        ),
                    ),
                ),
                data_bind="visible: case_type",
            ),
        )
示例#9
0
 def __init__(self, domain, *args, **kwargs):
     self.helper = FormHelper()
     self.helper.form_method = 'post'
     self.helper.add_input(Submit('submit', _('Save Changes')))
     super(ConfigurableFormDataSourceFromAppForm, self).__init__(*args, **kwargs)
     apps = get_apps_in_domain(domain, full=True, include_remote=False)
     self.fields['app_id'] = forms.ChoiceField(
         label=_('Application'),
         choices=[(app._id, app.name) for app in apps]
     )
     self.fields['form_id'] = forms.ChoiceField(
         label=_('Module - Form'),
         choices=[(form.get_unique_id(), form.get_module().default_name() + ' - ' + form.default_name())
                  for form in set([form for app in apps for form in app.get_forms()])]
     )
示例#10
0
def get_app_sources(domain):
    apps = get_apps_in_domain(domain, full=True, include_remote=False)
    return {
        app._id: {
            "name": app.name,
            "case": [{"text": t, "value": t} for t in app.get_case_types()],
            "form": [
                {
                    "text": form.default_name(),
                    "value": form.get_unique_id()
                } for form in app.get_forms()
            ]
        }
        for app in apps
    }
示例#11
0
 def obj_get_list(self, bundle, domain, **kwargs):
     return get_apps_in_domain(domain, include_remote=False)
示例#12
0
 def get_other_case_sharing_apps_in_domain(self):
     from corehq.apps.app_manager.models import get_apps_in_domain
     apps = get_apps_in_domain(self.app.domain, include_remote=False)
     return [a for a in apps if a.case_sharing and a.id != self.app.id]
示例#13
0
 def test_app_base(self):
     apps = get_apps_in_domain(self.domain)
     self.assertEqual(len(apps), 2)
示例#14
0
    def __init__(self, domain, *args, **kwargs):
        super(CreateFormExportForm, self).__init__(*args, **kwargs)
        apps = get_apps_in_domain(domain)
        self.fields['application'].choices = ([
            ('', _('Select Application...')),
        ] if len(apps) > 1 else []) + [
            (app._id, app.name) for app in apps
        ]
        self.fields['module'].choices = [
            (module.unique_id, module.name)
            for app in apps
            for module in app.modules
        ]
        self.fields['form'].choices = [
            (form.get_unique_id(), form.name)
            for app in apps
            for form in app.get_forms()
        ]

        self.helper = FormHelper()
        self.helper.form_id = "create-export-form"
        self.helper.form_class = "form-horizontal"

        self.helper.layout = crispy.Layout(
            crispy.Fieldset(
                _('Select Form'),
                crispy.Field(
                    'application',
                    data_bind='value: appId',
                ),
                crispy.Div(
                    crispy.Field(
                        'module',
                        data_bind=(
                            "options: moduleOptions, "
                            "optionsText: 'text', "
                            "optionsValue: 'value', "
                            "value: moduleId"
                        ),
                    ),
                    data_bind="visible: appId",
                ),
                crispy.Div(
                    crispy.Field(
                        'form',
                        data_bind=(
                            "options: formOptions, "
                            "optionsText: 'text', "
                            "optionsValue: 'value', "
                            "value: formId"
                        ),
                    ),
                    data_bind="visible: moduleId",
                ),
            ),
            crispy.Div(
                FormActions(
                    crispy.ButtonHolder(
                        crispy.Submit(
                            'create_export',
                            _('Next'),
                        ),
                    ),
                ),
                data_bind="visible: formId",
            ),
        )