예제 #1
0
        def mk_loctype(name, code, allowed_parents, administrative,
                       shares_cases, view_descendants, pk):
            if allowed_parents and allowed_parents[0]:
                parent = sql_loc_types[allowed_parents[0]]
            else:
                parent = None

            cleaned_code = unicode_slug(code)
            if cleaned_code != code:
                err = _('Location type code "{code}" is invalid. No spaces or '
                        'special characters are allowed. It has been replaced '
                        'with "{new_code}".')
                messages.warning(request,
                                 err.format(code=code, new_code=cleaned_code))

            try:
                loc_type = LocationType.objects.get(domain=self.domain, pk=pk)
            except LocationType.DoesNotExist:
                loc_type = LocationType(domain=self.domain)
            loc_type.name = name
            loc_type.code = cleaned_code
            loc_type.administrative = administrative
            loc_type.parent_type = parent
            loc_type.shares_cases = shares_cases
            loc_type.view_descendants = view_descendants
            loc_type.save()
            sql_loc_types[name] = loc_type
예제 #2
0
파일: models.py 프로젝트: ekush/commcare-hq
    def save(self, *args, **kwargs):
        if not self.code:
            from corehq.apps.commtrack.util import unicode_slug

            self.code = unicode_slug(self.name)
        self._populate_stock_levels()
        return super(LocationType, self).save(*args, **kwargs)
예제 #3
0
    def handle(self, app_id, path, **options):
        # setup directory
        if not os.path.exists(path):
            os.mkdir(path)

        app = Application.get(app_id)
        for module_index, module in enumerate(app.get_modules()):
            module_dir_name = '{index} - {name}'.format(index=module_index, name=unicode_slug(module.default_name()))
            module_dir = os.path.join(path, module_dir_name)
            if not os.path.exists(module_dir):
                os.mkdir(module_dir)
            for form_index, form in enumerate(module.get_forms()):
                form_name = ('{index} - {name}.xml'.format(index=form_index, name=unicode_slug(form.default_name())))
                form_path = os.path.join(module_dir, form_name)
                with open(form_path, 'w') as f:
                    f.write(form.source.encode('utf-8'))
                    print('wrote {}'.format(form_path))
예제 #4
0
 def test_unicode_slug(self):
     test_cases = (
         ('normal', 'normal'),
         ('unicode', 'unicode'),
         ('    with\n\t  whitespace   ', 'with-whitespace'),
         ('speçial çháracters', 'special-characters'),
         ('हिंदी', 'hindii'),
     )
     for input, output in test_cases:
         self.assertEqual(output, unicode_slug(input))
예제 #5
0
 def test_unicode_slug(self):
     test_cases = (
         ('normal', 'normal'),
         (u'unicode', 'unicode'),
         ('    with\n\t  whitespace   ', 'with-whitespace'),
         (u'speçial çháracters', 'special-characters'),
         (u'हिंदी', 'hindii'),
     )
     for input, output in test_cases:
         self.assertEqual(output, unicode_slug(input))
예제 #6
0
 def test_unicode_slug(self):
     test_cases = (
         ("normal", "normal"),
         (u"unicode", "unicode"),
         ("    with\n\t  whitespace   ", "with-whitespace"),
         (u"speçial çháracters", "special-characters"),
         (u"हिंदी", "hindii"),
     )
     for input, output in test_cases:
         self.assertEqual(output, unicode_slug(input))
예제 #7
0
 def mk_loctype(loctype):
     loctype['allowed_parents'] = [p or '' for p in loctype['allowed_parents']]
     cleaned_code = unicode_slug(loctype['code'])
     if cleaned_code != loctype['code']:
         err = _(
             'Location type code "{code}" is invalid. No spaces or special characters are allowed. '
             'It has been replaced with "{new_code}".'
         )
         messages.warning(request, err.format(code=loctype['code'], new_code=cleaned_code))
         loctype['code'] = cleaned_code
     return LocationType(**loctype)
