Example #1
0
    def save(self, request, domain):
        res = DomainGlobalSettingsForm.save(self, request, domain)

        if not res:
            return False
        try:
            domain.project_type = self.cleaned_data['project_type']
            domain.customer_type = self.cleaned_data['customer_type']
            domain.is_test = self.cleaned_data['is_test']
            domain.commconnect_enabled = self.cleaned_data.get(
                'commconnect_enabled', False)
            domain.survey_management_enabled = self.cleaned_data.get(
                'survey_management_enabled', False)
            domain.sms_case_registration_enabled = self.cleaned_data.get(
                'sms_case_registration_enabled', False)
            domain.sms_case_registration_type = self.cleaned_data.get(
                'sms_case_registration_type')
            domain.sms_case_registration_owner_id = self.cleaned_data.get(
                'sms_case_registration_owner_id')
            domain.sms_case_registration_user_id = self.cleaned_data.get(
                'sms_case_registration_user_id')
            domain.default_sms_backend_id = self.cleaned_data.get(
                'default_sms_backend_id')
            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)
            domain.restrict_superusers = self.cleaned_data.get(
                'restrict_superusers', False)
            domain.ota_restore_caching = self.cleaned_data.get(
                'ota_restore_caching', False)
            cloudcare_releases = self.cleaned_data.get('cloudcare_releases')
            if cloudcare_releases and domain.cloudcare_releases != 'default':
                # you're never allowed to change from default
                domain.cloudcare_releases = cloudcare_releases
            secure_submissions = self.cleaned_data.get('secure_submissions',
                                                       False)
            apps_to_save = []
            if secure_submissions != domain.secure_submissions:
                for app in ApplicationBase.by_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, e:
            logging.exception("couldn't save project settings - error is %s" %
                              e)
            return False
Example #2
0
    def obj_get_list(self, bundle, domain, **kwargs):
        # There should be few enough apps per domain that doing an explicit refresh for each is OK.
        # This is the easiest way to filter remote apps
        # Later we could serialize them to their URL or whatevs but it is not that useful yet
        application_bases = ApplicationBase.by_domain(domain)

        # This wraps in the appropriate class so that is_remote_app() returns the correct answer
        applications = [get_app(domain, application_base.id) for application_base in application_bases]

        return [app for app in applications if not app.is_remote_app()]
Example #3
0
    def obj_get_list(self, bundle, domain, **kwargs):
        # There should be few enough apps per domain that doing an explicit refresh for each is OK.
        # This is the easiest way to filter remote apps
        # Later we could serialize them to their URL or whatevs but it is not that useful yet
        application_bases = ApplicationBase.by_domain(domain)

        # This wraps in the appropriate class so that is_remote_app() returns the correct answer
        applications = [get_app(domain, application_base.id) for application_base in application_bases]

        return [app for app in applications if not app.is_remote_app()]
Example #4
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']
            domain.default_timezone = global_tz
            users = WebUser.by_domain(domain.name)
            for user in users:
                dm = user.get_domain_membership(domain.name)
                if not dm.override_global_tz:
                    dm.timezone = global_tz
                    user.save()
            secure_submissions = self.cleaned_data.get(
                'secure_submissions', False)
            apps_to_save = []
            if secure_submissions != domain.secure_submissions:
                for app in ApplicationBase.by_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
Example #5
0
    def save(self, request, domain):
        res = DomainGlobalSettingsForm.save(self, request, domain)

        if not res:
            return False
        try:
            domain.project_type = self.cleaned_data['project_type']
            domain.customer_type = self.cleaned_data['customer_type']
            domain.is_test = self.cleaned_data['is_test']
            domain.commconnect_enabled = self.cleaned_data.get(
                    'commconnect_enabled', False)
            domain.survey_management_enabled = self.cleaned_data.get('survey_management_enabled', False)
            domain.sms_case_registration_enabled = self.cleaned_data.get('sms_case_registration_enabled', False)
            domain.sms_case_registration_type = self.cleaned_data.get('sms_case_registration_type')
            domain.sms_case_registration_owner_id = self.cleaned_data.get('sms_case_registration_owner_id')
            domain.sms_case_registration_user_id = self.cleaned_data.get('sms_case_registration_user_id')
            domain.default_sms_backend_id = self.cleaned_data.get('default_sms_backend_id')
            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)
            domain.restrict_superusers = self.cleaned_data.get('restrict_superusers', False)
            domain.ota_restore_caching = self.cleaned_data.get('ota_restore_caching', False)
            cloudcare_releases = self.cleaned_data.get('cloudcare_releases')
            if cloudcare_releases and domain.cloudcare_releases != 'default':
                # you're never allowed to change from default
                domain.cloudcare_releases = cloudcare_releases
            secure_submissions = self.cleaned_data.get('secure_submissions', False)
            apps_to_save = []
            if secure_submissions != domain.secure_submissions:
                for app in ApplicationBase.by_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, e:
            logging.exception("couldn't save project settings - error is %s" % e)
            return False
Example #6
0
 def test_app_base(self):
     apps = ApplicationBase.by_domain(self.domain)
     self.assertEqual(len(apps), 2)