Exemplo n.º 1
0
    def upload_form(self):
        with tags.form(
            id=self.config['upload_name'],
            onsubmit=self.config['onsubmit'],
            enctype='multipart/form-data',
            method=self.config['upload_method'],
            action=self.config['upload_route'],
            cls='card p-3 bg-light'):

            tags.h5('Upload an image', cls='card-title')

            with tags.div(cls='form-group row'):
                with tags.div(cls='col-12'):
                    # This requires JavaScript to show the filename.
                    # https://github.com/Johann-S/bs-custom-file-input
                    #
                    # 'style' is necessary to avoid overlapping in Safari and
                    # Chrome on iOS:
                    # https://github.com/twbs/bootstrap/issues/26933
                    with tags.div(cls='custom-file', style='overflow: hidden;'):
                        tags.input(
                            type='file', cls='custom-file-input p-1 rounded',
                            id=self.config['upload_name'], name=self.config['upload_name'])
                        tags.label(
                            'Choose file', fr=self.config['upload_name'],
                            cls='custom-file-label bg-light')

            with tags.div(cls='form-group row'):
                with tags.div(cls='col-3'):
                    with tags.button(type='submit', cls='btn btn-primary'):
                        util.text('Submit')
Exemplo n.º 2
0
def Page():
    doc = document()
    with doc.head:
        link_("https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css")
        link_("https://extra-uru1z3cxu.now.sh/css/extra.css")
        link_(
            "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.8.2/css/all.css"
        )
        script_(
            'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js'
        )
        script_('http://intercoolerjs.org/release/intercooler-1.2.2.js')
    with doc.body:
        with dom.div(cls=CENTER_FRAME) as CenterFrame:
            with dom.div(cls=CARD) as Card:
                with dom.form(UPLOAD_FORM_ATTRS) as UploadForm:
                    dom.i(cls=UPLOAD_ICON,
                          onclick='''$('#fileupload').click()''')
                    dom.p("Find File", id=1, cls="text-gray-500 mt-4")
                    dom.button("Upload", type="submit", cls=BUTTON)
                    dom.input(
                        cls="hidden",
                        type="file",
                        name="image",
                        id="fileupload",
                        onchange=
                        '''$('#1').text(this.value.split("\\\\").pop(-1))''')
            with dom.div(id="there", cls=RESULT_CONTAINER) as ResultContainer:
                dom.span(id="here")  #新增
    return doc.render()