예제 #8
0
 def mk_loctype(loctype):
     loctype['allowed_parents'] = [p or '' for p in loctype['allowed_parents']]
     cleaned_code = unicode_slug(loctype['code'])
     if cleaned_code != loctype['code']:
         err = _(
             'Location type code "{code}" is invalid. No spaces or special characters are allowed. '
             'It has been replaced with "{new_code}".'
         )
         messages.warning(request, err.format(code=loctype['code'], new_code=cleaned_code))
         loctype['code'] = cleaned_code
     return LocationType(**loctype)
    def handle(self, *args, **options):
        # todo: would be nice if this worked off remote servers too
        if len(args) != 2:
            raise CommandError('Usage: %s\n%s' % (self.args, self.help))
        app_id, path = args

        # setup directory
        if not os.path.exists(path):
            os.mkdir(path)

        app = Application.get(app_id)
        for module_index, module in enumerate(app.get_modules()):
            module_dir_name = '{index} - {name}'.format(index=module_index, name=unicode_slug(module.default_name()))
            module_dir = os.path.join(path, module_dir_name)
            if not os.path.exists(module_dir):
                os.mkdir(module_dir)
            for form_index, form in enumerate(module.get_forms()):
                form_name = ('{index} - {name}.xml'.format(index=form_index, name=unicode_slug(form.default_name())))
                form_path = os.path.join(module_dir, form_name)
                with open(form_path, 'w') as f:
                    f.write(form.source.encode('utf-8'))
                    print 'wrote {}'.format(form_path)
예제 #10
0
    def _ordered_types(self, hierarchy):
        from corehq.apps.commtrack.util import unicode_slug

        def _gen(hierarchy):
            next_types = set([None])
            while next_types:
                next_type = next_types.pop()
                if next_type is not None:
                    yield next_type
                new_children = hierarchy.get(next_type, [])
                for child in new_children:
                    next_types.add(child)

        return [unicode_slug(t) for t in _gen(hierarchy)]
예제 #11
0
파일: xpath.py 프로젝트: caktus/commcare-hq
    def _ordered_types(self, hierarchy):
        from corehq.apps.commtrack.util import unicode_slug

        def _gen(hierarchy):
            next_types = set([None])
            while next_types:
                next_type = next_types.pop()
                if next_type is not None:
                    yield next_type
                new_children = hierarchy.get(next_type, [])
                for child in new_children:
                    next_types.add(child)

        return [unicode_slug(t) for t in _gen(hierarchy)]
    def handle(self, *args, **options):
        # todo: would be nice if this worked off remote servers too
        if len(args) != 2:
            raise CommandError('Usage: %s\n%s' % (self.args, self.help))
        app_id, path = args

        # setup directory
        if not os.path.exists(path):
            os.mkdir(path)

        app = Application.get(app_id)
        for module_index, module in enumerate(app.get_modules()):
            module_dir_name = '{index} - {name}'.format(
                index=module_index, name=unicode_slug(module.default_name()))
            module_dir = os.path.join(path, module_dir_name)
            if not os.path.exists(module_dir):
                os.mkdir(module_dir)
            for form_index, form in enumerate(module.get_forms()):
                form_name = ('{index} - {name}.xml'.format(
                    index=form_index, name=unicode_slug(form.default_name())))
                form_path = os.path.join(module_dir, form_name)
                with open(form_path, 'w') as f:
                    f.write(form.source.encode('utf-8'))
                    print('wrote {}'.format(form_path))
예제 #13
0
    def save(self, *args, **kwargs):
        from .tasks import sync_administrative_status
        if not self.code:
            from corehq.apps.commtrack.util import unicode_slug
            self.code = unicode_slug(self.name)
        if not self.commtrack_enabled:
            self.administrative = True
        self._populate_stock_levels()
        is_not_first_save = self.pk is not None
        saved = super(LocationType, self).save(*args, **kwargs)

        if is_not_first_save and self._administrative_old != self.administrative:
            sync_administrative_status.delay(self)
            self._administrative_old = self.administrative

        return saved
예제 #14
0
    def save(self, *args, **kwargs):
        if not self.code:
            from corehq.apps.commtrack.util import unicode_slug
            self.code = unicode_slug(self.name)
        if not self.commtrack_enabled:
            self.administrative = True

        config = stock_level_config_for_domain(self.domain, self.commtrack_enabled)
        if config:
            self._populate_stock_levels(config)

        is_not_first_save = self.pk is not None
        super(LocationType, self).save(*args, **kwargs)

        if is_not_first_save:
            self.sync_administrative_status()
