Smart sheet API - replace sheet? - smartsheet-api

I am using the Smart Sheet Python API.
How can I update data completely using the same sheet ID?
My approach was to loop through the columns and delete them (or delete the rowIDs) to clear out the existing sheet. How can I now load new data to the same sheet so I do not have to reshare it, etc?
Is there a more efficient method?

You could also use the copy_sheet function. This will create a copy of your current sheet, and then using the includes parameter you can specify whether the data is copied, or the shared users are included in the copy.
In your situation, it sounds like you want to have a blank copy of the sheet with the same shared users. That call in Python would look something like this:
copy_response = ss_client.Sheets.copy_sheet(
sheet_ID, # sheet_id
ss_client.models.ContainerDestination({
'destination_type': 'home', # folder, workspace, or home
'destination_id': None, # folder_id
'new_name': 'newSheetName'
}),
'shares' # includes
)
print(copy_response)
For a complete list of the available includes take a look at the Smartsheet API Docs section for Copy Sheet.

Related

Filtering a Treeview

I'm new to TypeScript and the VS Code API. I'm looking to learn and am creating an extension that I've wanted a long time in order to do so. I managed to create the functionality I needed (basically a filename filter) using a WebView but I'd prefer using treeview. Here's what I've got:
Unfiltered file list
Filtered file list
Ideally, I'd like to create this:
Is this currently possible and what keywords do I need to research to make it happen?
Thanks
See the demo at https://stackoverflow.com/a/73039858/836330 of filtering in a TreeView. It is not part of the extension-available api though. You could trigger it in an extension with
await vscode.commands.executeCommand('workbench.files.action.focusFilesExplorer');
await vscode.commands.executeCommand('list.find');
but looking at the commit for this functionality I don't think there is any way to populate that find input from an extension - I don't think the command list.find takes any arguments. I tried a couple of ways like
await vscode.commands.executeCommand('list.find', {text: 'findMe'});
await vscode.commands.executeCommand('list.find', {query: 'findMe'});
Other find functionality in vscode can take arguments, but this filtering a treeView is brand new and will probably need a feature request if you want to populate the find input programmatically.

Can you get access to a pages front matter (or other data) in a eleventy (11ty) plugin

I'm creating (would like to create) an eleventy (11ty) plugin that can automatically generate Open Graph images based on a pages data. So in the template:
---
generate_og_image: true
image_text: "text which will be baked into the image"
og_image_filename: some_file_name.jpg
---
#some markdown
...
I can process each file in my .eleventy.js file via plugin using:
module.exports = function (eleventyConfig) {
eleventyConfig.addLinter("og-image-generator", function(content, inputPath, outputPath) {
title = HOW_TO_ACCESS_TEMPLATE_FRONT_MATTER
createImage(title)
});
}
But only have access to the content, inputPath and outputPath of the template.
How can I access the front matter data associated with the Template? Or is there a better way to go about this?
Answering my own question. As #moritzlost mentioned it is not possible directly. I found this workaround.
eleventyComputed allows you to dynamically assign values to keys. It also allows you to call a custom shortcode.
You can pass whatever properties you like from the template into the shortcode. In this case ogImageName the image name, ogImageTemplate a template or background image and text which is the text to be written on that background.
You can even pass in other keys from your front matter and process them as you go.
---
layout: _main.njk
title: "Some title here"
eleventyComputed:
ogImageName: "{% ogCreateImage { ogImageName: title | slug, ogImageTemplate: 'page-blank.png', text: title } %}"
---
Then in .eleventy.js or a plugin:
eleventyConfig.addShortcode("ogCreateImage", function(props) {
const imageName = props.ogImageName
const imageTemplate = props.ogImageTemplate
const imageText = props.text
console.log('-----------------ogCreateImage-----------------');
console.log(`filename: ${imageName}`);
console.log(`using template: ${imageTemplate}`);
console.log(`with the text : ${imageText}`);
// call the image creation code — return filename with extension
const imageNameWithExtension = createOGImage(imageName, imageTemplate, imageText)
return imageNameWithExtension
});
Returning the final filename which you can use in your template.
I've also come across this problem. I don't think what you're trying to do is possible at the moment. There are not many ways for a plugin to hook into the build step directly:
Transforms
Linters
Events
I think events would be the best solution. However, events also don't receive enough information to process a template in a structured way. I've opened an issue regarding this on Github. For your use-case, you'd need to get structured page data in this hook as well. Or eleventy would need to provide a build hook for each page. I suggest opening a new feature-request issue or adding a comment with your use-case to my issue above so those hooks can be implemented.
Other solutions
Another solution that requires a bit more setup for the users of your plugin would be to add your functionality as a filter instead of an automatic script that's applied to every template. This means that the users of your plugin would need to add their own template which passes the relevant data to your filter. Of course this also gives more fine-control to the user, which may be beneficial.
I use a similar approach for my site processwire.dev:
A special template loops over all posts and generates an HTML file which is used as a template for the generated preview images. This template is processed by eleventy. (source)
After the build step: I start a local server in the directory with the generated HTML files, open them using puppeteer and programmatically take a screenshot which is saved alongside the HTML templates. The HTML templates are then deleted.
This is integrated into the build step with a custom script that is executed after the eleventy build.
I've published the script used to take screenshots with Puppeteer as an NPM package (generate-preview-images), though it's very much still in alpha. But you can check the source code on Github to see how it works, maybe it helps with your plugin.

