示例#1
0
 def get_dataset_name_form(self):
     form_action = "/hsapi/_internal/{0}/{1}/update-filetype-dataset-name/"
     form_action = form_action.format(self.logical_file.__class__.__name__,
                                      self.logical_file.id)
     root_div = div(cls="col-xs-12")
     dataset_name = self.logical_file.dataset_name if self.logical_file.dataset_name else ""
     with root_div:
         with form(action=form_action,
                   id="filetype-dataset-name",
                   method="post",
                   enctype="multipart/form-data"):
             div("{% csrf_token %}")
             with div(cls="form-group"):
                 with div(cls="control-group"):
                     legend('Title')
                     with div(cls="controls"):
                         input(
                             value=dataset_name,
                             cls="form-control input-sm textinput textInput",
                             id="file_dataset_name",
                             maxlength="250",
                             name="dataset_name",
                             type="text")
             with div(cls="row", style="margin-top:10px;"):
                 with div(
                         cls=
                         "col-md-offset-10 col-xs-offset-6 col-md-2 col-xs-6"
                 ):
                     button(
                         "Save changes",
                         cls="btn btn-primary pull-right btn-form-submit",
                         style="display: none;",
                         type="button")
     return root_div
示例#2
0
    def get_html(self, pretty=True):
        """Generates html code for displaying data for this metadata element"""

        root_div = div(cls="content-block")

        def get_th(heading_name):
            return th(heading_name, cls="text-muted")

        with root_div:
            legend('Cell Information')
            with table(cls='custom-table'):
                with tbody():
                    with tr():
                        get_th('Rows')
                        td(self.rows)
                    with tr():
                        get_th('Columns')
                        td(self.columns)
                    with tr():
                        get_th('Cell Size X Value')
                        td(self.cellSizeXValue)
                    with tr():
                        get_th('Cell Size Y Value')
                        td(self.cellSizeYValue)
                    with tr():
                        get_th('Cell Data Type')
                        td(self.cellDataType)

        return root_div.render(pretty=pretty)
示例#3
0
    def get_ncdump_html(self):
        """
        Generates html code to display the contents of the ncdump text file. The generated html
        is used for netcdf file type metadata view and edit modes.
        :return:
        """

        nc_dump_div = div()
        nc_dump_res_file = None
        for f in self.logical_file.files.all():
            if f.extension == ".txt":
                nc_dump_res_file = f
                break
        if nc_dump_res_file is not None:
            nc_dump_div = div(style="clear: both", cls="col-xs-12")
            with nc_dump_div:
                legend("NetCDF Header Information")
                p(nc_dump_res_file.full_path[33:])
                header_info = nc_dump_res_file.resource_file.read()
                header_info = header_info.decode('utf-8')
                textarea(header_info,
                         readonly="",
                         rows="15",
                         cls="input-xlarge",
                         style="min-width: 100%")

        return nc_dump_div
示例#4
0
    def get_html(self, pretty=True):
        """Generates html code for displaying data for this metadata element"""

        root_div = div(cls="content-block")

        def get_th(heading_name):
            return th(heading_name, cls="text-muted")

        with root_div:
            legend('Spatial Reference')
            div('Coordinate Reference System', cls='text-muted space-top')
            div(self.value.get('projection', ''))
            div('Coordinate Reference System Unit', cls='text-muted space-top')
            div(self.value['units'])
            div('Datum', cls='text-muted space-top')
            div(self.value.get('datum', ''))
            div('Coordinate String', cls='text-muted space-top')
            div(self.value.get('projection_string', ''), style="word-break: break-all;")
            h4('Extent', cls='space-top')
            with table(cls='custom-table'):
                with tbody():
                    with tr():
                        get_th('North')
                        td(self.value['northlimit'])
                    with tr():
                        get_th('West')
                        td(self.value['westlimit'])
                    with tr():
                        get_th('South')
                        td(self.value['southlimit'])
                    with tr():
                        get_th('East')
                        td(self.value['eastlimit'])

        return root_div.render(pretty=pretty)
示例#5
0
    def get_html(self, pretty=True):
        """Generates html code for displaying data for this metadata element"""

        root_div = div(cls="content-block")

        def get_th(heading_name):
            return th(heading_name, cls="text-muted")

        with root_div:
            legend('Cell Information')
            with table(cls='custom-table'):
                with tbody():
                    with tr():
                        get_th('Rows')
                        td(self.rows)
                    with tr():
                        get_th('Columns')
                        td(self.columns)
                    with tr():
                        get_th('Cell Size X Value')
                        td(self.cellSizeXValue)
                    with tr():
                        get_th('Cell Size Y Value')
                        td(self.cellSizeYValue)
                    with tr():
                        get_th('Cell Data Type')
                        td(self.cellDataType)

        return root_div.render(pretty=pretty)
    def get_abstract_form(self):
        form_action = "/hsapi/_internal/{}/update-reftimeseries-abstract/"
        form_action = form_action.format(self.logical_file.id)
        root_div = div(cls="col-xs-12")

        # if json file contains abstract then we don't need this form since abstract can't be
        # edited in that case
        if self.has_abstract_in_json:
            return

        with root_div:
            with form(action=form_action, id="filetype-abstract",
                      method="post", enctype="multipart/form-data"):
                div("{% csrf_token %}")
                with div(cls="form-group"):
                    with div(cls="control-group"):
                        legend('Abstract')
                        with div(cls="controls"):
                            textarea(self.abstract,
                                     cls="form-control input-sm textinput textInput",
                                     id="file_abstract", cols=40, rows=5,
                                     name="abstract")
                with div(cls="row", style="margin-top:10px;"):
                    with div(cls="col-md-offset-10 col-xs-offset-6 col-md-2 col-xs-6"):
                        button("Save changes", cls="btn btn-primary pull-right btn-form-submit",
                               style="display: none;", type="button")
        return root_div
示例#7
0
    def get_abstract_form(self):
        form_action = "/hsapi/_internal/{}/update-reftimeseries-abstract/"
        form_action = form_action.format(self.logical_file.id)
        root_div = div(cls="col-xs-12")

        # if json file contains abstract then we don't need this form since abstract can't be
        # edited in that case at the aggregation level
        if self.has_abstract_in_json:
            return

        with root_div:
            with form(action=form_action, id="filetype-abstract",
                      method="post", enctype="multipart/form-data"):
                div("{% csrf_token %}")
                with div(cls="form-group"):
                    with div(cls="control-group"):
                        legend('Abstract')
                        with div(cls="controls"):
                            abstract = ""
                            if self.abstract:
                                abstract = self.abstract
                            textarea(abstract,
                                     cls="form-control input-sm textinput textInput",
                                     id="file_abstract", cols=40, rows=5,
                                     name="abstract")
                with div(cls="row", style="margin-top:10px;"):
                    with div(cls="col-md-offset-10 col-xs-offset-6 col-md-2 col-xs-6"):
                        button("Save changes", cls="btn btn-primary pull-right btn-form-submit",
                               style="display: none;", type="button")
        return root_div
