Friday, August 24, 2018

django redirect to view

I have one view that I want to do some stuff in and then redirect to another view with a success message. The signature of the method that I want to redirect to is

quizView(request, quizNumber, errorMessage=None, successMessage=None): 

and my attempt at redirecting to that view looks like this:

return redirect(quizView, quizNumber=quizNumber, errorMessage=None, successMessage="Success!")

I've tried most every combination of named and un-named paramaters and I can't get it to do what I want. Is there a way to make this work?

Also, I tried just returning the the second view with the first but then the URL is still where it was in the old view instead of appearing as though it has redirected.

Thanks!

Solved

You haven't given your URL a name, so you need to use the whole path to the view function. Plus, that URL doesn't take errorMessage or successMessage parameters, so putting them into the reverse call will fail. This is what you want:

return redirect('quizzes.views.quizView', quizNumber=quizNumber)

Can you try example 2 given in https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#redirect

  • Make sure that it does the 'reverse' on the given view.
  • Your view name should be wrapped in single quotes/

You should Refer this https://docs.djangoproject.com/en/1.11/topics/http/shortcuts/#redirect

For redirect inside view. Its very easy either you redirect using creating a url for view or call inside the view also.


Monday, August 20, 2018

wpf DocumentViewer XPS pinch to zoom and scroll using touch

iam developing a wpf app and i will enable the pinch to zoom and scrolling feature on a touchscreen.

here is my code

XAML:


    
        
            
            

            
            
        
    
    

and .cs

 private void myCanvas_Loaded(object sender, RoutedEventArgs e)
{
  try
  {
    string xpsFilePath = System.IO.Path.GetFullPath("XPS/" + RunViewModel._textToDisplay + ".xps");
    XpsDocument myDoc = new XpsDocument(xpsFilePath, FileAccess.Read);
    Viewer.Document = myDoc.GetFixedDocumentSequence();
    Viewer.FitToHeight();
    Viewer.FitToWidth();
    test.Height = ActualHeight;
    // Viewer.Height = ActualHeight;
    //Viewer.Width = ActualWidth;
  } catch (Exception ex)
  {
    MessageBox.Show(ex.ToString());
  }
}

private void myCanvas_SizeChanged(object sender, SizeChangedEventArgs e)
{
  Viewer.Height = (ActualHeight);
  Viewer.Width = (ActualWidth);
  Viewer.FitToHeight();
  test.Height = ActualHeight;
 // Viewer.FitToWidth();
}

i added a scrollview, but nothing happend.

What must i add?

Thanks for your help!

Solved

I now use this and everything works!

https://archive.codeplex.com/?p=multitouchtransformbehavior

easy way to use pinch to zoom rotate and scroll!


Sunday, August 19, 2018

How to rid of Save As dialog and yellow box in tcpdf

When I generate and save a document with a link in it using TCPDF. It is always showing a save as dialog before closing in the pdf reader.

"Do you want to save the changes to file.pdf before closing?"

Also there is a yellow note box in the chrome browser when I hover over the link... as shown in the image below.

My code with problem is like this.

$pdf->writeHTML('link');

However, if my links are empty in my html then there is no problem while closing the pdf, also then there is no yellow box anymore in links. The following code for example is working fine.

$pdf->writeHTML('link');

Here is a complete example to reproduce the problem.

require_once __DIR__.'../../external_classes/TCPDF/tcpdf.php';
    $pdf = new \TCPDF();
    $pdf->SetCreator(PDF_CREATOR);
    $pdf->SetAuthor('ABC');
    $pdf->SetTitle('ABC');
    $pdf->SetSubject('ABC');

    $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, "ABC", "ABC");
    $pdf->setPrintFooter(false);
    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
    $pdf->SetMargins(PDF_MARGIN_LEFT, 10, PDF_MARGIN_RIGHT);
    $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
    $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
    $pdf->SetFont('helvetica', '', 10);
    $pdf->AddPage();
    $pdf->writeHTML('link');
    ob_clean();
    $pdf->Output('example.pdf', 'D');

The above example will generate the output like the following image. Which will have both the problems, I have tested both on tcpdf version 5.9.x and 6.2.x.

Solved