Exemplo n.º 3
0
def page():
    doc = document()
    with doc.head:
        link_("https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css")
        link_("https://extra-uru1z3cxu.now.sh/css/extra.css")
        link_("https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.8.2/css/all.css")
        dom.script(src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js')

    with doc.body:
        with dom.div(cls=CENTER_FRAME)as CenterFrame:
            with dom.div(cls=CARD) as Card:
                with dom.form(cls=UPLOAD_FORM) as UploadForm:
                    dom.i(cls=UPLOAD_ICON,onclick=''' $('#fileupload').click()''')
                    dom.p("Find File",id =1,cls="text-gray-500 mt-4")
                    dom.button("Upload",cls=BUTTON)
                    dom.input(cls='hidden',type="file",id="fileupload",onchange=''' $('#1').text(this.value.split("\\\\").pop(-1))''')
            with dom.div(cls=RESULT_CONTAINER) as ResultContainer:
                for _ in range(4):
                    with dom.div(cls=RESULT_ITEM) as ResultItem:
                        dom.p("filename.jpg",cls="text-xl text-gray-400")
                        dom.i(cls="fas fa-download text-xl text-gray-400")

            with dom.div() as ResultContainer:
                pass
    return doc.render()
    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
Exemplo n.º 5
0
    def visit_Search(self, node):
        form = tags.form(target="_blank", method="get", role="search")
        form['role'] = 'search'
        form[
            'class'] = 'navbar-form navbar-right' if node.navbar_right else 'navbar-form navbar-left'

        # action may also have a 'get_url()' method, in which case we render
        if node.action is not None:
            if hasattr(node.action, 'get_url'):
                form['action'] = node.action.get_url()
            else:
                form['action'] = node.action

        div = form.add(tags.div(_class='form-group'))
        search_input = div.add(
            tags.input(type="text",
                       _class="form-control",
                       placeholder=node.input_placeholder))
        if node.input_id is not None:
            search_input['id'] = node.input_id
        if node.input_name is not None:
            search_input['name'] = node.input_name

        btn = form.add(tags.button(type="submit", _class="btn btn-default"))
        if node.icon is not None:
            btn.add(tags.i(_class=str(node.icon)))

        if node.btn_text is not None:
            btn.add(tags.span(node.btn_text))

        return form
Exemplo n.º 6
0
    def visit_Form(self, node):
        form = tags.form(_class=' '.join(['form'] + self.extra_classes))

        if self.action:
            form['action'] = self.action

        if self.form_id:
            form['id'] = self.form_id

        if self.method:
            form['method'] = self.method

        # prepare enctype, this will be auto-updated by file fields if
        # necessary
        self._real_enctype = self.enctype

        # render fields
        for field in node:
            elem = self.visit(field)
            form.add(elem)

        if self._real_enctype:
            form['enctype'] = self._real_enctype

        return form
Exemplo n.º 7
0
    def get_html_forms(self, dataset_name_form=True, temporal_coverage=True):
        """overrides the base class function"""

        root_div = div("{% load crispy_forms_tags %}")
        with root_div:
            super(GenericFileMetaData, self).get_html_forms()
            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 btn-form-submit",
                                style="display: none;")  # TODO: TESTING

        template = Template(root_div.render())
        context_dict = dict()
        temp_cov_form = self.get_temporal_coverage_form()
        spatial_cov_form = self.get_spatial_coverage_form(allow_edit=True)
        update_action = "/hsapi/_internal/GenericLogicalFile/{0}/{1}/{2}/update-file-metadata/"
        create_action = "/hsapi/_internal/GenericLogicalFile/{0}/{1}/add-file-metadata/"

        element_name = "coverage"
        if self.temporal_coverage or self.spatial_coverage:
            if self.temporal_coverage:
                temp_action = update_action.format(self.logical_file.id,
                                                   element_name,
                                                   self.temporal_coverage.id)
                temp_cov_form.action = temp_action
            else:
                temp_action = create_action.format(self.logical_file.id,
                                                   element_name)
                temp_cov_form.action = temp_action

            if self.spatial_coverage:
                spatial_action = update_action.format(self.logical_file.id,
                                                      element_name,
                                                      self.spatial_coverage.id)
                spatial_cov_form.action = spatial_action
            else:
                spatial_action = create_action.format(self.logical_file.id,
                                                      element_name)
                spatial_cov_form.action = spatial_action
        else:
            action = create_action.format(self.logical_file.id, element_name)
            temp_cov_form.action = action
            spatial_cov_form.action = action

        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
Exemplo n.º 8
0
    def visit_Form(self, node):
        form = tags.form(_class=' '.join(['form'] + self.extra_classes))

        if self.action:
            form['action'] = self.action

        if self.form_id:
            form['id'] = self.form_id

        if self.method:
            form['method'] = self.method

        # prepare enctype, this will be auto-updated by file fields if
        # necessary
        self._real_enctype = self.enctype

        # render fields
        for field in node:
            elem = self.visit(field)
            form.add(elem)

        if self._real_enctype:
            form['enctype'] = self._real_enctype

        return form
Exemplo n.º 9
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
Exemplo n.º 10
0
    def visit_Form(self, node):
        form = tags.form()

        if self.extra_classes:
            form['class'] = ' '.join(self.extra_classes)

        if self.action:
            print(self.action)
            form['action'] = self.action

        if self.form_id:
            form['id'] = self.form_id

        if self.method:
            form['method'] = self.method

        self._real_enctype = self.enctype

        for field in node:
            form.add(self._wrapped_field(field))

        if self._real_enctype:
            form['enctype'] = self._real_enctype

        return form
Exemplo n.º 11
0
    def get_update_netcdf_file_html_form(self):
        form_action = "/hsapi/_internal/netcdf_update/{}/".\
            format(self.resource.short_id)
        style = "display:none;"
        root_div = div(id="netcdf-file-update",
                       cls="space-bottom",
                       style=style)

        with root_div:
            with div(cls="col-sm-12"):
                with div(cls="alert alert-warning alert-dismissible",
                         role="alert"):
                    div("NetCDF file needs to be synced with metadata changes.",
                        cls='space-bottom')

                    _input(id="metadata-dirty",
                           type="hidden",
                           value="{{ cm.metadata.is_dirty }}")
                    with form(
                            action=form_action,
                            method="post",
                            id="update-netcdf-file",
                    ):
                        div('{% csrf_token %}')
                        button(
                            "Update NetCDF File",
                            type="submit",
                            cls="btn btn-primary",
                            id="id-update-netcdf-file",
                        )

        return root_div