示例#8
0
    def get_html_forms(self, datatset_name_form=True):
        """generates html forms for all the metadata elements associated with this logical file
        type
        :param datatset_name_form If True then a form for editing dataset_name (title) attribute is
        included
        """
        root_div = div()

        with root_div:
            if datatset_name_form:
                self._get_dataset_name_form()

            keywords_div = div(cls="col-sm-12 content-block",
                               id="filetype-keywords")
            action = "/hsapi/_internal/{0}/{1}/add-file-keyword-metadata/"
            action = action.format(self.logical_file.__class__.__name__,
                                   self.logical_file.id)
            delete_action = "/hsapi/_internal/{0}/{1}/delete-file-keyword-metadata/"
            delete_action = delete_action.format(
                self.logical_file.__class__.__name__, self.logical_file.id)
            with keywords_div:
                legend("Keywords")
                with form(id="id-keywords-filetype",
                          action=action,
                          method="post",
                          enctype="multipart/form-data"):

                    input(id="id-delete-keyword-filetype-action",
                          type="hidden",
                          value=delete_action)
                    with div(cls="tags"):
                        with div(id="add-keyword-wrapper", cls="input-group"):
                            input(id="txt-keyword-filetype",
                                  cls="form-control",
                                  placeholder="keyword",
                                  type="text",
                                  name="keywords")
                            with span(cls="input-group-btn"):
                                a("Add",
                                  id="btn-add-keyword-filetype",
                                  cls="btn btn-success",
                                  type="button")
                    with ul(id="lst-tags-filetype",
                            cls="custom-well tag-list"):
                        for kw in self.keywords:
                            with li(cls="tag"):
                                span(kw)
                                with a():
                                    span(
                                        cls=
                                        "glyphicon glyphicon-remove-circle icon-remove"
                                    )
                p("Duplicate. Keywords not added.",
                  id="id-keywords-filetype-msg",
                  cls="text-danger small",
                  style="display: none;")

            self.get_extra_metadata_html_form()
            self.get_temporal_coverage_html_form()
        return root_div
示例#9
0
    def get_json_file_data_html(self):
        """
        Generates html code to display the contents of the json file. The generated html
        is used for ref timeseries file type metadata in the view and edit modes.
        :return:
        """

        json_res_file = self.logical_file.files.first()
        json_file_content_div = div(style="clear:both;",
                                    cls="col-xs-12 content-block")
        with json_file_content_div:
            legend("Reference Time Series JSON File Content",
                   style="margin-top:20px;")
            p(json_res_file.full_path[33:])
            header_info = self.json_file_content
            if isinstance(header_info, str):
                header_info = unicode(header_info, 'utf-8')

            textarea(header_info,
                     readonly="",
                     rows="15",
                     cls="input-xlarge",
                     style="min-width: 100%")

        return json_file_content_div
示例#10
0
    def get_extra_metadata_html_form(self):
        def get_add_keyvalue_button():
            add_key_value_btn = a(cls="btn btn-success",
                                  type="button",
                                  data_toggle="modal",
                                  data_target="#add-keyvalue-filetype-modal",
                                  style="margin-bottom:20px;")
            with add_key_value_btn:
                with span(cls="glyphicon glyphicon-plus"):
                    span("Add Key/Value", cls="button-label")
            return add_key_value_btn

        if self.extra_metadata:
            root_div_extra = div(cls="col-xs-12", id="filetype-extra-metadata")
            with root_div_extra:
                legend('Extended Metadata')
                get_add_keyvalue_button()
                with table(cls="table table-striped funding-agencies-table",
                           style="width: 100%"):
                    with tbody():
                        with tr(cls="header-row"):
                            th("Key")
                            th("Value")
                            th("Edit/Remove")
                        counter = 0
                        for k, v in self.extra_metadata.iteritems():
                            counter += 1
                            with tr(data_key=k):
                                td(k)
                                td(v)
                                with td():
                                    a(data_toggle="modal",
                                      data_placement="auto",
                                      title="Edit",
                                      cls=
                                      "glyphicon glyphicon-pencil icon-button icon-blue",
                                      data_target="#edit-keyvalue-filetype-modal"
                                      "-{}".format(counter))
                                    a(data_toggle="modal",
                                      data_placement="auto",
                                      title="Remove",
                                      cls=
                                      "glyphicon glyphicon-trash icon-button btn-remove",
                                      data_target=
                                      "#delete-keyvalue-filetype-modal"
                                      "-{}".format(counter))

                self._get_add_key_value_modal_form()
                self._get_edit_key_value_modal_forms()
                self._get_delete_key_value_modal_forms()
            return root_div_extra
        else:
            root_div_extra = div(cls="row", id="filetype-extra-metadata")
            with root_div_extra:
                with div(cls="col-lg-12 content-block"):
                    legend('Extended Metadata')
                    get_add_keyvalue_button()
                    self._get_add_key_value_modal_form()
            return root_div_extra
示例#11
0
 def get_dataset_name_html(self):
     """generates html for viewing dataset name (title)"""
     if self.logical_file.dataset_name:
         dataset_name_div = div(cls="col-xs-12 content-block")
         with dataset_name_div:
             legend("Title")
             p(self.logical_file.dataset_name)
         return dataset_name_div
示例#12
0
def new_user(form, ws_url, errors=None):
    title = 'New User'
    d = _doc(title)
    with d:
        with t.form(action=form.action, method='post'):
            with t.fieldset():
                t.legend(title)
                _errors(errors)
                with t.ol(cls='step_numbers'):
                    with t.li():
                        t.p('First, create a one-word username for yourself (lowercase, no spaces)...'
                            )
                        _text_input(
                            *form.nv('new_username'),
                            ('required', 'autofocus'), {
                                'pattern': valid.re_username,
                                'oninput': 'check_username(this.value)'
                            }, 'Type new username here',
                            _invalid(valid.inv_username,
                                     form.invalid('new_username')))
                        _invalid(valid.inv_username_exists, False,
                                 'username_exists_message')
                    with t.li():
                        t.p("Next, invent a password; type it in twice to make sure you've got it..."
                            )
                        _text_input('password',
                                    None, ('required', ),
                                    {'pattern': valid.re_password},
                                    'Type new password here',
                                    _invalid(valid.inv_password,
                                             form.invalid('password')),
                                    type_='password')
                        _text_input('password_confirmation',
                                    None, ('required', ),
                                    None,
                                    'Type password again for confirmation',
                                    _invalid(
                                        valid.inv_password_confirmation,
                                        form.invalid('password_confirmation'),
                                        'password_match_message'),
                                    type_='password')
                    with t.li():
                        t.p("Finally, type in an email address that can be used if you ever need a password reset (optional, but this may be very useful someday!)..."
                            )
                        _text_input(
                            *form.nv('email'), None,
                            {'pattern': valid.re_email},
                            'Type email address here',
                            _invalid(valid.inv_email, form.invalid('email')))
                t.input_(type="submit", value="Done!")
        t.script(_js_validate_new_user_fields())
        t.script(_js_check_username(ws_url))
    return d.render()
    def get_ts_series_html(self):
        """Generates html for all time series """

        root_div = div(cls="col-xs-12")
        with root_div:
            legend("Reference Time Series", cls="pull-left", style="margin-top:20px;")
            panel_group_div = div(cls="panel-group", id="accordion")
            panel_group_div.add(p("Note: Time series are listed below by site name. "
                                  "Click on a site name to see details.", cls="col-xs-12"))
            for index, series in enumerate(self.time_series_list):
                panel_group_div.add(series.get_html(index + 1))

        return root_div
