def lme_prepare_template(self, key):
     return {
         'page_title': self.format_title('Edit Label'),
         'main_content': self.get_form(
             LabelRestHandler, key,
             dashboard_utils.build_assets_url('labels'))
     }
Esempio n. 2
0
    def get_manage_text_asset(self):
        """Show an edit/save/delete/revert form for a text asset."""
        assert self.app_context.is_editable_fs()
        uri = self.request.get('uri')
        assert uri
        tab_name = self.request.get('tab')

        asset = self.app_context.fs.impl.get(
            os.path.join(appengine_config.BUNDLE_ROOT, uri))
        assert asset
        asset_in_datastore_fs = not is_readonly_asset(asset)

        try:
            asset_in_local_fs = bool(self.local_fs.get(uri))
        except IOError:
            asset_in_local_fs = False

        exit_url = self.canonicalize_url(
            dashboard_utils.build_assets_url(tab_name))
        rest_url = self.canonicalize_url(TextAssetRESTHandler.URI)

        delete_button_caption = 'Delete'
        delete_message = None
        delete_url = None

        if asset_in_datastore_fs:
            delete_message = 'Are you sure you want to delete %s?' % uri
            delete_url = self._get_delete_url(
                TextAssetRESTHandler.URI, uri,
                TextAssetRESTHandler.XSRF_TOKEN_NAME)

        if asset_in_local_fs:
            delete_message = (
                'Are you sure you want to restore %s to the original version? '
                'All your customizations will be lost.' % uri)
            delete_button_caption = 'Restore original'

        # Disable the save button if the payload is not text by setting method
        # to ''.
        save_method = 'put' if is_text_payload(asset.read()) else ''

        form_html = oeditor.ObjectEditor.get_html_for(
            self,
            TextAssetRESTHandler.SCHEMA.get_json_schema(),
            TextAssetRESTHandler.SCHEMA.get_schema_dict(),
            uri,
            rest_url,
            exit_url,
            delete_button_caption=delete_button_caption,
            delete_method='delete',
            delete_message=delete_message,
            delete_url=delete_url,
            required_modules=TextAssetRESTHandler.REQUIRED_MODULES,
            save_method=save_method,
        )
        self.render_page(
            {
                'page_title': self.format_title('Edit ' + uri),
                'main_content': form_html,
            }, 'assets', tab_name)
 def qgmae_prepare_template(self, key):
     template_values = {}
     template_values['page_title'] = self.format_title('Edit Question Group')
     template_values['main_content'] = self.get_form(
         QuestionGroupRESTHandler, key,
         dashboard_utils.build_assets_url('edit_questions'))
     return template_values
Esempio n. 4
0
 def tme_prepare_template(self, key):
     return {
         'page_title': self.format_title('Edit Track'),
         'main_content': self.get_form(
             TrackRestHandler, key,
             dashboard_utils.build_assets_url('edit_tracks'))
     }
 def lme_prepare_template(self, key):
     return {
         'page_title': self.format_title('Edit Label'),
         'main_content': self.get_form(
             LabelRestHandler, key,
             dashboard_utils.build_assets_url('labels'))
     }
Esempio n. 6
0
    def get_manage_asset(self):
        """Show an upload/delete dialog for assets."""

        key = self.request.get('key').lstrip('/').rstrip('/')
        if not _is_asset_in_allowed_bases(key):
            raise ValueError('Cannot add/edit asset with key "%s" ' % key +
                             'which is not under a valid asset path')
        fs = self.app_context.fs.impl

        delete_url = None
        delete_method = None
        delete_message = None
        auto_return = False
        if fs.isfile(fs.physical_to_logical(key)):
            delete_url = self._get_delete_url(FilesItemRESTHandler.URI, key,
                                              'delete-asset')
            delete_method = 'delete'
        else:
            # Sadly, since we don't know the name of the asset when we build
            # the form, the form can't update itself to show the uploaded
            # asset when the upload completes.  Rather than continue to
            # show a blank form, bring the user back to the assets list.
            auto_return = True

        if self._is_displayable_asset(key):
            json = AssetItemRESTHandler.DISPLAYABLE_SCHEMA_JSON
            ann = AssetItemRESTHandler.DISPLAYABLE_SCHEMA_ANNOTATIONS_DICT
        else:
            json = AssetItemRESTHandler.UNDISPLAYABLE_SCHEMA_JSON
            ann = AssetItemRESTHandler.UNDISPLAYABLE_SCHEMA_ANNOTATIONS_DICT

        tab_name = self.request.get('tab')
        exit_url = self.canonicalize_url(
            dashboard_utils.build_assets_url(tab_name))
        rest_url = self.canonicalize_url(AssetItemRESTHandler.URI)

        form_html = oeditor.ObjectEditor.get_html_for(
            self,
            json,
            ann,
            key,
            rest_url,
            exit_url,
            save_method='upload',
            save_button_caption='Upload',
            auto_return=auto_return,
            delete_url=delete_url,
            delete_method=delete_method,
            delete_message=delete_message,
            required_modules=AssetItemRESTHandler.REQUIRED_MODULES,
            additional_dirs=[
                os.path.join(dashboard_utils.RESOURCES_DIR, 'js')
            ],
            extra_js_files=['multiple_file_load.js'])

        template_values = {}
        template_values['page_title'] = self.format_title('Manage Asset')
        template_values['page_description'] = messages.UPLOAD_ASSET_DESCRIPTION
        template_values['main_content'] = form_html
        self.render_page(template_values, 'assets', tab_name)