How to use ApplyAction

I've been trying to search for information on how use the copyCard trello action, it looks like I should use Card.ApplyAction, but I am not sure if thats the correct way. I have not found how to set the needed data on the action to copy the card.
Is there a method in Manatee.Trello to copy a card or do I just do it all myself? If there is how do you use it?
To copy a card, you'll need the destination list. If you're just trying to put it in the same list, that's card.List.
Then you can just add a new card using the existing card as a source:
var card = new Card("<card ID>");
var copy = Card.List.Cards.Add(card);
Done!
Edit for completeness
The ActionTypes enum serves two purposes:
Identify the type of action when you get the list of actions (card.Actions) for objects that expose them (boards, lists, cards, etc.)
Filter actions that are included in the Filter() extension method.
You can find out more on the Manatee.Trello wiki
Another edit for more completeness
The card.ApplyAction() method is for web hooks. When a request is received, the content is deserialized as a string and passed to this method. It is an alternative updating mechanism from the default on-demand polling.

Get path of uploaded image in Moodle

I have added custom column to store company logo. I have used file api of moodle like :
$mform->addElement('filepicker', 'certificatelogo', 'Company Logo', null,
array('maxbytes' => $maxbytes, 'accepted_types' => '*'));
$mform->setDefault('certificatelogo', '0');
$mform->addHelpButton('certificatelogo', 'certificatelogo', 'certificate');
Once the form is submitted itemid will be stored in custom column. Say "648557354"
Now I need to get image to print logo on certificate. How can I get image path from itemid? Do I need to store any other information to retrieve image?
The itemid returned is the temporary id of the draft area where the file is stored whilst the form is being displayed. You need to copy the file into its 'real' location, when the form is submitted, otherwise the file will be automatically deleted after a few days (and it will only be accessible to the user who originally uploaded it).
I'd always recommend using the filemanager element, if you are planning on keeping the file around (filepicker elements are for files you want to process and discard, such as when uploading a CSV file data to parse and add to the database).
Details of how to use it are here:
https://docs.moodle.org/dev/Using_the_File_API_in_Moodle_forms#filemanager
But the basic steps are:
Copy any existing files from the 'real' area to the draft area (file_prepare_standard_filemanager).
Display the form.
On submission, copy files from the draft area to the 'real' area (file_postupdate_standard_filemanager).
When you want to display the file to the user, get a list of files stored in the file area (defined by the component, filearea, context and, optionally, itemid, you used in file_prepare_standard_filemanager and file_postupdate_standard_filemanager). You can do this with: $fs = get_file_storage(); $fs->get_area_files().
For those files (maybe only 1 file, in your case), generate the URL with moodle_url::make_pluginfile_url.
Make sure your plugin has a PLUGINNAME_pluginfile() function in lib.php, to examine incoming file requests, do security checks on them, then serve the file.
There is a reasonable example of all of this at: https://github.com/AndyNormore/filemanager

Modus Operandi - Upload and Resize Multiple images using Zend Framework and HTML5

The good news:
I don't care if it uses ajax or not.
I don't care if the user must install a specific browser to make it work.
I don't care if there isn't any specifc progress bar.
The bad news:
I don't want to use flash.
The user must upload a file from any width or height - however no bigger then 8MB.
The file must be stored on a specific folder (or database column).
A thumbnail must be generated on a specific folder (or database column).
Those images must be associated with a specific record.
This is a "modus operandi" question, I realise that there is to much code involved here.
So:
We first create our form element to support multiple upload, like this:
$element = new Zend_Form_Element_File('multifile');
$element->setAttrib('multiple', true);
$element->setIsArray(true);
We then, need to add some validations and allowed extensions;
Then we need to process the upload;
Once the upload is done, we need to resize those multiple files according to our needs.
We need to store those resized files somewhere else.
Once all this is done, we are ready to display the files associated with a specific database record?
Is this the way to go? Should I have more steps? Am I missing something. I've never done this before, but I'm taking it like a challenge.
First, you create a form. Not much complication here:
$this->addElement('File','Filedata');
$this->Filedata
->setLabel('Select images')
->setDestination('somepath') //define & create it somewhere earlier ;)
->addValidator('Size', false, 1024000)
->addValidator('Extension', false, 'jpg,png,gif')
->setMultiFile(5)
->addValidator('Count', false, array('min'=>0,'max' => 5))
;
In the controller, you receive the images. They will have temporary random names, which you can keep later if you wish (I usually do).
$fileinfo = $form->Filedata->getFileInfo();
$path = 'somepath'; //make sure it exists
for($i=0;$i<5;$i++) {
if($fileinfo['Filedata_'.$i.'_']['tmp_name']) {
$img = new Imagick($fileinfo['Filedata_'.$i.'_']['tmp_name']);
// image processing goes here
file_put_contents('somepath',$img);
}
}
And that's it ;)