Exemplo n.º 12
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
Exemplo n.º 13
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
Exemplo n.º 14
0
    def get_update_netcdf_file_html_form(self):
        form_action = "/hsapi/_internal/{}/update-netcdf-file/".format(self.id)
        style = "display:none;"
        if self.is_dirty:
            style = "margin-bottom:10px"
        root_div = div(id="div-netcdf-file-update", cls="row", style=style)

        with root_div:
            with div(cls="col-sm-12"):
                with div(cls="alert alert-warning alert-dismissible",
                         role="alert"):
                    strong(
                        "NetCDF file needs to be synced with metadata changes."
                    )
                    input(id="metadata-dirty",
                          type="hidden",
                          value=self.is_dirty)
                    with form(action=form_action,
                              method="post",
                              id="update-netcdf-file"):
                        button("Update NetCDF File",
                               type="button",
                               cls="btn btn-primary",
                               id="id-update-netcdf-file")

        return root_div
Exemplo n.º 15
0
def page():
    doc = document()
    with doc.head:
        link_("https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css")
        link_("https://extra-uru1z3cxu.now.sh/css/extra.css")
        link_("https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.8.2/css/all.css")
        script_("https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js")
        script_("http://intercoolerjs.org/release/intercooler-1.2.2.js")

    with doc.body:
        with dom.div(cls=CENTER_FRAME) as CenterFrame:
            with dom.form(FORM_ATTR):
                with dom.div(cls=LABEL_CARD):
                    dom.label('Write down your mark here',
                              cls="text-white text-xl")
                    dom.input(
                        cls=LABEL_INPUT, type='text', placeholder='your watermark text here', name='mk-text')
                with dom.div(cls=IMG_CARD):
                    with dom.div(cls=IMG_FORM):
                        dom.i(cls=UPLOAD_ICON,
                              onclick='''$('#fileupload').click()''')
                        dom.p("Find File", id="file", cls="text-gray-500 mt-4")
                        dom.input(cls="hidden", type="file", name='bg-img', id="fileupload",
                                  onchange='''$('#file').text(this.value.split("\\\\").pop(-1))''')
                        dom.button('Upload', cls=BUTTON, type='submit')

            with dom.div(cls=RESULT_CONTAINER, id="there") as ResultContainer:
                dom.span(id="here")
    return doc.render()
Exemplo n.º 16
0
 def render_post_form(self, auto_redirect=False):
     form = tag.form(id='payment_redirect_form',
                     action=self.url,
                     method=self.request_method)
     with form:
         for name, value in self.request_data.items():
             tag.input(type='hidden', name=name, value=value)
         tag.input(type='submit', name='submit', value='Продолжить оплату')
     return form.render()
Exemplo n.º 17
0
    def visit_Navbar(self, node):
        node_id = self.id or sha1(str(id(node)).encode()).hexdigest()

        root = tags.nav(
            _class='navbar navbar-expand-md navbar-dark bg-dark fixed-top')

        # title may also have a 'get_url()' method, in which case we render
        # a brand-link
        if node.title is not None:
            if hasattr(node.title, 'get_url'):
                root.add(
                    tags.a(node.title.text,
                           _class='navbar-brand',
                           href=node.title.get_url()))
            else:
                root.add(tags.span(node.title, _class='navbar-brand'))

        btn = root.add(tags.button())
        btn['type'] = 'button'
        btn['class'] = 'navbar-toggler'
        btn['data-toggle'] = 'collapse'
        btn['data-target'] = '#' + node_id
        btn['aria-controls'] = 'navbarCollapse'
        btn['aria-expanded'] = 'false'
        btn['aria-label'] = "Toggle navigation"

        btn.add(tags.span('', _class='navbar-toggler-icon'))

        bar = root.add(
            tags.div(
                _class='navbar-collapse collapse',
                id=node_id,
            ))

        bar_list = bar.add(tags.ul(_class='navbar-nav mr-auto'))

        for item in node.items:
            bar_list.add(self.visit(item))

        search_form = bar.add(tags.form(_class="form-inline mt-2 mt-md-0"))
        # search_input = search_form.add(tags.input(_class="form-control mr-sm-2"))
        # search_input['type'] = "text"
        # search_input['placeholder'] = "Search"
        # search_input['aria-label'] = "Search"

        search_btn = search_form.add(
            tags.button(_class="btn btn-success my-2 my-sm-0"))
        search_btn['type'] = "submit"
        search_btn.add_raw_string('+')

        search_btn = search_form.add(
            tags.button(_class="btn btn-success my-2 my-sm-0"))
        search_btn['type'] = "submit"
        search_btn.add_raw_string('Login')

        return root
