"=" symbols in GAE TextProperty - google-app-engine

I'm getting strange additional symbols (=) in text property when adding text there via POST.
For example:
The team is back with an unstoppable fury as they are being chased by the p= olice, Alonzo and Yuuma. Vinnie, Shorty and Kiro=92s skills will be put to = the test.
There shouldn't be any of = symbols in that text.
My co de is:
class FileUploadHandler(blobstore_handlers.BlobstoreUploadHandler):
def post(self):
game_file = self.get_uploads()[1]
screen_file = self.get_uploads()[0]
if not users.get_current_user():
game_file.delete()
screen_file.delete()
self.redirect(users.create_login_url("/"))
return
game = Game()
game.title = self.request.get('title')
game.url_name = self.request.get('url')
if self.request.get('active') == 'active':
game.active = True
else:
game.active = False
if self.request.get('featured') == 'featured':
game.featured = True
else:
game.featured = False
query = Category.gql("WHERE url_name = :url_name", url_name=self.request.get('category'))
game.category = query.get()
game.width = int(self.request.get('width'))
game.height = int(self.request.get('height'))
game.description = db.Text(self.request.get('desc'))
game.how_to_play = db.Text(self.request.get('htp'))
game.game_file = game_file
game.game_screenshot = screen_file
db.put(game)
What am i doing wrong?

This is a known issue of blobstore handler that is breaking the data encoding.

I had the same difficulty. But, I found a fix. I'm using Python 2.5. In my model, I have a TextProperty, hooked up to an html TextArea tag. Like your situation, in the Dev server, it saved what I entered. However, in Prod, the DataStore somehow added "= " among others, every time I write the content of textarea over to the textproperty field.
Go here:
http://code.google.com/p/googleappengine/issues/detail?id=2749
Then, scroll down to Comment 21. The poster of that comment attached a file, named appengine_config.py Download it, and put it on the root folder of your app. Then Deploy it to Prod and try it out in Prod.
I did that, and my "= " problem went away.

Related

Libreoffice Base - how to call a control event from a macro?

Question: I need to manually call an object listener event (e.g. key pressed) to trigger a function. I used to do it in Access but haven't found the documentation for it in LibreOffice Base.
Context: Having retired from software development 7 years ago, I am doing a favour for a friend by building a database in LibreOffice Base. Previously experienced in Access - but more with Oracle, PL/SQL, APEX, etc! I am struggling a little in getting it to do what I know can be done!
Here is the code I've tried so far.
Sub CauseKeyPressedEventToBeFired
oDoc = ThisComponent
oController = oDoc.getCurrentController()
oVC = oController.getViewCursor()
oForm = oDoc.getDrawpage().getForms().getByName("Form")
oTextBox = oForm.getByName("Text Box 1")
oControlView = oController.getControl(oTextBox)
oControlView.setFocus()
Dim oEvent As New com.sun.star.awt.KeyEvent
oEvent.Source = oControlView
oEvent.KeyCode = com.sun.star.awt.Key.A
oControlView.keyPressed(oEvent)
End Sub
However, it doesn't seem to work on my system (LibreOffice 6.4.3.2 on Windows). I also found this post, but that code doesn't seem to work for me either.
I searched for com.sun.star.awt.XToolkitRobot, but it's not in the API documentation, perhaps because the functionality is not fully supported. Presumably, it can be obtained from com.sun.star.awt.Toolkit.
For more help, post a question on ask.libreoffice.org. I'd suggest explaining why you want to do this, because there may be a different kind of solution. Ratslinger has a lot of experience solving various database problems, and he'll probably direct you toward a simpler solution that doesn't involve this kind of event hacking.
a function (i.e. a procedure that returns a value)
Yes, that is what a function is. But "an object listener event" implies, correctly I think, that we're talking about the method of an object instead. That's what LibreOffice event listeners are in Python or Java, although in Basic, they're a little strange, using the object name as some kind of magic to determine what they apply to. Anyway, that's getting off track, because your question isn't about listening for events, but rather about triggering them.
EDIT:
The following Python code works. The problem with my earlier attempts was that oEvent.KeyChar needs to be set, and that doesn't seem to work in Basic. I can't imagine why, unless I am ignoring some obvious mistake in the Basic code.
def causeKeyPressedEventToBeFired(oEvent=None):
oDoc = XSCRIPTCONTEXT.getDocument()
oController = oDoc.getCurrentController()
oForm = oDoc.getDrawPage().getForms().getByName("Form")
oTextBox = oForm.getByName("Text Box 1")
oControlView = oController.getControl(oTextBox)
oControlView.setFocus()
oEvent = uno.createUnoStruct("com.sun.star.awt.KeyEvent")
oEvent.Source = oControlView
from com.sun.star.awt.Key import A
oEvent.KeyCode = A
oEvent.KeyChar = "a" # works in Python but strangely not in Basic
simulate_KeyPress(oEvent)
def simulate_KeyPress(oKeyEvent):
oDoc = XSCRIPTCONTEXT.getDocument()
oWindow = oDoc.CurrentController.Frame.getContainerWindow()
oKeyEvent.Source = oWindow
oToolkit = oWindow.getToolkit()
oToolkit.keyPress(oKeyEvent)
oToolkit.keyRelease(oKeyEvent)
EDIT 2:
Finally, here is working Basic code. In the earlier attempt, the type was wrong.
Sub CauseKeyPressedEventToBeFired
oDoc = ThisComponent
oController = oDoc.getCurrentController()
oForm = oDoc.getDrawpage().getForms().getByName("Form")
oTextBox = oForm.getByName("Text Box 1")
oControlView = oController.getControl(oTextBox)
oControlView.setFocus()
Dim oEvent As New com.sun.star.awt.KeyEvent
oEvent.KeyCode = com.sun.star.awt.Key.A
oEvent.KeyChar = CByte(97)
simulate_KeyPress(oEvent)
End Sub
Sub simulate_KeyPress(oKeyEvent As com.sun.star.awt.KeyEvent)
oWindow = ThisComponent.CurrentController.Frame.getContainerWindow()
oKeyEvent.Source = oWindow
oToolkit = oWindow.getToolkit()
oToolkit.keyPress(oKeyEvent)
oToolkit.keyRelease(oKeyEvent)
End Sub

