TextProperty field in NDB gets "=" appended after every line - google-app-engine

I have very strange case which I wasn't able to debug for a day.
On my front-end I have form with textarea and submit button.
On submission, the textarea field gets saved as ndb.TextProperty()
When I submit a multiline text, the text in the database gets = or =20 characters on every line. At first I thought they get randomly inserted, but it seems every 76 characters gets one = character.
This gets really hard to debug as on my localhost instance it works perfectly fine, but on the deployed version it doesn't. They are both in sync. Also on my localhost instance the text field on the datastore entity shows correctly the newline and tab characters, but on the deployed version, the datastore field is shown as one text blob without newlines or tabs.
Anyone can guide me to the right direction ?

Oh, BlobStoreHandler you didn't mention that in your original question.
Ok there is your problem.
I don't believe you can combine the two. If you are uploading to the Blobstore you can't do other form elements, as the upload is directed to the BlobStore service.
From the docs
The user creates a blob by submitting an HTML form that includes one
or more file input fields. Your application calls create_upload_url()
to get the destination (action) of this form, passing the function a
URL path of a handler in your application. When the user submits the
form, the user's browser uploads the specified files directly to the
Blobstore. The Blobstore rewrites the user's request and stores the
uploaded file data, replacing the uploaded file data with one or more
corresponding blob keys, then passes the rewritten request to the
handler at the URL path you provided to create_upload_url(). This
handler can do additional processing based on the blob key.
So it's difficult to say exactly what is going on without seeing your code, but I seriously doubt you can do what you are trying to achieve.

I've also had the same problem,
I solved it in a way that isn't elegant, but functional:
I did a replace on the input;
here is the code
input_html_text = unicode(self.request.get('text')).replace('=\r\n', '')

Related

Solr - When Save and Update an Index In Form Data Entry scenarios

I have a web form from which I want to save the data from the very first page to an index by using this sample code below.
Startup.Init<SomeModel>("http://localhost:8983/solr/somemodels");
var solr = ServiceLocator.Current.GetInstance<ISolrOperations<Quote>>();
solr.Add(new SomeModel() {Id=1001; Content="Some Content"});
solr.Commit();
On the very last page, the user is given a chance to change/update his entries on the form. Should I also use this line of code?
solr.Add(new SomeModel() {Id=1001; Content="New Content"});
Also, is this a good practice - having indexes updated in this fashion?
You can consider the below things.
Is there any chance that user does something in the first page and drops off in before reaching the last page?
If this is valid scenario and data loss is not acceptable, you should
save the data.
If you only want to save the data when use reaches at the last page, then you should do the below.
You should save the data which you want to be saved between pages. At the last page, you save it too SOLR.
Hope you are also using some backend data source to save the data and solr for search use cases. In this case, it is advisable to update one doc once per operation.
In case of Cassandra as backend. there are chances for tombstone when you update a document multiple times.

Send file to server through iText PDF?

I'm dynamically creating some PDF files through my application, using iText, and I need to use several components (TextField, CheckBox, RadioButtons etc), and then submit the values to server. But, one of the requirements says that the user needs to be able to select and send files along with the other values. I did not find a specific component to this, and so I'm asking for some help with this situation.
Is there a way to create some kind of Input File, File Chooser, etc, and attach it on the generated PDF file? And then send this selected file to server?
Thanks
This is explained in the official documentation, more specifically in the example FdfServlet of chapter 9 of my book. However, in this example, we add a file selection field to an existing PDF, so I've made you an example that explains how to create such a field when creating a document from scratch: FileSelectionExample
A file selection field is created just like any other text field, except that you have to set a flag using the setOptions() method. If you want a file chooser to appear, you also have to add a JavaScript action:
TextField file = new TextField(writer, new Rectangle(36, 788, 559, 806), "myfile");
file.setOptions(TextField.FILE_SELECTION);
PdfFormField upload = file.getTextField();
upload.setAdditionalActions(PdfName.U, PdfAction.javaScript(
"this.getField('myfile').browseForFileToSubmit();", writer));
writer.addAnnotation(upload);
In the full example, I also added a second field and after selecting the file with the browseForFileToSubmit() method, I set the focus to that other field. I'm doing this because the file name only becomes visible in the file selection field after that field loses focus.

CakePHP Parsing data from file and adding to database

