Exemple #1
0
    def show_edit(self):
        '''Displays the form editor, for new or existing forms.'''
        form_id = self.request.matchdict['id']
        fields_config_json = json.dumps({ft[0]: ft[1](Field()).initJson() \
                                         for ft in fields_dict.items()})
        if form_id == 'new':
            form = Form()
            fields_json = json.dumps([])
        else:
            form = self._get_form_if_belongs_to_user(form_id=form_id)
            fields_json = safe_json_dumps([f.to_dict() for f in form.fields])
            # (indent=1 causes the serialization to be much prettier.)
        dform = d.Form(form_schema, formid='FirstPanel') \
            .render(self.model_to_dict(form, ('name', 'description',
                    'rich', 'use_rich', 'submit_label')))

        # TODO: Consider a caching alternative; this query might be
        # too expensive to stay in this view.
        # List of all system templates
        system_templates = sas.query(FormTemplate) \
            .filter(FormTemplate.system_template_id != None) \
            .order_by(FormTemplate.system_template_id).all()

        # Field types class names
        fieldtypes_json = json.dumps([typ.__class__.__name__ \
                                    for typ in all_fieldtypes])
        return dict(pagetitle=self._pagetitle, form=form, dform=dform,
                    action=self.url('form', action='edit', id=form_id),
                    system_templates=system_templates,
                    fields_json=fields_json, all_fieldtypes=all_fieldtypes,
                    fieldtypes_json=fieldtypes_json,
                    fields_config_json=fields_config_json)
Exemple #2
0
 def collectors(self):
     '''Displays all collectors of a form.'''
     # TODO Don't convert to int here, use the regex in Pyramid routes
     form_id = int(self.request.matchdict['id'])
     form = FormView(self.request)._get_form_if_belongs_to_user(form_id=form_id)
     collectors = [c.to_dict(translator=self.tr) for c in form.collectors]
     collectors_json = safe_json_dumps(collectors)
     return dict(form=form, collectors_json=collectors_json,
         pagetitle=_('Collectors for {0}').format(form.name))
Exemple #3
0
    def list(self):
        '''Displays a list of the entries of a form.'''
        form_id = int(self.request.matchdict['id'])
        form = FormView(self.request)._get_form_if_belongs_to_user(form_id)

        entries = [e.to_dict() for e in entry.pagination(form_id)]
        entries_json = safe_json_dumps(entries)
        return dict(form=form, form_id=form.id, entries_json=entries_json,
                    entries=form.entries,
                    pagetitle=_('Entries for {0}').format(form.name))
Exemple #4
0
    def list(self):
        '''Displays a list of the entries of a form.'''
        form_id = int(self.request.matchdict['id'])
        form = FormView(self.request)._get_form_if_belongs_to_user(form_id)

        entries = [e.to_dict() for e in entry.pagination(form_id)]
        entries_json = safe_json_dumps(entries)
        return dict(form=form,
                    form_id=form.id,
                    entries_json=entries_json,
                    entries=form.entries,
                    pagetitle=_('Entries for {0}').format(form.name))
Exemple #5
0
    def show_edit(self):
        """Displays the form editor, for new or existing forms."""
        form_id = self.request.matchdict["id"]
        fields_config_json = json.dumps({ft[0]: ft[1](Field()).initJson() for ft in fields_dict.items()})
        if form_id == "new":
            form = Form()
            fields_json = json.dumps([])
        else:
            form = self._get_form_if_belongs_to_user(form_id=form_id)
            fields_json = safe_json_dumps([f.to_dict() for f in form.fields])
            # (indent=1 causes the serialization to be much prettier.)
        dform = d.Form(form_schema, formid="FirstPanel").render(
            self.model_to_dict(form, ("name", "description", "rich", "use_rich", "submit_label"))
        )

        # TODO: Consider a caching alternative; this query might be
        # too expensive to stay in this view.
        # List of all system templates
        system_templates = (
            sas.query(FormTemplate)
            .filter(FormTemplate.system_template_id != None)
            .order_by(FormTemplate.system_template_id)
            .all()
        )

        # Field types class names
        fieldtypes_json = json.dumps([typ.__class__.__name__ for typ in all_fieldtypes])
        return dict(
            pagetitle=self._pagetitle,
            form=form,
            dform=dform,
            action=self.url("form", action="edit", id=form_id),
            system_templates=system_templates,
            fields_json=fields_json,
            all_fieldtypes=all_fieldtypes,
            fieldtypes_json=fieldtypes_json,
            fields_config_json=fields_config_json,
        )