def test1(form, title_prefix, button_title):
    title = title_prefix + ' Test 1'
    d = _doc(title)
    with d:
        with t.form(action=form.action, method='post'):
            with t.fieldset():
                t.legend(title)
                with t.div(cls='form_row'):
                    _text_input(*form.nv('name'), ('autofocus', 'required'),
                                {'pattern': valid.re_alphanum})
            with t.div(cls='form_row'):
                t.input(type='submit', value=button_title)
    return d.render()
示例#15
0
    def get_ts_series_html(self):
        """Generates html for all time series """

        root_div = div()
        with root_div:
            legend("Reference Time Series")
            panel_group_div = div(cls="panel-group", id="accordion")
            panel_group_div.add(p("Note: Time series are listed below by site name. "
                                  "Click on a site name to see details."))
            for index, series in enumerate(self.time_series_list):
                panel_group_div.add(series.get_html(index + 1))

        return root_div
示例#16
0
 def get_keywords_html(self):
     """generates html for viewing keywords"""
     keywords_div = div()
     if self.keywords:
         keywords_div = div(cls="col-sm-12 content-block")
         with keywords_div:
             legend('Keywords')
             with div(cls="tags"):
                 with ul(id="list-keywords-file-type",
                         cls="tag-list custom-well"):
                     for kw in self.keywords:
                         with li():
                             a(kw, cls="tag")
     return keywords_div
示例#17
0
    def get_html(self):
        """Generates html for displaying all metadata elements associated with this logical file.
        Subclass must override to include additional html for additional metadata it supports.
        """

        root_div = div()
        dataset_name_div = div()
        if self.logical_file.dataset_name:
            with dataset_name_div:
                with table(cls='custom-table'):
                    with tbody():
                        with tr():
                            th("Title", cls="text-muted")
                            td(self.logical_file.dataset_name)
        keywords_div = div()
        if self.keywords:
            keywords_div = div(cls="col-sm-12 content-block")
            with keywords_div:
                legend('Keywords')
                with div(cls="tags"):
                    with ul(id="list-keywords-file-type",
                            cls="tag-list custom-well"):
                        for kw in self.keywords:
                            with li():
                                a(kw, cls="tag")

        extra_metadata_div = div()
        if self.extra_metadata:
            extra_metadata_div = div(cls="col-sm-12 content-block")
            with extra_metadata_div:
                legend('Extended Metadata')
                with table(cls="table table-striped funding-agencies-table",
                           style="width: 100%"):
                    with tbody():
                        with tr(cls="header-row"):
                            th("Key")
                            th("Value")
                        for k, v in self.extra_metadata.iteritems():
                            with tr(data_key=k):
                                td(k)
                                td(v)

        if self.logical_file.dataset_name:
            root_div.add(dataset_name_div)
        if self.keywords:
            root_div.add(keywords_div)
        if self.extra_metadata:
            root_div.add(extra_metadata_div)

        return root_div.render()
示例#18
0
    def _get_field_informations_html(self):
        root_div = div(cls="content-block")
        with root_div:
            legend('Field Information')
            with table(style="width: 100%;"):
                with tbody():
                    with tr(cls='row'):
                        th('Name')
                        th('Type')
                        th('Width')
                        th('Precision')

                    for field_info in self.fieldinformations.all():
                        field_info.get_html(pretty=False)

        return root_div.render()
示例#19
0
    def _get_field_informations_html(self):
        root_div = div(cls="content-block")
        with root_div:
            legend('Field Information')
            with table(style="width: 100%;"):
                with tbody():
                    with tr(cls='row'):
                        th('Name')
                        th('Type')
                        th('Width')
                        th('Precision')

                    for field_info in self.fieldinformations.all():
                        field_info.get_html(pretty=False)

        return root_div.render()
示例#20
0
文件: mannatags.py 项目: bsync/Manna
 def __init__(self, title, **kwargs):
     super().__init__(id=self.id, method=self.method, **kwargs)
     with self.add(tags.fieldset()):
         tags.legend(title, style="display: flex;")
         self.content = tags.div()
         tags.input(name=f"{self.id}", type='hidden')
         tags.input(_class='selection', name='selection', type='hidden')
         tags.input(_class='order', name='order', type='hidden')
         self.submit_tag = tags.input(id=f"{self.submit_id}",
                                      type='submit',
                                      name='submit_button',
                                      _class='submit_button',
                                      value=self.submission_label,
                                      style="clear: both; width: 100%; " +
                                      "margin-top: 20px;")
         self.on_ready_scriptage = ""
    def _get_field_informations_html(self):
        root_div = div(cls="col-md-12 col-sm-12 pull-left",
                       style="margin-bottom:40px;")
        with root_div:
            legend('Field Information')
            with table(style="width: 100%;"):
                with tbody():
                    with tr(cls='row'):
                        th('Name')
                        th('Type')
                        th('Width')
                        th('Precision')

                    for field_info in self.fieldinformations.all():
                        field_info.get_html(pretty=False)

        return root_div.render()
示例#22
0
    def get_html(self, pretty=True):
        """Generates html code for displaying data for this metadata element"""

        root_div = div(cls="col-xs-6 col-sm-6", style="margin-bottom:40px;")

        def get_th(heading_name):
            return th(heading_name, cls="text-muted")

        with root_div:
            legend('Spatial Reference')
            with table(cls='custom-table'):
                with tbody():
                    with tr():
                        get_th('Coordinate Reference System')
                        td(self.value.get('projection', ''))
                    with tr():
                        get_th('Datum')
                        td(self.datum)
                    with tr():
                        get_th('Coordinate String Type')
                        td(self.projection_string_type)
                    with tr():
                        get_th('Coordinate String Text')
                        td(self.projection_string_text)
            h4('Extent')
            with table(cls='custom-table'):
                with tbody():
                    with tr():
                        get_th('North')
                        td(self.value['northlimit'])
                    with tr():
                        get_th('West')
                        td(self.value['westlimit'])
                    with tr():
                        get_th('South')
                        td(self.value['southlimit'])
                    with tr():
                        get_th('East')
                        td(self.value['eastlimit'])
                    with tr():
                        get_th('Unit')
                        td(self.value['units'])

        return root_div.render(pretty=pretty)
示例#23
0
    def get_html(self, pretty=True):
        """Generates html code for displaying data for this metadata element"""

        root_div = div(cls='content-block')

        def get_th(heading_name):
            return th(heading_name, cls="text-muted")

        with root_div:
            legend('Spatial Reference')
            if self.value.get('projection', ''):
                div('Coordinate Reference System', cls='text-muted')
                div(self.value.get('projection', ''))
            if self.datum:
                div('Datum', cls='text-muted space-top')
                div(self.datum)
            if self.projection_string_type:
                div('Coordinate String Type', cls='text-muted space-top')
                div(self.projection_string_type)
            if self.projection_string_text:
                div('Coordinate String Text', cls='text-muted space-top')
                div(self.projection_string_text)

            h4('Extent', cls='space-top')
            with table(cls='custom-table'):
                with tbody():
                    with tr():
                        get_th('North')
                        td(self.value['northlimit'])
                    with tr():
                        get_th('West')
                        td(self.value['westlimit'])
                    with tr():
                        get_th('South')
                        td(self.value['southlimit'])
                    with tr():
                        get_th('East')
                        td(self.value['eastlimit'])
                    with tr():
                        get_th('Unit')
                        td(self.value['units'])

        return root_div.render(pretty=pretty)