예제 #15
0
    def save(self, *args, **kwargs):
        from .tasks import sync_administrative_status
        if not self.code:
            from corehq.apps.commtrack.util import unicode_slug
            self.code = unicode_slug(self.name)
        if not self.commtrack_enabled:
            self.administrative = True
        self._populate_stock_levels()
        is_not_first_save = self.pk is not None
        saved = super(LocationType, self).save(*args, **kwargs)

        if is_not_first_save and self._administrative_old != self.administrative:
            sync_administrative_status.delay(self)
            self._administrative_old = self.administrative

        return saved
예제 #16
0
    def save(self, *args, **kwargs):
        if not self.code:
            from corehq.apps.commtrack.util import unicode_slug
            self.code = unicode_slug(self.name)
        if not self.commtrack_enabled:
            self.administrative = True

        config = stock_level_config_for_domain(self.domain, self.commtrack_enabled)
        if config:
            self._populate_stock_levels(config)

        is_not_first_save = self.pk is not None
        saved = super(LocationType, self).save(*args, **kwargs)

        if is_not_first_save:
            self.sync_administrative_status()

        return saved
예제 #17
0
        def mk_loctype(name, parent_type, administrative,
                       shares_cases, view_descendants, pk, code, **kwargs):
            parent = sql_loc_types[parent_type] if parent_type else None

            loc_type = None
            if not _is_fake_pk(pk):
                try:
                    loc_type = LocationType.objects.get(domain=self.domain, pk=pk)
                except LocationType.DoesNotExist:
                    pass
            if loc_type is None:
                loc_type = LocationType(domain=self.domain)
            loc_type.name = name
            loc_type.administrative = administrative
            loc_type.parent_type = parent
            loc_type.shares_cases = shares_cases
            loc_type.view_descendants = view_descendants
            loc_type.code = unicode_slug(code)
            sql_loc_types[pk] = loc_type
            loc_type.save()
예제 #18
0
        def mk_loctype(name, parent_type, administrative,
                       shares_cases, view_descendants, pk, code, **kwargs):
            parent = sql_loc_types[parent_type] if parent_type else None

            loc_type = None
            if not _is_fake_pk(pk):
                try:
                    loc_type = LocationType.objects.get(domain=self.domain, pk=pk)
                except LocationType.DoesNotExist:
                    pass
            if loc_type is None:
                loc_type = LocationType(domain=self.domain)
            loc_type.name = name
            loc_type.administrative = administrative
            loc_type.parent_type = parent
            loc_type.shares_cases = shares_cases
            loc_type.view_descendants = view_descendants
            loc_type.code = unicode_slug(code)
            sql_loc_types[pk] = loc_type
            loc_type.save()
예제 #19
0
    def save(self, *args, **kwargs):
        from .tasks import update_location_users

        if not self.code:
            from corehq.apps.commtrack.util import unicode_slug
            self.code = unicode_slug(self.name)
        if not self.commtrack_enabled:
            self.administrative = True

        config = stock_level_config_for_domain(self.domain, self.commtrack_enabled)
        if config:
            self._populate_stock_levels(config)

        is_not_first_save = self.pk is not None
        saved = super(LocationType, self).save(*args, **kwargs)

        if is_not_first_save:
            self.sync_administrative_status()
            if self._has_user_old != self.has_user:
                update_location_users.delay(self)

        return saved
예제 #20
0
 def wrap(cls, obj):
     from corehq.apps.commtrack.util import unicode_slug
     if not obj.get('code'):
         obj['code'] = unicode_slug(obj['name'])
     return super(LocationType, cls).wrap(obj)
예제 #21
0
 def save(self, *args, **kwargs):
     if not self.code:
         from corehq.apps.commtrack.util import unicode_slug
         self.code = unicode_slug(self.name)
     self._populate_stock_levels()
     return super(LocationType, self).save(*args, **kwargs)
예제 #22
0
 def location_type_lookup(location_type):
     return type_to_slug_mapping.get(location_type, unicode_slug(location_type))
예제 #23
0
 def location_type_lookup(location_type):
     return type_to_slug_mapping.get(location_type,
                                     unicode_slug(location_type))