Exemplo n.º 18
0
def page():
    doc = document()
    with doc as root:
        with doc.body:  ## form input button;input三个属性:type,name,value
            with dom.form(action="/file",
                          method="post",
                          enctype="multipart/form-data"):
                dom.input(type="file", name="image")
                dom.button("submit", type="submit")
    return root.render()
Exemplo n.º 19
0
def page():
    doc = document()
    with doc as root:
        with doc.body:
            with dom.form(action='/file',
                          method='post',
                          enctype='multipart/form-data'):
                dom.input(type='file', name='image')
                dom.button('提交', type='submit')
    return root.render()
Exemplo n.º 20
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 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()
Exemplo n.º 22
0
    def get_device(self, provider=None, user_code=None, client_id=None):
        """The device authorization endpoint can be used to request device and user codes.
        This endpoint is used to start the device flow authorization process and user code verification.

        User code confirmation::

          GET LOCATION/device/<provider>?user_code=<user code>

        Response::

          HTTP/1.1 200 OK
        """

        if user_code:
            # If received a request with a user code, then prepare a request to authorization endpoint.
            self.log.verbose("User code verification.")
            result = self.server.db.getSessionByUserCode(user_code)
            if not result["OK"] or not result["Value"]:
                return getHTML(
                    "session is expired.",
                    theme="warning",
                    body=result.get("Message"),
                    info="Seems device code flow authorization session %s expired." % user_code,
                )
            session = result["Value"]
            # Get original request from session
            req = createOAuth2Request(dict(method="GET", uri=session["uri"]))
            req.setQueryArguments(id=session["id"], user_code=user_code)

            # Save session to cookie and redirect to authorization endpoint
            authURL = "%s?%s" % (req.path.replace("device", "authorization"), req.query)
            return self.server.handle_response(302, {}, [("Location", authURL)], session)

        # If received a request without a user code, then send a form to enter the user code
        with dom.div(cls="row mt-5 justify-content-md-center") as tag:
            with dom.div(cls="col-auto"):
                dom.div(
                    dom.form(
                        dom._input(type="text", name="user_code"),
                        dom.button("Submit", type="submit", cls="btn btn-submit"),
                        action=self.currentPath,
                        method="GET",
                    ),
                    cls="card",
                )
        return getHTML(
            "user code verification..",
            body=tag,
            icon="ticket-alt",
            info="Device flow required user code. You will need to type user code to continue.",
        )
Exemplo n.º 23
0
def page():
    doc = document()
    with doc.head:
        link_("https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css")
        link_("https://extra-uru1z3cxu.now.sh/css/extra.css")
        link_(
            "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.8.2/css/all.css"
        )
        dom.script(
            src=
            'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js'
        )

    with doc.body:
        with dom.div(cls=CENTER_FRAME) as CenterFrame:
            with dom.form(action='/file',
                          method='post',
                          enctype='multipart/form-data'):
                with dom.div(cls=LABEL_CARD):
                    dom.label('Write down your mark here',
                              cls="text-white text-xl")
                    dom.input(cls=LABEL_INPUT,
                              type='text',
                              placeholder='your watermark text here',
                              name='mk-text')
                with dom.div(cls=IMG_CARD):
                    with dom.div(cls=IMG_FORM):
                        dom.i(cls=UPLOAD_ICON,
                              onclick='''$('#fileupload').click()''')
                        dom.p("Find File", id="file", cls="text-gray-500 mt-4")
                        dom.input(
                            cls="hidden",
                            type="file",
                            name='bg-img',
                            id="fileupload",
                            onchange=
                            '''$('#file').text(this.value.split("\\\\").pop(-1))'''
                        )
                        dom.button('Upload', cls=BUTTON, type='submit')

            with dom.div(cls=RESULT_CONTAINER) as ResultContainer:
                for _ in range(4):
                    with dom.div(cls=RESULT_ITEM) as ResultItem:
                        dom.p("filename.jpg", cls="text-xl text-gray-400")
                        dom.i(cls="fas fa-download text-xl text-gray-400")

    return doc.render()
