Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8048399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:25:23+00:00 2026-06-05T06:25:23+00:00

Desperately need help on this task; been hacking at it for a day now.

  • 0

Desperately need help on this task; been hacking at it for a day now. The functionality is to translate text written by the admin through the admin interface to a PDF the user can view through the web application.

That functionality has been implemented except I want to be able to see the PDF I will generate before actually publishing it. So in the admin interface, I’m looking to create a “Preview PDF” button. Essentially it would save the current form (with new changes) generate the PDF so the changes can be seen, and rollback to the original state so no change can be seen by the outside world.

I’m tackling the problem by overriding the save function in models.

@transaction.commit_manually
def save(self, force_insert=False, force_update=False, using=None):
    super(Doc, self).save(force_insert=force_insert, force_update=force_update, using=using)
    if self.preview:
        from lava_server.settings import common
        # make a copy
        doc_copy = self
        doc_copy.id = None
        # Prevent loopback
        doc_copy.preview = False
        transaction.rollback()
        doc_copy.save()
        common.TEMP_PDF_ID = doc_copy.id
    else:
        transaction.savepoint_commit(sid)

I’ve also overridden the response_change and response_add to redirect to the view that renders the PDF. The view deletes the doc_copy after the render.

To be honest, it was working I think but now it’s giving me a

TransactionManagementError: Transaction managed block ended with pending COMMIT/ROLLBACK

It’s probably because of my nested transaction in the save method? But I feel like I should seek for higher help on this in case I’m missing something fundamental or there’s just a plain superior way of doing it.

Any help is much appreciated, thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T06:25:26+00:00Added an answer on June 5, 2026 at 6:25 am

    This seems like a very complex way of doing it – this way you make it possible to create a savepoint and never commit/rollback it into DB, which may lead to database locks(like in your example).

    I’d do it simpler – when hitting the “Preview PDF” button, just create the pdf and return it using

    response = HttpResponse(mimetype='application/pdf')
    response['Content-Disposition'] = 'attachment; filename=preview.pdf'
    
    #print PDF to response
    return response
    

    This will download the PDF in your browser, and no saving will occur into the DB. You can preview it, and when everything seem OK – then save it in the regular way. Just save all other changes in the DB, so when reloading the page to keep them in the form.

    Another solution could be to implement file status field for the PDF file, with status = “DRAFT|PUBLISHED”, and to show to users only PUBLISHED versions, while DRAFT to be available in Admin only …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I desperately need help on this. I've have been looking all over for a
I'm in desperate need of help. I've been working on this for over 20
I desperately need some help on this one. I've created a <script> that closely
I really desperately need help with this issue and am more than a little
I desperately need help with a query that's been causing a lot of grief
I'm in desperate need of help and direction. Been trying to get this to
I'm new to this ExpandableListView and I desperately need your help please. I'm using
I really need help here. I'm desperate at this point. I have NSOperation that
I am new in this field and i desperately need some guidance from u
I desperately need help with a memory leak in my iPhone app. The app

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.