You may resolve the second problem by removing annotations at all.

  • Create your own class MyTCPDF extends \TCPDF.
  • Copy to created class "protected function _putannotsobjs()" from tcpdf.php. You will override it.
  • Change this string in method form

    `$annots .= ' /Contents ' . $this->_textstring($pl['txt'], $annot_obj_id);`

    enter code here to

    `$annots .= ' /Contents ()';`
  • Use your class for generation pdf file.
  • You may put any logic in this method an disable annotations by constant or something else.

Okay, found some explanation to both the problems.

1. First Problem: The issue of Save as Dialog

For some reason the tcpdf library is appending my website html at the end of the pdf. I found this out by viewing my pdf in pure text using a text editor.

Using an exist function immediately after output() will fix it.

$pdf->Output('example.pdf', 'D');
exit();

2. Second Problem: The issue of yellow link box in chrome

This is currently an unresolved active issue in chrome. Check this link for example on mPdf forum.


Saturday, August 18, 2018

Why is Eclipse Juno 4.2 running "JPA Java Change Event Handler" processes?

I have just upgraded to Eclipse Juno 4.2. I have a completely clean new workspace, but have imported projects that have previously been used in Eclipse 3.7 and therefore have some Eclipse metadata in them.

When moving to 4.2 I converted a project to use "Project Facets". The only Facet enabled is "Java".

However, I regularly get "JPA Java Change Event Handler (Waiting)" appearing in my progress view. I do have JPA annotated classes within the project, but I do not have the JPA facet enabled.

So...why am I getting these tasks being run by Eclipse?

Screenshot of eclipse progress window

Update: Have submitted bug to Eclipse and it is being looked at by the looks of it: https://bugs.eclipse.org/bugs/show_bug.cgi?id=386171

Solved

Unfortunately, the JPA java completion proposals extension point is incorrectly forcing o.e.jpt.jpa.core plug-in activation. Once our plug-in is activated we start listening for java events and facet events, whether JPA faceted or not. In Juno these background threads were converted to the Eclipse Jobs framework. In Helios you would not have seen them in the Progress View, but the same problem existed.

Thanks for entering a bug against Dali https://bugs.eclipse.org/bugs/show_bug.cgi?id=386171 for this problem.

Update: The bug has been fixed for Juno SR1, thanks to JDT Text for their quick turn around on this Dali bug!

Update 2: This problem is still occurring for other use cases. In Juno SR2 there are 3 bugs being worked on that will help resolve this issue. Some of these have further fixes that will need to go in Kepler. See bugs:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=397778

https://bugs.eclipse.org/bugs/show_bug.cgi?id=397606

https://bugs.eclipse.org/bugs/show_bug.cgi?id=386393


I've experienced this behavior whenever I disabled the JPA Validator in Window => Preferences => Validation. Enabling it for both Build and Manual made the crazy loop disappear.


I found (in Eclipse Neon where this still occurs) that removing all the groups in the JPA Validator worked well. Click on the box to the right of JPA Validator and remove all the included groups:

enter image description here


The drastic solution in my case was to uninstall "Dali JPA". That seemed to solve the issue for me.

Of course it is not the best solution. Try first to enable the validation as explained in NPE's anwser. Bug 386171 has people that report the same problem at May of 2015 so I must not be the only one.

I would be very happy to delete my answer if something better is found.


set eclipse_dir=D:\eclipse\release

mkdir %eclipse_dir%\disabled
mkdir %eclipse_dir%\disabled\features 
mkdir %eclipse_dir%\disabled\plugins

move %eclipse_dir%\plugins\org.eclipse.jpt.* disabled\plugins

for /f %%i in ('dir features\org.eclipse.jpt.*" /ad /b') do (
    move features\%%i" "%eclipse_dir%\disabled\features\%%i"
)

I had the same issue I had the same issue in eclipse 4.5.2 (mars 2). I've tried almost every answer from stackoverflow, tuned my eclipse settings (I thought maybe its a performance issue).

Problem stops after disabling JPA in Project Facets in every Project properties.

enter image description here

After this change Eclipse keeps yelling about JPA Event Handler but it doesn't take ages to finish save or clean, so it looks like its disabled (before changing this it took something about 10 minutes to finish, now its matter of seconds)

Hope that help someone to fix this problem.

enter image description here