示例#24
0
 def get_keywords_html_form(self):
     keywords_div = div(cls="col-sm-12 content-block",
                        id="filetype-keywords")
     action = "/hsapi/_internal/{0}/{1}/add-file-keyword-metadata/"
     action = action.format(self.logical_file.__class__.__name__,
                            self.logical_file.id)
     delete_action = "/hsapi/_internal/{0}/{1}/delete-file-keyword-metadata/"
     delete_action = delete_action.format(
         self.logical_file.__class__.__name__, self.logical_file.id)
     with keywords_div:
         legend("Keywords")
         with form(id="id-keywords-filetype",
                   action=action,
                   method="post",
                   enctype="multipart/form-data"):
             input(id="id-delete-keyword-filetype-action",
                   type="hidden",
                   value=delete_action)
             with div(cls="tags"):
                 with div(id="add-keyword-wrapper", cls="input-group"):
                     input(id="txt-keyword-filetype",
                           cls="form-control",
                           placeholder="keyword",
                           type="text",
                           name="keywords")
                     with span(cls="input-group-btn"):
                         a("Add",
                           id="btn-add-keyword-filetype",
                           cls="btn btn-success",
                           type="button")
             with ul(id="lst-tags-filetype", cls="custom-well tag-list"):
                 for kw in self.keywords:
                     with li(cls="tag"):
                         span(kw)
                         with a():
                             span(
                                 cls=
                                 "glyphicon glyphicon-remove-circle icon-remove"
                             )
         p("Duplicate. Keywords not added.",
           id="id-keywords-filetype-msg",
           cls="text-danger small",
           style="display: none;")
示例#25
0
    def get_html(self, pretty=True):
        """Generates html code for displaying data for this metadata element"""

        root_div = div(cls="content-block", style="margin-bottom:40px;")

        def get_th(heading_name):
            return th(heading_name, cls="text-muted")

        with root_div:
            legend('Geometry Information')
            with table(cls='custom-table'):
                with tbody():
                    with tr():
                        get_th('Geometry Type')
                        td(self.geometryType)
                    with tr():
                        get_th('Feature Count')
                        td(self.featureCount)
        return root_div.render(pretty=pretty)
示例#26
0
 def get_key_value_metadata_html(self):
     """generates html for viewing key/vale extra metadata"""
     extra_metadata_div = div()
     if self.extra_metadata:
         extra_metadata_div = div(cls="col-sm-12 content-block")
         with extra_metadata_div:
             legend('Extended Metadata')
             with table(cls="hs-table table dataTable no-footer",
                        style="width: 100%"):
                 with thead():
                     with tr(cls="header-row"):
                         th("Key")
                         th("Value")
                 with tbody():
                     for k, v in self.extra_metadata.iteritems():
                         with tr(data_key=k):
                             td(k)
                             td(v)
     return extra_metadata_div
示例#27
0
    def get_html(self, pretty=True):
        """Generates html code for displaying data for this metadata element"""

        root_div = div(cls="content-block", style="margin-bottom:40px;")

        def get_th(heading_name):
            return th(heading_name, cls="text-muted")

        with root_div:
            legend('Geometry Information')
            with table(cls='custom-table'):
                with tbody():
                    with tr():
                        get_th('Geometry Type')
                        td(self.geometryType)
                    with tr():
                        get_th('Feature Count')
                        td(self.featureCount)
        return root_div.render(pretty=pretty)
示例#28
0
    def get_json_file_data_html(self):
        """
        Generates html code to display the contents of the json file. The generated html
        is used for ref timeseries file type metadata in the view and edit modes.
        :return:
        """

        json_res_file = self.logical_file.files.first()
        json_file_content_div = div(cls="content-block")
        with json_file_content_div:
            legend("Reference Time Series JSON File Content")
            p(json_res_file.full_path[33:])
            header_info = self.json_file_content
            if isinstance(header_info, str):
                header_info = unicode(header_info, 'utf-8')

            textarea(header_info, readonly="", rows="15",
                     cls="input-xlarge", style="min-width: 100%; resize: vertical;")

        return json_file_content_div
示例#29
0
def login(action, error=None):
    d = _doc('OHS-Test Login')
    with d:
        with t.form(action=action, method='post'):
            with t.fieldset(cls='small_fieldset'):
                t.legend('Log in...')
                _error(error)
                t.div(_text_input('username',
                                  None, ('required', 'autofocus'),
                                  {'pattern': valid.re_username},
                                  invalid_div=_invalid(valid.inv_username,
                                                       False)),
                      cls='field')
                t.div(_text_input('password',
                                  None, ('required', ),
                                  type_='password'),
                      cls='field')
                t.div(t.input_(type="submit", value="Log in!"), cls='field')
        t.script(_js_validate_login_fields())
    return d.render()
示例#30
0
    def get_html(self, pretty=True):
        """Generates html code for displaying data for this metadata element"""

        root_div = div(cls="content-block")

        def get_th(heading_name):
            return th(heading_name, cls="text-muted")

        with root_div:
            legend('Spatial Reference')
            div('Coordinate Reference System', cls='text-muted')
            div(self.projection_name)
            div('Datum', cls='text-muted space-top')
            div(self.datum)
            div('Coordinate String Text', cls='text-muted space-top')
            div(self.projection_string)
            h4('Extent', cls='space-top')
            with table(cls='custom-table'):
                with tbody():
                    with tr():
                        get_th('North')
                        td(self.northlimit)
                    with tr():
                        get_th('West')
                        td(self.westlimit)
                    with tr():
                        get_th('South')
                        td(self.southlimit)
                    with tr():
                        get_th('East')
                        td(self.eastlimit)
                    with tr():
                        get_th('Unit')
                        td(self.unit)

        return root_div.render(pretty=pretty)
示例#31
0
    def get_html(self, pretty=True):
        """Generates html code for displaying data for this metadata element"""

        root_div = div(cls="content-block")

        def get_th(heading_name):
            return th(heading_name, cls="text-muted")

        with root_div:
            legend('Spatial Reference')
            div('Coordinate Reference System', cls='text-muted')
            div(self.projection_name)
            div('Datum', cls='text-muted space-top')
            div(self.datum)
            div('Coordinate String Text', cls='text-muted space-top')
            div(self.projection_string)
            h4('Extent', cls='space-top')
            with table(cls='custom-table'):
                with tbody():
                    with tr():
                        get_th('North')
                        td(self.northlimit)
                    with tr():
                        get_th('West')
                        td(self.westlimit)
                    with tr():
                        get_th('South')
                        td(self.southlimit)
                    with tr():
                        get_th('East')
                        td(self.eastlimit)
                    with tr():
                        get_th('Unit')
                        td(self.unit)

        return root_div.render(pretty=pretty)