Exemplo n.º 24
0
    def get_update_netcdf_file_html_form(self):
        form_action = "/hsapi/_internal/{}/update-netcdf-file/".format(self.logical_file.id)
        style = "display:none;"
        self.refresh_from_db()
        if self.is_dirty:
            style = "margin-bottom:15px"
        root_div = div(id="div-netcdf-file-update", cls="row", style=style)

        with root_div:
            with div(cls="col-sm-12"):
                with div(cls="alert alert-warning alert-dismissible", role="alert"):
                    div("NetCDF file needs to be synced with metadata changes.", cls='space-bottom')
                    input(id="metadata-dirty", type="hidden", value=self.is_dirty)
                    with form(action=form_action, method="post", id="update-netcdf-file"):
                        button("Update NetCDF File", type="button", cls="btn btn-primary",
                               id="id-update-netcdf-file")

        return root_div
Exemplo n.º 25
0
    def get_update_netcdf_file_html_form(self):
        form_action = "/hsapi/_internal/netcdf_update/{}/".\
            format(self.resource.short_id)
        style = "display:none;"
        root_div = div(id="netcdf-file-update", cls="space-bottom", style=style)

        with root_div:
            with div(cls="col-sm-12"):
                with div(cls="alert alert-warning alert-dismissible", role="alert"):
                    div("NetCDF file needs to be synced with metadata changes.", cls='space-bottom')

                    input(id="metadata-dirty", type="hidden", value="{{ cm.metadata.is_dirty }}")
                    with form(action=form_action, method="post", id="update-netcdf-file",):
                        div('{% csrf_token %}')
                        button("Update NetCDF File", type="submit", cls="btn btn-primary",
                               id="id-update-netcdf-file",
                               )

        return root_div
Exemplo n.º 26
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;")
Exemplo n.º 27
0
 def get_temporal_coverage_html_form(self):
     # Note: When using this form layout the context variable 'temp_form' must be
     # set prior to calling the template.render(context)
     root_div = div(cls="col-lg-6 col-xs-12",
                    id="temporal-coverage-filetype")
     with root_div:
         with form(id="id-coverage_temporal-file-type",
                   action="{{ temp_form.action }}",
                   method="post",
                   enctype="multipart/form-data"):
             div("{% crispy temp_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;")
     return root_div
Exemplo n.º 28
0
    def url_form(self):
        with tags.form(
            id=self.config['url_name'],
            onsubmit=self.config['onsubmit'],
            method=self.config['url_method'],
            action=self.config['url_route'],
            cls='card p-3 bg-light'):

            tags.h5('Load an image from a URL', cls='card-title')

            with tags.div(cls='form-group row'):
                with tags.div(cls='col-12'):
                    tags.input(
                        type='url', cls='form-control p-1 bg-light rounded',
                        name=self.config['url_name'], placeholder='https://example.com/image.png')

            with tags.div(cls='form-group row'):
                with tags.div(cls='col-3'):
                    with tags.button(type='submit', cls='btn btn-primary'):
                        util.text('Submit')
Exemplo n.º 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()
Exemplo n.º 30
0
    def html(self,
             action: str,
             method: str = 'GET',
             enctype: str = "multipart/form-data",
             id_: str = 'my-form') -> html.html_tag:
        """
        Renders the HTML of the form
        """
        content = html.div(cls='vis-form')

        form_args = dict(action=action,
                         cls='form-horizontal',
                         method=method,
                         enctype=enctype,
                         id=id_)

        form_html = content.add(html.form(**form_args))

        for name, field in self._fields.items():

            row = form_html.add(html.div(cls='form-group row_vertical_offset'))

            label = row.add(html.div(cls='col-sm-4 control-label'))
            label.add_raw_string(str(field.label))

            cell = row.add(html.div(cls='col-sm-8'))
            cell.add_raw_string(field(class_="form-control"))

        # submit button
        button_row = form_html.add(
            html.div(cls='text-right row_vertical_offset'))
        button_row.add(
            html.button('Senden',
                        type="submit",
                        id='submit_form_button',
                        cls='btn btn-success'))

        return content