Block in published page has "This item is not used anywhere."

I have a scheduled job that loops through all pages of a certain type and creates a block for each page and puts it in a ContentArea.
if (productPageClone.GeneralContentArea == null)
{
productPageClone.GeneralContentArea = new ContentArea();
}
var newBlockForArea = _contentRepository.GetDefault<CrossLinkContainerBlock>
(assetsFolderForPage.ContentLink, productPageClone.Language);
(newBlockForArea as IContent).Name = "newCrossLinkContainer";
var blockReference = _contentRepository.Save((newBlockForArea as IContent), SaveAction.Publish,
AccessLevel.NoAccess);
var newItem = new ContentAreaItem();
newItem.ContentLink = blockReference;
productPageClone.GeneralContentArea.Items.Add(newItem);
When the block is created it is published.
When the page is updated it is either saved or published depending on earlier status.
_contentRepository.Save(productPageClone, SaveAction.ForceCurrentVersion | SaveAction.Publish,
AccessLevel.NoAccess);`
Later when inspecting the page, the block is in the page's assets folder and the block is in the correct ContentArea and it renders correctly. The only problem is that when I edit the block, it says "This item is not used anywhere."
However, then I republish the page the block is in, and then edit the block, it says "Changes made here will affect at least 1 item" as it should.
I am using Episerver 11.11.2.0
I have run the scheduled job manually each time I've tested this.
Has anyone any idea why this is happening?
I found the solution after reading this page:
https://gregwiechec.com/2015/10/reindexing-soft-links/
After page that has the new block has been published, get the page's softLinks and re-index them:
var links = _contentSoftLinkIndexer.GetLinks(productPageClone);
_softLinkRepository.Save(productPageClone.ContentLink.ToReferenceWithoutVersion(),
productPageClone.Language, links, false);
Softlink-tools are imported like this:
private IContentSoftLinkRepository _softLinkRepository =
ServiceLocator.Current.GetInstance<IContentSoftLinkRepository>();
private ContentSoftLinkIndexer _contentSoftLinkIndexer =
ServiceLocator.Current.GetInstance<ContentSoftLinkIndexer>();
This will occur if your content area is null
Try the following
// Before adding the ContentAreaItem
if(productPageClone.GeneralContentArea == null)
{
productPageClone.GeneralContentArea = new ContentArea();
}
productPageClone.GeneralContentArea.Items.Add(newItem);

Windows Form "Jumps" when clicked

This question is regarding a Windows form built in PowerShell using System.Windows.Forms - I intend to convert it to C# at some point, just hasn't happened yet. C# contextual answers welcomed.
So in order to make this tool appear more like an "app" verses another WPF thing, the control boxes were removed, along with the title. In doing so, we lose the ability to move the form. So I decided to write a nice little number to handle that, which you all may agree or disagree with. Anyhow, it works great on my workstation, laptop, and a remote session to a few random terminal servers. However, when testing with a user, the app experiences a "jump" when clicked on where this bit of code might be picking up on the mouse click. The form's icon still shows in the toolbar, but it's obvious that the form has gone way off screen, and cannot be pulled back to center. I am not 100% sure if it's the code, but I have a feeling. I cannot reproduce this on my machines. Please don't tell me how to get the form back on the screen, that is just a workaround. I appreciate any ideas.
$GLOBAL:ButtonDown = 0
$GLOBAL:FX = 0
$GLOBAL:MX = 0
$GLOBAL:FY = 0
$GLOBAL:MY = 0
$Form.Add_MouseUp({handler_Form_MouseUp})
function handler_Form_MouseUp{$GLOBAL:ButtonDown = 0}
$Form.Add_MouseDown({handler_Form_MouseDown})
function handler_Form_MouseDown{
$GLOBAL:FX = $Form.Location.X
$GLOBAL:MX = [System.Windows.Forms.Cursor]::Position.X
$GLOBAL:FY = $Form.Location.Y
$GLOBAL:MY = [System.Windows.Forms.Cursor]::Position.Y
$GLOBAL:ButtonDown = 1
}
$Form.Add_MouseMove({handler_Form_MouseMove})
function handler_Form_MouseMove{
if($GLOBAL:ButtonDown){
#write-host ("X:"+ ([System.Windows.Forms.Cursor]::Position.X) + " || Y:" + ([System.Windows.Forms.Cursor]::Position.Y))
$newX = $GLOBAL:FX + ([System.Windows.Forms.Cursor]::Position.X - $GLOBAL:MX)
$newY = $GLOBAL:FY + ([System.Windows.Forms.Cursor]::Position.Y - $GLOBAL:MY)
$Form.SetDesktopLocation($newX, $newY)
$GLOBAL:FX = $Form.Location.X
$GLOBAL:MX = [System.Windows.Forms.Cursor]::Position.X
$GLOBAL:FY = $Form.Location.Y
$GLOBAL:MY = [System.Windows.Forms.Cursor]::Position.Y
}
}

How can I store empty value in GAE LinkProperty?

By default LinkProperty() is empty. But let us say I submit a form that stores site link in the DB field with the property LinkProperty(). This works fine so far.
Next, I want to delete that link stored in the DB by resubmitting the form with empty site link. At this time, I get database error as follows:
"BadValueError: link must not be empty."
Can anyone please help with this? Code below.
###Database
class MyDatabase(db.Model):
site = db.LinkProperty()
###Trying to store form data in the database
mydb_obj = MyDatabase.get_or_insert('abc')
#above line works fine
mydb_obj.site = self.request.get('form_site') #works fine.
#Above form_site is read from form submission. It can be 'www.google.com' or it can be
#empty as in ''
mydb_obj.put() #I GET ERROR WHEN form_site = ''.
#"BadValueError: link must not be empty"
I have not tried to replicate this error. It could be possible that the when the link input is empty, the value requested is None. Perhaps this might work:
mydb_obj.site = self.request.get('form_site')
if mydb_obj.site is None:
mydb_obj.site = '' # value is empty string instead of None.
The following works
mydb_obj.site = self.request.get('form_site')
if not mydb_obj.site:
mydb_obj.site = None
mydb_obj.put()

Printing text in Silverlight that measures larger than page

I have a silverlight application that allows people to enter into a notes field which can be printed, the code used to do this is:
PrintDocument pd = new PrintDocument();
Viewbox box = new Viewbox();
TextBlock txt = new TextBlock();
txt.TextWrapping = TextWrapping.Wrap;
Paragraph pg = new Paragraph();
Run run = new Run();
pg = (Paragraph)rtText.Blocks[0];
run = (Run)pg.Inlines[0];
txt.Text = run.Text;
pd.PrintPage += (s, pe) =>
{
double grdHeight = pe.PrintableArea.Height - (pe.PageMargins.Top + pe.PageMargins.Bottom);
double grdWidth = pe.PrintableArea.Width - (pe.PageMargins.Left + pe.PageMargins.Right);
txt.Width = grdWidth;
txt.Height = grdHeight;
pe.PageVisual = txt;
};
pd.Print(lblTitle.Text);
This simply prints the content of the textbox on the page however some of the notes are spanning larger than the page itself causing it to be cut off. How can I change my code to measure the text and add more pages OR is there a better way to do the above where it will automatically create multiple pages for me?
There are several solutions to your problem, all of them under "Multiple Page Printing Silverlight" on Google. I was having a similar problem and tried most of them. The only one that worked for me was this one:
http://www.codeproject.com/Tips/248553/Silverlight-converting-to-image-and-printing-an-UI
But honestly you should look at Google first and see whether there are better solutions to your specific problem.
Answering your question, there is a flag called HasMorePages that indicates you need a new page. Just type pe.HasMorePages and you will see.
Hope it helps
First you need to work out how many pages are needed
Dim pagesNeeded As Integer = Math.Ceiling(gridHeight / pageHeight) 'gets number of pages needed
Then once the first page has been sent to the printer, you need to move that data out of view and bring the new data into view ready to print. I do this by converting the whole dataset into an image/UI element, i can then adjust Y value accordingly to bring the next set of required data on screen.
transformGroup.Children.Add(New TranslateTransform() With {.Y = -(pageIndex * pageHeight)})
Then once the number of needed pages is reached, tell the printer to stop
'sets if there is more than 1 page to print
If pagesLeft <= 0 Then
e.HasMorePages = False
Exit Sub
Else
e.HasMorePages = True
End If
Or if this is too much work, you can simply just scale all the notes to fit onto screen. Again probably by converting to UI element.
Hope this helps

Resources