Telerik MVC Upload files - how to reinitialize if Model.State is invalid - kendo-asp.net-mvc

I have a view which has an upload control placed on it - I only want to actually process the files to upload when the form is completed and valid - in which case I will upload the files.
However - I seem to have problem with either binding the control to an property in the viewmodel passed to the view OR having a the correct property type to pass between the view and the controller.

Related

How to store large fetched dataset from postgres in Django view?

When user open some Django view there is option to choose what data to load from postgres DB. After that click submit and process is started. But when data is fetched and in the same view pressed reload, then all process starts from begining. Fetched time is about ~10min (best solution to fetched once by opening view and after that just manupulate with data without fetced each reloading)
I want to load data once or by button. But how to implement that i don't understand.
The easier approach is to do this with two pages:
First page: User can choose to load the data
Second page: Loads the data and shows it
If you want to do this on the same page you normally put a div on your page where the data should be loaded and then you need to use Javascript / AJAX to load and update your current page (or a part of it) based on user input like a clicked button.
There are multiple ways to implement this. Here are some examples:
HTMX - Click to load
JQuery - load div on button click
Pure Javascript
I would recommend HTMX, because it allows you to do this without having to write any JavaScript and it works great together with Django templates.

List column(Text) not saving/showing data after setting attribute multiple=true on Attachments control so to enable uploading multiple Files at a time

By default we can only upload one file at a time so I followed solution given here(https://www.c-sharpcorner.com/article/attach-multiple-files-to-sharepoint-list-item-with-default-attachment-of-new-for/). Now I am unable to store RFI No column(text). It maybe stores value on form submit but the value does not show. Following is my column setting:
List view and inspect element:
I simply added the code in NewForm.aspx which works and enables user to upload multiple files but now New Item form does not save RFI No value which is not in anyway dependent on Attachments field
If I log the value of RFI No column to workflow history list through Workflow it is showing the saved value there..
If so, the value is saved in the RFI No column. Looks like there are some code in the list view page which hided the column value, that's why the value does not show.
You could click Edit page in the site settings to check if there are script editor or content editor web partin the view page.

How to update cache for a Sitecore Web Api output upon the index update

I am implementing Sitecore 8 Web Api. To be exact, i am using ServiceApiController in Sitecore Services Infrastructre. I wonder how can I cache the JSON output from this controller in such a way that it gets updated only if the lucene index which I am fetching data from, gets rebuilt?
I have not registered this controller as controller rendering because apparently we don't need to do that and it just works out-of-box. I just read the JSON output by an ajax call through jQuery and the javascript code and HTML markup is inside a MVC view rendering. I guess it doesn't make sense to setup cache on the view rendering. Isn't it?
What should i do?
The best option would be to use the HtmlCache and store the data there. This cache gets completed cleared on a publish, so it would make sense to use it.
You can add an entry into the cache by using the SetHtml method:
var cache = Sitecore.Caching.CacheManager.GetHtmlCache(Sitecore.Context.Site);
var json = cache.GetHtml("mycachekey");
if (string.IsNullOrWhiteSpace(json))
{
var json = // build your json output here
cache.SetHtml("mycachekey", jsonValue);
}
return json;

Creating model instances inside a Django template

I have an upload page written in Django that uses webkit calls to enable folder upload and list all files in the uploaded folder.
In my template, I have an event handler for the "drop" event, so it can iterate through the files in the folder and process them accordingly.
It would be really nice to create model instances for each of these files as this iteration happens. Is this possible within the javascript code block inside the template?
Maybe I should write a custom tag to do this? Just not sure if there is an easier way to call MyModel.objects.create(opts) from inside a template and have it do the right thing.
Would really appreciate inputs or any examples. Thanks!
i think you cannot do that from the "Tempalte", but i recomend to you build this using AJAX, your Js code will get the data from the html and then send that data to an URL and so, your View will receive that Data and create your instances and after that your view will return a HttpResponse to your js code.

Django Admin - Create 'temporary' entry

Is there a way to make it so the Django Admin panel creates a temporary model when you click the "add" button?
I want to be able to 'attach' multiple files / media to a particular model entry which would involve uploading the files at the time of creation. I can't do this until the model has a pk as obviously I can't create a link between the uploaded file and the entry.
I am using the Content-Type framework to create the attachment between my uploaded file (which is wrapped in a class)
I noticed that Wordpress for example creates what is called an 'auto draft' when you click the "new post" button to get around problem.
If I understand correctly, you want to take care that the filename of your uploaded file corresponds with the model's PK where the file-fields are used.
There is nothing you must change in the django-admin, but make some adjustions on your model:
First, make use of "upload_to" in your filefield. I usually set the filename to a uuid4-value to make sure it's unique.
After saving the model, you can rename the file if you want. The best place is in a function that is triggered by a post-save-signal. But if you only want to ensure, that the filename is unique, the filename-generation by uuid should work.