示例#32
0
    def get_ncdump_html(self):
        """
        Generates html code to display the contents of the ncdump text file. The generated html
        is used for netcdf file type metadata view and edit modes.
        :return:
        """

        nc_dump_div = div()
        nc_dump_res_file = None
        for f in self.logical_file.files.all():
            if f.extension == ".txt":
                nc_dump_res_file = f
                break
        if nc_dump_res_file is not None:
            nc_dump_div = div(style="clear: both", cls="content-block")
            with nc_dump_div:
                legend("NetCDF Header Information")
                p(nc_dump_res_file.full_path[33:])
                header_info = nc_dump_res_file.resource_file.read()
                header_info = header_info.decode('utf-8')
                textarea(header_info, readonly="", rows="15",
                         cls="input-xlarge", style="min-width: 100%; resize: vertical;")

        return nc_dump_div
示例#33
0
    def get_html(self):
        """overrides the base class function"""

        html_string = super(NetCDFFileMetaData, self).get_html()
        html_string += self.spatial_coverage.get_html()
        html_string += self.originalCoverage.get_html()
        if self.temporal_coverage:
            html_string += self.temporal_coverage.get_html()
        variable_legend = legend("Variables",
                                 cls="pull-left",
                                 style="margin-top:20px;")
        html_string += variable_legend.render()
        for variable in self.variables.all():
            html_string += variable.get_html()

        # ncdump text from the txt file
        html_string += self.get_ncdump_html().render()
        template = Template(html_string)
        context = Context({})
        return template.render(context)
示例#34
0
    def get_html(self):
        """overrides the base class function"""

        html_string = super(NetCDFFileMetaData, self).get_html()
        if self.spatial_coverage:
            html_string += self.spatial_coverage.get_html()
        if self.originalCoverage:
            html_string += self.originalCoverage.get_html()
        if self.temporal_coverage:
            html_string += self.temporal_coverage.get_html()
        variable_legend = legend("Variables")
        html_string += variable_legend.render()
        for variable in self.variables.all():
            html_string += variable.get_html()

        # ncdump text from the txt file
        html_string += self.get_ncdump_html().render()
        template = Template(html_string)
        context = Context({})
        return template.render(context)
示例#35
0
    def get_html(self):
        """overrides the base class function to generate html needed to display metadata
        in view mode"""

        html_string = super(GeoRasterFileMetaData, self).get_html()
        if self.spatial_coverage:
            html_string += self.spatial_coverage.get_html()
        if self.originalCoverage:
            html_string += self.originalCoverage.get_html()

        html_string += self.cellInformation.get_html()
        if self.temporal_coverage:
            html_string += self.temporal_coverage.get_html()
        band_legend = legend("Band Information")
        html_string += band_legend.render()
        for band_info in self.bandInformations:
            html_string += band_info.get_html()

        template = Template(html_string)
        context = Context({})
        return template.render(context)
示例#36
0
    def get_html(self):
        """overrides the base class function to generate html needed to display metadata
        in view mode"""

        html_string = super(GeoRasterFileMetaData, self).get_html()
        if self.spatial_coverage:
            html_string += self.spatial_coverage.get_html()
        if self.originalCoverage:
            html_string += self.originalCoverage.get_html()

        html_string += self.cellInformation.get_html()
        if self.temporal_coverage:
            html_string += self.temporal_coverage.get_html()
        band_legend = legend("Band Information")
        html_string += band_legend.render()
        for band_info in self.bandInformations:
            html_string += band_info.get_html()

        template = Template(html_string)
        context = Context({})
        return template.render(context)
示例#37
0
    def get_html(self):
        """overrides the base class function"""

        html_string = super(RefTimeseriesFileMetaData, self).get_html()
        if not self.has_metadata:
            root_div = div(cls="alert alert-warning alert-dismissible",
                           role="alert")
            with root_div:
                h4("No file level metadata exists for the selected file.")
            html_string = root_div.render()
        else:
            if self.abstract:
                abstract_div = div(cls="col-xs-12 content-block")
                with abstract_div:
                    legend("Abstract")
                    p(self.abstract)

                html_string += abstract_div.render()
            if self.file_version:
                file_ver_div = div(cls="col-xs-12 content-block")
                with file_ver_div:
                    legend("File Version")
                    p(self.file_version)
                html_string += file_ver_div.render()
            if self.symbol:
                symbol_div = div(cls="col-xs-12 content-block")
                with symbol_div:
                    legend("Symbol")
                    if self.symbol.startswith('http'):
                        with p():
                            a(self.symbol, href=self.symbol, target="_blank")
                    else:
                        p(self.symbol)
                html_string += symbol_div.render()
            if self.temporal_coverage:
                html_string += self.temporal_coverage.get_html()

            if self.spatial_coverage:
                html_string += self.spatial_coverage.get_html()

        html_string += self.get_ts_series_html().render()
        html_string += self.get_json_file_data_html().render()
        template = Template(html_string)
        context = Context({})
        return template.render(context)
示例#38
0
    def get_html(self):
        """overrides the base class function"""

        html_string = super(RefTimeseriesFileMetaData, self).get_html()
        if self.abstract:
            abstract_div = div(cls="content-block")
            with abstract_div:
                legend("Abstract")
                p(self.abstract)

            html_string += abstract_div.render()
        if self.file_version:
            file_ver_div = div(cls="content-block")
            with file_ver_div:
                legend("File Version")
                p(self.file_version)
            html_string += file_ver_div.render()
        if self.symbol:
            symbol_div = div(cls="content-block")
            with symbol_div:
                legend("Symbol")
                if self.symbol.startswith('http'):
                    with p():
                        a(self.symbol, href=self.symbol, target="_blank")
                else:
                    p(self.symbol)
            html_string += symbol_div.render()
        if self.temporal_coverage:
            html_string += self.temporal_coverage.get_html()

        if self.spatial_coverage:
            html_string += self.spatial_coverage.get_html()

        html_string += self.get_ts_series_html().render()
        html_string += self.get_json_file_data_html().render()
        template = Template(html_string)
        context = Context({})
        return template.render(context)
示例#39
0
    def get_html(self):
        """overrides the base class function"""

        html_string = super(RefTimeseriesFileMetaData, self).get_html()
        if self.abstract:
            abstract_div = div(cls="content-block")
            with abstract_div:
                legend("Abstract")
                p(self.abstract)

            html_string += abstract_div.render()
        if self.file_version:
            file_ver_div = div(cls="content-block")
            with file_ver_div:
                legend("File Version")
                p(self.file_version)
            html_string += file_ver_div.render()
        if self.symbol:
            symbol_div = div(cls="content-block")
            with symbol_div:
                legend("Symbol")
                if self.symbol.startswith('http'):
                    with p():
                        a(self.symbol, href=self.symbol, target="_blank")
                else:
                    p(self.symbol)
            html_string += symbol_div.render()
        if self.temporal_coverage:
            html_string += self.temporal_coverage.get_html()

        if self.spatial_coverage:
            html_string += self.spatial_coverage.get_html()

        html_string += self.get_ts_series_html().render()
        html_string += self.get_json_file_data_html().render()
        template = Template(html_string)
        context = Context({})
        return template.render(context)
