Пример #1
0
    def __init__(self,
                 xform_raw=None,
                 xform_path=None,
                 instance_raw=None,
                 instance_path=None,
                 preload_data={},
                 extensions=[],
                 nav_mode='prompt'):
        self.lock = threading.Lock()
        self.nav_mode = nav_mode
        self.seq_id = 0

        def content_or_path(content, path):
            if content != None:
                return content
            elif path != None:
                with codecs.open(path, encoding='utf-8') as f:
                    return f.read()
            else:
                return None

        xform = content_or_path(xform_raw, xform_path)
        instance = content_or_path(instance_raw, instance_path)

        self.form = load_form(xform, instance, extensions, preload_data)
        self.fem = FormEntryModel(self.form,
                                  FormEntryModel.REPEAT_STRUCTURE_NON_LINEAR)
        self.fec = FormEntryController(self.fem)
        self._parse_current_event()

        self.update_last_activity()
Пример #2
0
    def __init__(self, xform, instance=None, **params):
        self.uuid = params.get('uuid', uuid.uuid4().hex)
        self.nav_mode = params.get('nav_mode', 'prompt')
        self.seq_id = params.get('seq_id', 0)
        self.uses_sql_backend = params.get('uses_sql_backend')

        self.form = load_form(
            xform,
            instance,
            params.get('extensions', []),
            params.get('session_data', {}),
            params.get('api_auth'),
            params.get('form_context', None),
            self.uses_sql_backend,
        )
        self.fem = FormEntryModel(self.form, FormEntryModel.REPEAT_STRUCTURE_NON_LINEAR)
        self.fec = FormEntryController(self.fem)

        if params.get('init_lang'):
            try:
                self.fec.setLanguage(params.get('init_lang'))
            except UnregisteredLocaleException:
                pass # just use default language

        if params.get('cur_index'):
            self.fec.jumpToIndex(self.parse_ix(params.get('cur_index')))

        self._parse_current_event()

        self.staleness_window = 3600. * params['staleness_window']
        self.persist = params.get('persist', settings.PERSIST_SESSIONS)
        self.orig_params = {
            'xform': xform,
            'nav_mode': params.get('nav_mode'),
            'session_data': params.get('session_data'),
            'api_auth': params.get('api_auth'),
            'staleness_window': params['staleness_window'],
        }
        self.update_last_activity()
Пример #3
0
    def __init__(self,
                 xform,
                 instance=None,
                 init_lang=None,
                 session_data={},
                 extensions=[],
                 nav_mode='prompt',
                 api_auth=None):
        self.lock = threading.Lock()
        self.nav_mode = nav_mode
        self.seq_id = 0

        self.form = load_form(xform, instance, extensions, session_data,
                              api_auth)
        self.fem = FormEntryModel(self.form,
                                  FormEntryModel.REPEAT_STRUCTURE_NON_LINEAR)
        self.fec = FormEntryController(self.fem)

        if init_lang is not None:
            self.fec.setLanguage(init_lang)

        self._parse_current_event()

        self.update_last_activity()