Esempio n. 7
0
    def get_manage_text_asset(self):
        """Show an edit/save/delete/revert form for a text asset."""
        assert self.app_context.is_editable_fs()
        uri = self.request.get('uri')
        assert uri
        tab_name = self.request.get('tab')

        asset = self.app_context.fs.impl.get(
            os.path.join(appengine_config.BUNDLE_ROOT, uri))
        assert asset
        asset_in_datastore_fs = not is_readonly_asset(asset)

        try:
            asset_in_local_fs = bool(self.local_fs.get(uri))
        except IOError:
            asset_in_local_fs = False

        exit_url = self.canonicalize_url(
            dashboard_utils.build_assets_url(tab_name))
        rest_url = self.canonicalize_url(TextAssetRESTHandler.URI)

        delete_button_caption = 'Delete'
        delete_message = None
        delete_url = None

        if asset_in_datastore_fs:
            delete_message = 'Are you sure you want to delete %s?' % uri
            delete_url = self._get_delete_url(
                TextAssetRESTHandler.URI, uri,
                TextAssetRESTHandler.XSRF_TOKEN_NAME)

        if asset_in_local_fs:
            delete_message = (
                'Are you sure you want to restore %s to the original version? '
                'All your customizations will be lost.' % uri)
            delete_button_caption = 'Restore original'

        # Disable the save button if the payload is not text by setting method
        # to ''.
        save_method = 'put' if is_text_payload(asset.read()) else ''

        form_html = oeditor.ObjectEditor.get_html_for(
            self,
            TextAssetRESTHandler.SCHEMA.get_json_schema(),
            TextAssetRESTHandler.SCHEMA.get_schema_dict(),
            uri,
            rest_url,
            exit_url,
            delete_button_caption=delete_button_caption,
            delete_method='delete',
            delete_message=delete_message,
            delete_url=delete_url,
            required_modules=TextAssetRESTHandler.REQUIRED_MODULES,
            save_method=save_method,
        )
        self.render_page({
            'page_title': self.format_title('Edit ' + uri),
            'main_content': form_html,
        }, 'assets', tab_name)
Esempio n. 8
0
 def qgmae_prepare_template(self, key):
     template_values = {}
     template_values['page_title'] = self.format_title(
         'Edit Question Group')
     template_values['main_content'] = self.get_form(
         QuestionGroupRESTHandler, key,
         dashboard_utils.build_assets_url('questions'))
     return template_values
 def tme_prepare_template(self, key):
     return {
         'page_title':
         self.format_title('Edit Track'),
         'main_content':
         self.get_form(TrackRestHandler, key,
                       dashboard_utils.build_assets_url('edit_tracks'))
     }
Esempio n. 10
0
    def qmae_prepare_template(self, rest_handler, key=''):
        """Build the Jinja template for adding a question."""
        template_values = {}
        template_values['page_title'] = self.format_title('Edit Question')
        template_values['main_content'] = self.get_form(
            rest_handler, key,
            dashboard_utils.build_assets_url('questions'))

        return template_values
Esempio n. 11
0
    def get_manage_asset(self):
        """Show an upload/delete dialog for assets."""

        path = self.request.get('key')
        key = asset_paths.as_key(path)
        if not asset_paths.AllowedBases.is_path_allowed(path):
            raise ValueError('Cannot add/edit asset with key "%s" ' % key +
                             'which is not under a valid asset path')
        fs = self.app_context.fs.impl

        delete_url = None
        delete_method = None
        delete_message = None
        auto_return = False
        if fs.isfile(fs.physical_to_logical(key)):
            delete_url = self._get_delete_url(FilesItemRESTHandler.URI, key,
                                              'delete-asset')
            delete_method = 'delete'
        else:
            # Sadly, since we don't know the name of the asset when we build
            # the form, the form can't update itself to show the uploaded
            # asset when the upload completes.  Rather than continue to
            # show a blank form, bring the user back to the assets list.
            auto_return = True

        details = AssetItemRESTHandler.get_schema_details(path)
        json, ann = details.json, details.annotations
        from_action = self.request.get('from_action')
        exit_url = self.canonicalize_url(
            dashboard_utils.build_assets_url(from_action))
        rest_url = self.canonicalize_url(AssetItemRESTHandler.URI)

        form_html = oeditor.ObjectEditor.get_html_for(
            self,
            json,
            ann,
            key,
            rest_url,
            exit_url,
            save_method='upload',
            save_button_caption='Upload',
            auto_return=auto_return,
            delete_url=delete_url,
            delete_method=delete_method,
            delete_message=delete_message,
            required_modules=AssetItemRESTHandler.REQUIRED_MODULES,
            additional_dirs=[
                os.path.join(dashboard_utils.RESOURCES_DIR, 'js')
            ])

        template_values = {}
        template_values['page_title'] = self.format_title('Manage Asset')
        template_values['main_content'] = form_html

        self.render_page(template_values, in_action=from_action)