示例#40
0
    def get_html_forms(self, dataset_name_form=True, temporal_coverage=True, **kwargs):
        """overrides the base class function"""

        root_div = div("{% load crispy_forms_tags %}")
        with root_div:
            self.get_update_netcdf_file_html_form()
            super(NetCDFFileMetaData, self).get_html_forms()
            with div():
                with div(cls="content-block", id="original-coverage-filetype"):
                    with form(id="id-origcoverage-file-type",
                              action="{{ orig_coverage_form.action }}",
                              method="post", enctype="multipart/form-data"):
                        div("{% crispy orig_coverage_form %}")
                        with div(cls="row", style="margin-top:10px;"):
                            with div(cls="col-md-offset-10 col-xs-offset-6 "
                                         "col-md-2 col-xs-6"):
                                button("Save changes", type="button",
                                       cls="btn btn-primary pull-right",
                                       style="display: none;")

            with div(cls="content-block", id="spatial-coverage-filetype"):
                with form(id="id-spatial-coverage-file-type",
                          cls='hs-coordinates-picker', data_coordinates_type="box",
                          action="{{ spatial_coverage_form.action }}",
                          method="post", enctype="multipart/form-data"):
                    div("{% crispy spatial_coverage_form %}")
                    with div(cls="row", style="margin-top:10px;"):
                        with div(cls="col-md-offset-10 col-xs-offset-6 "
                                     "col-md-2 col-xs-6"):
                            button("Save changes", type="button",
                                   cls="btn btn-primary pull-right",
                                   style="display: none;")

            with div():
                legend("Variables")
                # id has to be variables to get the vertical scrollbar
                with div(id="variables"):
                    with div("{% for form in variable_formset_forms %}"):
                        with form(id="{{ form.form_id }}", action="{{ form.action }}",
                                  method="post", enctype="multipart/form-data",
                                  cls="well"):
                            div("{% crispy form %}")
                            with div(cls="row", style="margin-top:10px;"):
                                with div(cls="col-md-offset-10 col-xs-offset-6 "
                                             "col-md-2 col-xs-6"):
                                    button("Save changes", type="button",
                                           cls="btn btn-primary pull-right",
                                           style="display: none;")
                    div("{% endfor %}")

            self.get_ncdump_html()

        template = Template(root_div.render())
        temp_cov_form = self.get_temporal_coverage_form()
        update_action = "/hsapi/_internal/NetCDFLogicalFile/{0}/{1}/{2}/update-file-metadata/"
        create_action = "/hsapi/_internal/NetCDFLogicalFile/{0}/{1}/add-file-metadata/"
        if self.temporal_coverage:
            temp_action = update_action.format(self.logical_file.id, "coverage",
                                               self.temporal_coverage.id)
        else:
            temp_action = create_action.format(self.logical_file.id, "coverage")

        temp_cov_form.action = temp_action

        orig_cov_form = self.get_original_coverage_form()
        if self.originalCoverage:
            temp_action = update_action.format(self.logical_file.id, "originalcoverage",
                                               self.originalCoverage.id)
        else:
            temp_action = create_action.format(self.logical_file.id, "originalcoverage")

        orig_cov_form.action = temp_action

        spatial_cov_form = self.get_spatial_coverage_form(allow_edit=True)
        if self.spatial_coverage:
            temp_action = update_action.format(self.logical_file.id, "coverage",
                                               self.spatial_coverage.id)
        else:
            temp_action = create_action.format(self.logical_file.id, "coverage")

        spatial_cov_form.action = temp_action
        context_dict = dict()
        context_dict["temp_form"] = temp_cov_form
        context_dict["orig_coverage_form"] = orig_cov_form
        context_dict["spatial_coverage_form"] = spatial_cov_form
        context_dict["variable_formset_forms"] = self.get_variable_formset().forms
        context = Context(context_dict)
        rendered_html = template.render(context)
        return rendered_html
示例#41
0
    def get_html_forms(self, dataset_name_form=True, temporal_coverage=True):
        """overrides the base class function"""

        root_div = div()
        with root_div:
            div("{% load crispy_forms_tags %}")
            if self.has_title_in_json:
                self.get_dataset_name_html()
            else:
                self.get_dataset_name_form()
            if self.has_keywords_in_json:
                self.get_keywords_html()
            else:
                self.get_keywords_html_form()

            self.get_extra_metadata_html_form()
            abstract_div = div(cls="col-xs-12 content-block")
            with abstract_div:
                if self.has_abstract_in_json:
                    legend("Abstract")
                    p(self.abstract)
                else:
                    self.get_abstract_form()
            if self.file_version:
                file_ver_div = div(cls="col-xs-12 content-block")
                with file_ver_div:
                    legend("File Version")
                    p(self.file_version)

            if self.symbol:
                symbol_div = div(cls="col-xs-12 content-block")
                with symbol_div:
                    legend("Symbol")
                    if self.symbol.startswith('http'):
                        with p():
                            a(self.symbol, href=self.symbol, target="_blank")
                    else:
                        p(self.symbol)

            self.get_temporal_coverage_html_form()
            with div(cls="col-lg-6 col-xs-12"):
                with form(id="id-coverage-spatial-filetype",
                          action="{{ spatial_form.action }}",
                          method="post",
                          enctype="multipart/form-data"):
                    div("{% crispy spatial_form %}")
                    with div(cls="row", style="margin-top:10px;"):
                        with div(cls="col-md-offset-10 col-xs-offset-6 "
                                 "col-md-2 col-xs-6"):
                            button("Save changes",
                                   type="button",
                                   cls="btn btn-primary pull-right",
                                   style="display: none;",
                                   onclick="metadata_update_ajax_submit("
                                   "'id-coverage-spatial-filetype');")

            self.get_ts_series_html()
            self.get_json_file_data_html()

        template = Template(root_div.render())
        context_dict = dict()
        temp_cov_form = self.get_temporal_coverage_form(allow_edit=False)
        spatial_cov_form = self.get_spatial_coverage_form()

        context_dict["temp_form"] = temp_cov_form
        context_dict["spatial_form"] = spatial_cov_form
        context = Context(context_dict)
        rendered_html = template.render(context)
        return rendered_html
示例#42
0
    def get_html_forms(self, dataset_name_form=True, temporal_coverage=True):
        """overrides the base class function"""

        root_div = div()
        with root_div:
            div("{% load crispy_forms_tags %}")
            if self.has_title_in_json:
                # title is in json file - we don't allow the user to edit title (dataset name)
                self.get_dataset_name_html()
            else:
                # title is not in json file - we allow the user to edit title (dataset name)
                self.get_dataset_name_form()
            if self.has_keywords_in_json:
                self.get_keywords_html()
            else:
                self.get_keywords_html_form()

            self.get_extra_metadata_html_form()
            abstract_div = div(cls="content-block")
            with abstract_div:
                if self.has_abstract_in_json:
                    # abstract is in json file - we don't allow the user to edit abstract
                    legend("Abstract")
                    p(self.abstract)
                else:
                    # abstract is not in json file - we allow the user to edit abstract
                    self.get_abstract_form()
            if self.file_version:
                file_ver_div = div(cls="content-block")
                with file_ver_div:
                    legend("File Version")
                    p(self.file_version)

            if self.symbol:
                symbol_div = div(cls="content-block")
                with symbol_div:
                    legend("Symbol")
                    if self.symbol.startswith('http'):
                        with p():
                            a(self.symbol, href=self.symbol, target="_blank")
                    else:
                        p(self.symbol)

            self.get_temporal_coverage_html_form()
            with div(cls="content-block"):
                with form(id="id-coverage-spatial-filetype", action="{{ spatial_form.action }}",
                          method="post", enctype="multipart/form-data"):
                    div("{% crispy spatial_form %}")
                    with div(cls="row", style="margin-top:10px;"):
                        with div(cls="col-md-offset-10 col-xs-offset-6 "
                                     "col-md-2 col-xs-6"):
                            button("Save changes", type="button",
                                   cls="btn btn-primary pull-right",
                                   style="display: none;",
                                   onclick="metadata_update_ajax_submit("
                                           "'id-coverage-spatial-filetype');")

            self.get_ts_series_html()
            self.get_json_file_data_html()

        template = Template(root_div.render())
        context_dict = dict()
        temp_cov_form = self.get_temporal_coverage_form(allow_edit=False)
        spatial_cov_form = self.get_spatial_coverage_form()

        context_dict["temp_form"] = temp_cov_form
        context_dict["spatial_form"] = spatial_cov_form
        context = Context(context_dict)
        rendered_html = template.render(context)
        return rendered_html