Exemplo n.º 31
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
Exemplo n.º 32
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())
Exemplo n.º 33
0
    def get_html_forms(self, datatset_name_form=True):
        """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(cls="row"):
                with div(cls="col-lg-6 col-xs-12",
                         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="col-lg-6 col-xs-12",
                         id="spatial-coverage-filetype"):
                    with form(id="id-spatial-coverage-file-type",
                              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(cls="pull-left col-sm-12"):
                # id has to be variables to get the vertical scrollbar
                with div(cls="well", id="variables"):
                    with div(cls="row"):
                        with div("{% for form in variable_formset_forms %}"):
                            with div(cls="col-sm-6 col-xs-12"):
                                with form(id="{{ form.form_id }}",
                                          action="{{ form.action }}",
                                          method="post",
                                          enctype="multipart/form-data"):
                                    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)
        update_action = update_action.format(self.logical_file.id, "coverage",
                                             self.spatial_coverage.id)
        spatial_cov_form.action = update_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
Exemplo n.º 34
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
Exemplo n.º 35
0
    def get_html_forms(self, dataset_name_form=True, temporal_coverage=True, **kwargs):
        """overrides the base class function to generate html needed for metadata editing"""

        root_div = div("{% load crispy_forms_tags %}")
        with root_div:
            super(GeoRasterFileMetaData, self).get_html_forms()
            with div(id="spatial-coverage-filetype"):
                with form(id="id-spatial-coverage-file-type",
                          cls='hs-coordinates-picker', data_coordinates_type="point",
                          action="{{ coverage_form.action }}",
                          method="post", enctype="multipart/form-data"):
                    div("{% crispy 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;")

                div("{% crispy orig_coverage_form %}", cls="content-block")

                div("{% crispy cellinfo_form %}", cls='content-block')

                with div(id="variables", cls="content-block"):
                    div("{% for form in bandinfo_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 btn-form-submit",
                                       style="display: none;")
                    div("{% endfor %}")

        template = Template(root_div.render())
        context_dict = dict()

        context_dict["orig_coverage_form"] = self.get_original_coverage_form()
        context_dict["cellinfo_form"] = self.get_cellinfo_form()
        temp_cov_form = self.get_temporal_coverage_form()

        update_action = "/hsapi/_internal/GeoRasterLogicalFile/{0}/{1}/{2}/update-file-metadata/"
        create_action = "/hsapi/_internal/GeoRasterLogicalFile/{0}/{1}/add-file-metadata/"
        spatial_cov_form = self.get_spatial_coverage_form(allow_edit=True)
        if self.spatial_coverage:
            form_action = update_action.format(self.logical_file.id, "coverage",
                                               self.spatial_coverage.id)
        else:
            form_action = create_action.format(self.logical_file.id, "coverage")

        spatial_cov_form.action = form_action

        if self.temporal_coverage:
            form_action = update_action.format(self.logical_file.id, "coverage",
                                               self.temporal_coverage.id)
            temp_cov_form.action = form_action
        else:
            form_action = create_action.format(self.logical_file.id, "coverage")
            temp_cov_form.action = form_action

        context_dict["coverage_form"] = spatial_cov_form
        context_dict["temp_form"] = temp_cov_form
        context_dict["bandinfo_formset_forms"] = self.get_bandinfo_formset().forms
        context = Context(context_dict)
        rendered_html = template.render(context)
        return rendered_html
Exemplo n.º 36
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
Exemplo n.º 37
0
    def get_html_forms(self,
                       dataset_name_form=True,
                       temporal_coverage=True,
                       **kwargs):
        """overrides the base class function to generate html needed for metadata editing"""

        root_div = div("{% load crispy_forms_tags %}")
        with root_div:
            super(GeoRasterFileMetaData, self).get_html_forms()
            with div(id="spatial-coverage-filetype"):
                with form(id="id-spatial-coverage-file-type",
                          cls='hs-coordinates-picker',
                          data_coordinates_type="point",
                          action="{{ coverage_form.action }}",
                          method="post",
                          enctype="multipart/form-data"):
                    div("{% crispy 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;")

                div("{% crispy orig_coverage_form %}", cls="content-block")

                div("{% crispy cellinfo_form %}", cls='content-block')

                with div(id="variables", cls="content-block"):
                    div("{% for form in bandinfo_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 btn-form-submit",
                                    style="display: none;")
                    div("{% endfor %}")

        template = Template(root_div.render())
        context_dict = dict()

        context_dict["orig_coverage_form"] = self.get_original_coverage_form()
        context_dict["cellinfo_form"] = self.get_cellinfo_form()
        temp_cov_form = self.get_temporal_coverage_form()

        update_action = "/hsapi/_internal/GeoRasterLogicalFile/{0}/{1}/{2}/update-file-metadata/"
        create_action = "/hsapi/_internal/GeoRasterLogicalFile/{0}/{1}/add-file-metadata/"
        spatial_cov_form = self.get_spatial_coverage_form(allow_edit=True)
        if self.spatial_coverage:
            form_action = update_action.format(self.logical_file.id,
                                               "coverage",
                                               self.spatial_coverage.id)
        else:
            form_action = create_action.format(self.logical_file.id,
                                               "coverage")

        spatial_cov_form.action = form_action

        if self.temporal_coverage:
            form_action = update_action.format(self.logical_file.id,
                                               "coverage",
                                               self.temporal_coverage.id)
            temp_cov_form.action = form_action
        else:
            form_action = create_action.format(self.logical_file.id,
                                               "coverage")
            temp_cov_form.action = form_action

        context_dict["coverage_form"] = spatial_cov_form
        context_dict["temp_form"] = temp_cov_form
        context_dict["bandinfo_formset_forms"] = self.get_bandinfo_formset(
        ).forms
        context = Context(context_dict)
        rendered_html = template.render(context)
        return rendered_html
Exemplo n.º 38
0
    def get_html_forms(self, dataset_name_form=True, temporal_coverage=True):
        """overrides the base class function"""

        root_div = div("{% load crispy_forms_tags %}")
        with root_div:
            super(GenericFileMetaDataMixin, self).get_html_forms()
            with div():
                with form(id="id-coverage-spatial-filetype", action="{{ spatial_form.action }}",
                          method="post", enctype="multipart/form-data", cls='hs-coordinates-picker',
                          data_coordinates_type="point"):
                    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 btn-form-submit",
                                   style="display: none;")  # TODO: TESTING
                # for aggregation that contains other aggregations with spatial data,
                # show option to update spatial coverage from contained aggregations
                if self.logical_file.has_children_spatial_data:
                    with div(style="margin-top:20px;"):
                        with div():
                            button("Set spatial coverage from folder contents", type="button",
                                   cls="btn btn-primary pull-right",
                                   id="btn-update-aggregation-spatial-coverage")

        template = Template(root_div.render())
        context_dict = dict()
        temp_cov_form = self.get_temporal_coverage_form()
        spatial_cov_form = self.get_spatial_coverage_form(allow_edit=True)
        update_action = "/hsapi/_internal/{0}/{1}/{2}/{3}/update-file-metadata/"
        create_action = "/hsapi/_internal/{0}/{1}/{2}/add-file-metadata/"

        element_name = "coverage"
        logical_file_class_name = self.logical_file.__class__.__name__
        if self.temporal_coverage or self.spatial_coverage:
            if self.temporal_coverage:
                temp_action = update_action.format(logical_file_class_name, self.logical_file.id,
                                                   element_name, self.temporal_coverage.id)
                temp_cov_form.action = temp_action
            else:
                temp_action = create_action.format(logical_file_class_name, self.logical_file.id,
                                                   element_name)
                temp_cov_form.action = temp_action

            if self.spatial_coverage:
                spatial_action = update_action.format(logical_file_class_name, self.logical_file.id,
                                                      element_name, self.spatial_coverage.id)
                spatial_cov_form.action = spatial_action
            else:
                spatial_action = create_action.format(logical_file_class_name, self.logical_file.id,
                                                      element_name)
                spatial_cov_form.action = spatial_action
        else:
            action = create_action.format(logical_file_class_name, self.logical_file.id,
                                          element_name)
            temp_cov_form.action = action
            spatial_cov_form.action = action

        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