I have a file that I wish to parse and add to the database.
The way I wish to do it is this:
The user uploads the file
File is parsed
The users are given the parsed data and selects what they want to keep
They submit
(More detailed explanation follows)
I have a film script file that I wish to parse and enter scenes and their respective characters and props. I have already managed to parse this file into an array using php.
What I want to do now is to
prompt the user with the various scenes and its contents
allow the user to fix / modify the data before submitting it into the database.
The thing is that the script file has more than one scene in it, so I am unsure how to handle the data-entry aspect of this problem.
Are there any "best practices" for these kinds of data entries?
(if I didn't explain something in enough detail, please tell me and I'll update the question).
I would simply parse the file and save it as it is to the database. Something like Script hasMany Scenes. Let them select their script and simply paginate the Scene records and let them delete them.
Is there an urgent need to not save them all after import? Another downside of your approach is that if the browser crashes or the user closes it he has to start over again because you just kept the data in memory but not persistant.
If you want to rely on your approach you'll have to work with the data coming back from the form and simply remove the key from the form data.
Like doing this in a foreach running over the data structure
if ($data['Scene][$key]['delete'] == 1) { unset($data['Scene'][$key]); }

CakePHP - Prevent model data being save in a saveMany call when certain fields are blank

I have scenario where I have 3 different models data being saved from one form, by means of the saveAll pass through method in CakePHP 2.x
The models on the form are:
Project
ProjectImage
ProjectAttachment
1 and 2 are saving perfectly, but I am having problems with the ProjectAttachment fields. If you look at the following image, the fields in question are at the bottom right, highlighted by a red frame: http://img.skitch.com/20120417-bnarwihc9mqm1b49cjy2bp13cf.jpg
Here is the situation:
I have named the fields as follows: *ProjectAttachment.0.project_id*, ProjectAttachment.0.name .... *ProjectAttachment.6.project_id* etc where the numbers are relative to the already present amount of attachments the user has added, as there is no limit. So if the user has ALREADY added 6 documents, the field would be called ProjectAttachment.7.id and so on. This is because of the naming convention when using the saveAll method.
I have made use of two hidden fields, one to store the user ID, the other to store the project ID.
The problem is that if the user does not fill in the Document Title and select a file to upload, the form fails! If I remove all validation rules, the form no longer fails BUT a blank ProjectAttachment record is inserted.
I suspect the problem may also be that the project_id and user_id fields (that are hidden) already have values in them?
I gave it some thought, and came up with a simple concept: In my controller, before the saveAll call, I would check to see if a blank Document Title field was submitted, and if so, I would completely eliminate the relevant array entry from the $this->request->data['ProjectAttachment'] array, but this did not seem to work.
To clarify, I am not looking for validation rules. If the user decides they only want to upload images and not touch the ProjectAttachment form, them the saveAll operation must not fail, it must simple not attempt to save the blank fields in the form, if this is at all possible.
Any suggestions?
Kind regards,
Simon
Well it seems that the solution was far simpler than I had initially thought! I was partially on the right track, and I had to unset the variable ProjectArray key in the $this->request->data array if I had encountered any blank fields.
I did this as follows:
if(!empty($this->request->data['ProjectAttachment'])){
foreach($this->request->data['ProjectAttachment'] as $key => $value){
if(is_array($value) && array_key_exists('upload_file', $value)){
if($value['upload_file']['name'] == ''){ // Blank document file
unset($this->request->data['ProjectAttachment']);
}
}
}
}
I hope someone finds this somehow useful in some form or another.
Kind regards,
Simon

asp mvc, best solution to store user input data before it will be saved to database

for example i've got a form with some input fields(every form and it's inputs with validation rules are stored in database).
Every input got it's own OnChange() which posts json (i.e. new value, input element name, ...) to controller for validation, if validation passes the new value must be saved somewhere until user clicks submit button, which will save all data to database table.
And here i'd like to ask, what this special place between ui and database can be ?
p.s.
also if user closes browser/form the next time he'll come back i need to ask him if he would like to start from an empty form or fill form with values he previously entered there.
Thank You !
Cookies or intermediary database table would work for this case.
for an intermediary database like that, you could use something like MongoDB, it is really easy to get it started, you just work with the classes you have, don't need to setup any schema, you just save the objects
http://www.mongodb.org/display/DOCS/CSharp+Driver+Tutorial
If you are submitting the entire form at the end, why can't you just store the values at that time? Is this a multi-page form(s)? Why not allow the database records to be partially filled? You could always add a bit column to mark the record as complete or incomplete. This would be much simpler than duplicating your table structure.

Resources