示例#43
0
def landing_page(request, page):
    content_model = page.get_content_model()
    edit_resource = page_processors.check_resource_mode(request)

    if not edit_resource:  # non-edit mode
        # get the context from hs_core
        context = page_processors.get_page_context(page, request.user, resource_edit=edit_resource,
                                                   extended_metadata_layout=None, request=request)
        extended_metadata_exists = False

        if content_model.metadata.originalcoverage:
            extended_metadata_exists = True

        context['extended_metadata_exists'] = extended_metadata_exists

        # add the original coverage context
        geom_info_for_view = {}
        geom_info = content_model.metadata.geometryinformation
        if geom_info:
            geom_info_for_view['geometryType'] = geom_info.geometryType
            geom_info_for_view['featureCount'] = geom_info.featureCount
            context['geometry_information'] = geom_info_for_view

        ori_cov_dict = {}
        ori_cov_obj = content_model.metadata.originalcoverage
        if ori_cov_obj:
            ori_cov_dict['northlimit'] = ori_cov_obj.northlimit
            ori_cov_dict['eastlimit'] = ori_cov_obj.eastlimit
            ori_cov_dict['southlimit'] = ori_cov_obj.southlimit
            ori_cov_dict['westlimit'] = ori_cov_obj.westlimit
            ori_cov_dict['projection_string'] = ori_cov_obj.projection_string
            ori_cov_dict['projection_name'] = ori_cov_obj.projection_name
            ori_cov_dict['datum'] = ori_cov_obj.datum
            ori_cov_dict['unit'] = ori_cov_obj.unit
            context['original_coverage'] = ori_cov_dict

        field_info_list = content_model.metadata.fieldinformations.all()
        field_info_list_context = []
        for field_info in field_info_list:
            field_info_dict_item = {}
            field_info_dict_item["fieldName"] = field_info.fieldName
            field_info_dict_item["fieldType"] = field_info.fieldType
            field_info_dict_item["fieldTypeCode"] = field_info.fieldTypeCode
            field_info_dict_item["fieldWidth"] = field_info.fieldWidth
            field_info_dict_item["fieldPrecision"] = field_info.fieldPrecision
            field_info_list_context.append(field_info_dict_item)
        context['field_information'] = field_info_list_context

    else:  # editing mode
        # now editing is allowed for resource specific metadata
        geom_info_for_view = {}
        geom_info = content_model.metadata.geometryinformation
        if geom_info:
            geom_info_for_view['geometryType'] = geom_info.geometryType
            geom_info_for_view['featureCount'] = geom_info.featureCount

        geom_information_form = GeometryInformationForm(initial=geom_info_for_view,
                                                        res_short_id=content_model.short_id,
                                                        allow_edit=False,
                                                        element_id=geom_info.id
                                                        if geom_info else None)

        geom_information_layout = HTML('<div class="form-group col-lg-6 col-xs-12" '
                                       'id="geometryinformation">'
                                       '{% load crispy_forms_tags %}'
                                       '{% crispy geom_information_form %}'
                                       '</div>')

        # origina coverage_form
        ori_cov_obj = content_model.metadata.originalcoverage
        ori_coverage_data_dict = {}
        if ori_cov_obj:
            ori_coverage_data_dict['projection_string'] = ori_cov_obj.projection_string
            ori_coverage_data_dict['projection_name'] = ori_cov_obj.projection_name
            ori_coverage_data_dict['datum'] = ori_cov_obj.datum
            ori_coverage_data_dict['unit'] = ori_cov_obj.unit
            ori_coverage_data_dict['northlimit'] = ori_cov_obj.northlimit
            ori_coverage_data_dict['eastlimit'] = ori_cov_obj.eastlimit
            ori_coverage_data_dict['southlimit'] = ori_cov_obj.southlimit
            ori_coverage_data_dict['westlimit'] = ori_cov_obj.westlimit

        ori_coverage_form = OriginalCoverageForm(initial=ori_coverage_data_dict,
                                                 res_short_id=content_model.short_id,
                                                 allow_edit=False,
                                                 element_id=ori_cov_obj.id
                                                 if ori_cov_obj else None)
        ori_coverage_layout = HTML('<div class="form-group col-lg-6 '
                                   'col-xs-12" id="originalcoverage"> '
                                   '{% load crispy_forms_tags %} '
                                   '{% crispy ori_coverage_form %} '
                                   '</div>')
        root_div = div(cls="col-md-12 col-sm-12 pull-left", style="margin-bottom:40px;")
        with root_div:
            legend('Field Information')
            with table(style="width: 100%;"):
                with tbody():
                    with tr(cls='row'):
                        th('Name')
                        th('Type')
                        th('Width')
                        th('Precision')

                    for field_info in content_model.metadata.fieldinformations.all():
                        field_info.get_html(pretty=False)

        ext_md_layout = Layout(geom_information_layout,
                               ori_coverage_layout,
                               HTML(root_div.render()))

        context = page_processors.get_page_context(page,
                                                   request.user,
                                                   resource_edit=edit_resource,
                                                   extended_metadata_layout=ext_md_layout,
                                                   request=request)
        context['ori_coverage_form'] = ori_coverage_form
        context['geom_information_form'] = geom_information_form

    context['edit_mode'] = edit_resource
    hs_core_context = add_generic_context(request, page)
    context.update(hs_core_context)

    return context