Esempio n. 12
0
    def get_manage_asset(self):
        """Show an upload/delete dialog for assets."""

        key = self.request.get('key').lstrip('/').rstrip('/')
        if not _is_asset_in_allowed_bases(key):
            raise ValueError('Cannot add/edit asset with key "%s" ' % key +
                             'which is not under a valid asset path')
        fs = self.app_context.fs.impl

        delete_url = None
        delete_method = None
        delete_message = None
        auto_return = False
        if fs.isfile(fs.physical_to_logical(key)):
            delete_url = self._get_delete_url(
                FilesItemRESTHandler.URI, key, 'delete-asset')
            delete_method = 'delete'
        else:
            # Sadly, since we don't know the name of the asset when we build
            # the form, the form can't update itself to show the uploaded
            # asset when the upload completes.  Rather than continue to
            # show a blank form, bring the user back to the assets list.
            auto_return = True

        if self._is_displayable_asset(key):
            json = AssetItemRESTHandler.DISPLAYABLE_SCHEMA_JSON
            ann = AssetItemRESTHandler.DISPLAYABLE_SCHEMA_ANNOTATIONS_DICT
        else:
            json = AssetItemRESTHandler.UNDISPLAYABLE_SCHEMA_JSON
            ann = AssetItemRESTHandler.UNDISPLAYABLE_SCHEMA_ANNOTATIONS_DICT

        tab_name = self.request.get('tab')
        exit_url = self.canonicalize_url(
            dashboard_utils.build_assets_url(tab_name))
        rest_url = self.canonicalize_url(AssetItemRESTHandler.URI)

        form_html = oeditor.ObjectEditor.get_html_for(
            self, json, ann, key, rest_url, exit_url, save_method='upload',
            save_button_caption='Upload', auto_return=auto_return,
            delete_url=delete_url, delete_method=delete_method,
            delete_message=delete_message,
            required_modules=AssetItemRESTHandler.REQUIRED_MODULES,
            additional_dirs=[os.path.join(dashboard_utils.RESOURCES_DIR, 'js')])

        template_values = {}
        template_values['page_title'] = self.format_title('Manage Asset')
        template_values['page_description'] = messages.UPLOAD_ASSET_DESCRIPTION
        template_values['main_content'] = form_html
        self.render_page(template_values, 'assets', tab_name)
Esempio n. 13
0
    def get_manage_asset(self):
        """Show an upload/delete dialog for assets."""

        path = self.request.get('key')
        key = asset_paths.as_key(path)
        if not asset_paths.AllowedBases.is_path_allowed(path):
            raise ValueError('Cannot add/edit asset with key "%s" ' % key +
                             'which is not under a valid asset path')
        fs = self.app_context.fs.impl

        delete_url = None
        delete_method = None
        delete_message = None
        auto_return = False
        if fs.isfile(fs.physical_to_logical(key)):
            delete_url = self._get_delete_url(
                FilesItemRESTHandler.URI, key, 'delete-asset')
            delete_method = 'delete'
        else:
            # Sadly, since we don't know the name of the asset when we build
            # the form, the form can't update itself to show the uploaded
            # asset when the upload completes.  Rather than continue to
            # show a blank form, bring the user back to the assets list.
            auto_return = True

        details = AssetItemRESTHandler.get_schema_details(path)
        json, ann = details.json, details.annotations
        from_action = self.request.get('from_action')
        exit_url = self.canonicalize_url(
            dashboard_utils.build_assets_url(from_action))
        rest_url = self.canonicalize_url(AssetItemRESTHandler.URI)

        form_html = oeditor.ObjectEditor.get_html_for(
            self, json, ann, key, rest_url, exit_url, save_method='upload',
            save_button_caption='Upload', auto_return=auto_return,
            delete_url=delete_url, delete_method=delete_method,
            delete_message=delete_message,
            required_modules=AssetItemRESTHandler.REQUIRED_MODULES,
            additional_dirs=[os.path.join(dashboard_utils.RESOURCES_DIR, 'js')])

        template_values = {}
        template_values['page_title'] = self.format_title('Manage Asset')
        template_values['main_content'] = form_html

        self.render_page(template_values, in_action=from_action)
Esempio n. 14
0
 def lme_prepare_template(self, key):
     return {
         "page_title": self.format_title("Edit Label"),
         "main_content": self.get_form(LabelRestHandler, key, dashboard_utils.build_assets_url("edit_labels")),
     }