Validate using model rules before saving in Yii - yii

I am building a CSV import, and am looking to run through the CSV and display any potential errors to the user before actually doing the import.
$model->getErrors() only works after an attempted $model->save(), I am looking to get those potential errors before the save so the importer can then adjust his CSV file and make the necessary changes to have a flawless import.
Any ideas?

$model->validate();
$model->getErrors();

at first place, why dont you try this tool wrote by me: http://www.yiiframework.com/wiki/401/simple-csv-export/

Related

READ CSV from DROPBOX

I have a program that takes input from a CSV that is in my colleague's dropbox at a certain URL and builds a dataframe. The program starts like this:
df=pd.read_csv('www.dropbox.com/s/certainurl=1')
I know that you have to put dl=1 otherwise it doesn't work but as I try to run the program it did see the CSV but it downloads data in a confusing way and subsequently, it cannot read the columns. Of course, if I download the CSV and I run the program taking the CSV from local all works perfectly.
I don't have Dropbox and looking in similar question on StackOverflow no answers fits.
How to solve it?
Thanks in advance!
FWIW the problem was that my colleague saved the file as a particular CSV that uses ";" instead of "," to separate values. So I fixed with:
df=pd.read_csv('www.dropbox.com/s/certainurl=1', sep=";")
and the program worked.

Access when exporting it removes spaces at the end of a string

Long story short, I am dealing with an excel files, which need to be modified a little bit. As the files are coming on weekly basis, I decided to write a simple program via Access, which will help me to make the process fully automatic.
The first step was to upload the excel file into an Access database. I managed to achieve that by creating a custom function and inside to just use the "DoCMD.TransferSpreadsheet acImport" aproach.
The second step was to create two queries and update the table that I just uploaded. That was also pretty straight forward too.
However, the third step is what I am struggling with. Now when the table is updated I wanted to export it back to .xlsx format. However, when I do that no matter if I do it manually via the "External Data" tab or simply use "DoCMD.TransferText acExport" approach I noticed that a few columns that have a space after the end of the string are trimmed automatically. For example, original:"string ", but after exporting it is changed to "string".
I would be really grateful if someone can tell me how to specify to Access that the space after the string is intended and not done by mistake? Preferably with a VBA solution than having to do it manually. Thank you in advance for the help!
PS: I know that .CSV format would be way better, but sadly I need it to be in a XLSX format.

Jhipster second time CRUD

Is there a way to Jhipster to automatically generate CRUD when generating an entity a second time ?
For instance, I missed to add a field in an entity and replay "yo entity...".
I modified the .json configuration file as described in the doc but when I checked the page, the changes didn't appear.
Do you met the same issue ?
Thanks for your help, JM
What I do is I remove all generated code (except .jhipster/.json) and run yo jhipster:entity again. When yo jhipster:entity has run, it outputs all the created files. I save that list in a text file for the next time I want to change the entity. This way I can remove all generated files easily. I know it's not ideal but it works for me.

Any way to automate the process of opening a .mpp file and saving it as a .csv?

I need to find a way to automate the process when a user uploads a microsoft project file to a web application I already have created. The process will need to basically use the save as from project to save into a .csv file so I can use this to import the data to an SQL database (this is needed for custom reporting we already have set up using SQL). I need to automate this process because I will be receiving tons of project files, and if the process is automated the users will then be able to instantly see results.
Basically, is there any way to create or run an automated process that will save these project files as .csv files? Even if the csv files are not formatted correctly, I can find a way around that, just need to first get them into .csv files.
Thank you.
edit - the only way i could think of this is to follow the instructions listed below, but
I would then need to automate a process to open the file and hit save so this works... any other suggestions?
http://social.technet.microsoft.com/Forums/en-US/projectprofessional2010general/thread/eea4ca15-0a0b-4c07-9989-87536b961385/
edit 2 - also looking into ways using Microsoft.Office.Interop.MSProject but not finding any luck.
edit 3 0 now using mpxj - the only issue I am having is the following listed below. Converting their example to vb.
Private Shared Function ToEnumerable(ByVal javaCollection As Collection) As EnumerableCollection
Return New EnumerableCollection(javaCollection)
End Function
the error is with EnumberableCollection - visual studio is not picking it up as a valid type - anything I am doing wrong or should substitute?
If you aren't wedded to using MS Project itself to extract data from the project files, you could consider using the MPXJ library. This would allow you to write a simple utility to open the MPP files you are given, extract the data items you are interested in, and write them directly to your database (or an intermediate CSV file, as required). MPXJ comes in Java and .Net flavours, so you can use your preferred language to do the work.
Jon
p.s. Disclaimer: I maintain MPXJ

Difficulty in testing a CSV upload, due to Rails thinking it should use it to populate test data

I have a case where I want to test a file upload but I'm having problems breaking a circle of pain.
We are checking that the file uploaded is a CSV file, so the file should have the extention .csv.
To test we need to use ActionDispatch::TestProcess.fixture_file_upload and we place the test file in the test/fixtures/files diectory.
Now when I try to run a test, Rails sees this csv file in the sub-folder of fixtures and thinks it should use the file to populate some table. Which is wrong.
Is there any way I can tell Rails not to try and use this file for populating a table?
I can't rename the extension as that is what I'm trying to test.
I can't move the file out of fixtures as then the fixture_file_upload won't work
I can't seem to tell Rails to leave this file alone when populating fixture data.
:(
Well the answer I've come up with so far is to move the files out of fixtures directory and to place the equivalent of "../" at the start of the filename (in the fixture_file_upload parameter) to make it backdown a level.
Not exactly a good fix, so would still like to hear if it's possible to tell Rails not to load the csv file as table data.