示例#44
0
def landing_page(request, page):
    content_model = page.get_content_model()
    edit_resource = page_processors.check_resource_mode(request)

    if not edit_resource:  # non-edit mode
        # get the context from hs_core
        context = page_processors.get_page_context(page, request.user, resource_edit=edit_resource,
                                                   extended_metadata_layout=None, request=request)
        extended_metadata_exists = False

        if content_model.metadata.originalcoverage:
            extended_metadata_exists = True

        context['extended_metadata_exists'] = extended_metadata_exists

        # add the original coverage context
        geom_info_for_view = {}
        geom_info = content_model.metadata.geometryinformation
        if geom_info:
            geom_info_for_view['geometryType'] = geom_info.geometryType
            geom_info_for_view['featureCount'] = geom_info.featureCount
            context['geometry_information'] = geom_info_for_view

        ori_cov_dict = {}
        ori_cov_obj = content_model.metadata.originalcoverage
        if ori_cov_obj:
            ori_cov_dict['northlimit'] = ori_cov_obj.northlimit
            ori_cov_dict['eastlimit'] = ori_cov_obj.eastlimit
            ori_cov_dict['southlimit'] = ori_cov_obj.southlimit
            ori_cov_dict['westlimit'] = ori_cov_obj.westlimit
            ori_cov_dict['projection_string'] = ori_cov_obj.projection_string
            ori_cov_dict['projection_name'] = ori_cov_obj.projection_name
            ori_cov_dict['datum'] = ori_cov_obj.datum
            ori_cov_dict['unit'] = ori_cov_obj.unit
            context['original_coverage'] = ori_cov_dict

        field_info_list = content_model.metadata.fieldinformations.all()
        field_info_list_context = []
        for field_info in field_info_list:
            field_info_dict_item = {}
            field_info_dict_item["fieldName"] = field_info.fieldName
            field_info_dict_item["fieldType"] = field_info.fieldType
            field_info_dict_item["fieldTypeCode"] = field_info.fieldTypeCode
            field_info_dict_item["fieldWidth"] = field_info.fieldWidth
            field_info_dict_item["fieldPrecision"] = field_info.fieldPrecision
            field_info_list_context.append(field_info_dict_item)
        context['field_information'] = field_info_list_context

    else:  # editing mode
        # now editing is allowed for resource specific metadata
        geom_info_for_view = {}
        geom_info = content_model.metadata.geometryinformation
        if geom_info:
            geom_info_for_view['geometryType'] = geom_info.geometryType
            geom_info_for_view['featureCount'] = geom_info.featureCount

        geom_information_form = GeometryInformationForm(initial=geom_info_for_view,
                                                        res_short_id=content_model.short_id,
                                                        allow_edit=False,
                                                        element_id=geom_info.id
                                                        if geom_info else None)

        geom_information_layout = HTML('<div class="form-group col-lg-6 col-xs-12" '
                                       'id="geometryinformation">'
                                       '{% load crispy_forms_tags %}'
                                       '{% crispy geom_information_form %}'
                                       '</div>')

        # origina coverage_form
        ori_cov_obj = content_model.metadata.originalcoverage
        ori_coverage_data_dict = {}
        if ori_cov_obj:
            ori_coverage_data_dict['projection_string'] = ori_cov_obj.projection_string
            ori_coverage_data_dict['projection_name'] = ori_cov_obj.projection_name
            ori_coverage_data_dict['datum'] = ori_cov_obj.datum
            ori_coverage_data_dict['unit'] = ori_cov_obj.unit
            ori_coverage_data_dict['northlimit'] = ori_cov_obj.northlimit
            ori_coverage_data_dict['eastlimit'] = ori_cov_obj.eastlimit
            ori_coverage_data_dict['southlimit'] = ori_cov_obj.southlimit
            ori_coverage_data_dict['westlimit'] = ori_cov_obj.westlimit

        ori_coverage_form = OriginalCoverageForm(initial=ori_coverage_data_dict,
                                                 res_short_id=content_model.short_id,
                                                 allow_edit=False,
                                                 element_id=ori_cov_obj.id
                                                 if ori_cov_obj else None)
        ori_coverage_layout = HTML('<div class="form-group col-lg-6 '
                                   'col-xs-12" id="originalcoverage"> '
                                   '{% load crispy_forms_tags %} '
                                   '{% crispy ori_coverage_form %} '
                                   '</div>')
        root_div = div(cls="col-md-12 col-sm-12 pull-left", style="margin-bottom:40px;")
        with root_div:
            legend('Field Information')
            with table(style="width: 100%;"):
                with tbody():
                    with tr(cls='row'):
                        th('Name')
                        th('Type')
                        th('Width')
                        th('Precision')

                    for field_info in content_model.metadata.fieldinformations.all():
                        field_info.get_html(pretty=False)

        ext_md_layout = Layout(HTML("<div class='row'>"),
                               geom_information_layout,
                               ori_coverage_layout,
                               HTML("</div>"),
                               HTML(root_div.render()))

        context = page_processors.get_page_context(page,
                                                   request.user,
                                                   resource_edit=edit_resource,
                                                   extended_metadata_layout=ext_md_layout,
                                                   request=request)
        context['ori_coverage_form'] = ori_coverage_form
        context['geom_information_form'] = geom_information_form

    context['edit_mode'] = edit_resource
    hs_core_context = add_generic_context(request, page)
    context.update(hs_core_context)

    return context
示例#45
0
def dominate_register_page():
    """
    第二頁:註冊頁面,對應到  @app.route('/jump')  及其函數   registerpage_run
    目標:利用dominate寫出registerpage的html並在templates資料夾中存成index2.html

    分為三個區塊
    doc = dominate.document()
    with doc.head   (包含css的style;meta確保中文可以運行在utf-8下)
    with doc.body   (包含 a form with 7 legends: name/ password/ student_id/
                    telephone_number/ school_bike_license/ bike_lock_number/ picture uploading and a button submit)

    最後寫入文件中(在templates資料夾中存成index2.html)
    """
    doc = dominate.document(title="registerpage")

    with doc.head:
        tags.meta(name='charset', content="utf-8")
        tags.style("""\
            body {
                background-color: #F9F8F1;
                color: #2C232A;
                font-family: sans-serif;
                font-size: 14;
                text-align: center;
            }
            
             section{
                width: 800px;
                height: 800px;
                position: absolute;
                top: 15%;
                left: 15%;
                overflow: auto;
                text-align: center;
            }

            label{
                cursor: pointer;
                display: inline-block;
                padding: 3px 6px;
                text-align: center;
                width: 500px;
                vertical-align: top;
            }

            input{
                font-size: inherit;
            }

        """)

    with doc.body:
        with tags.div(clas='headline', style='font-size: 20;'):
            tags.h1('Register Page')
        with tags.section():
            with tags.form(method='POST', action="/jump", enctype="multipart/form-data"):
                with tags.legend():
                    tags.label('請輸入姓名(中文)')
                    tags.input(type='text', name='name', size=20)
                with tags.legend():
                    tags.label('請輸入密碼')
                    tags.input(type='text', name='password', size=20)
                with tags.legend():
                    tags.label('請輸入學號(1個大寫英文字母+8個數字)')
                    tags.input(type='text', name='student_id', size=20)
                with tags.legend():
                    tags.label('請輸入電話(請輸入10位數字)')
                    tags.input(type='text', name='telephone_number', size=20)
                with tags.legend():
                    tags.label('是否有台大車證(Y/N)')
                    tags.input(type='text', name='school_bike_license', size=20)
                with tags.legend():
                    tags.label('腳踏車的密碼(選填、請輸入數字)')
                    tags.input(type='text', name='bike_lock_number', size=20)
                with tags.legend():
                    tags.label('上傳圖片')
                    tags.input(type='file', name='photo', size=20)
                with tags.div(cls='button', style="margin:0 auto; width:250px;"):
                    tags.input(type='submit', value='click me', style="width:120px; background-color:pink;")

    fn = 'templates/index2.html'
    with open(file=fn, mode='w', encoding='utf-8') as f:
        f.write(doc.render())