Login page getting downloaded as pdf instead of the other page url.

2022-02-06 Thread Aadil Rashid


Hello Django Family, I hope you all are well and in good Health. 

I am trying to generating pdf from webpages, using popen subprocess , but 
when i call its

view it generates only login page as pdf,


Here is my view


from projName.settings import BASE_DIR

from subprocess import Popen, PIPE, STDOUT

from wsgiref.util import FileWrapper



class DownloadAsPDF(View):

 def post(self, request, *args, **kwargs):

  base = str(BASE_DIR)

  file_name = str( base + '/testreport.pdf')

  post_url = request.POST.get("page_url")

  url = str('http://' + request.get_host() + post_url)

  chrome_args = ['/path/google-chrome', '--headless', 
'--virtual-time-buget=2',

'--print-to-pdf=/path/testreport.pdf', URL]

  external_process = Popen(chrome_args, stdout=PIPE, stderr=STDOUT)

  external_process.wait()

  return_file = FileWrapper(open('{}'.format(file_name), 'r'))

  download_file_name = 'report'

  response = FileResponse(return_file, 
content_type='application/force-download')

  response['Content-Disposition'] = f'attachment; filename=
  
{download_file_name}.pdf'

  return response


I was thinking of creating the popen subprocess in the same browser session 
so that it will directly go to the said url page, instead of login page, 

I couldn't find any good resources to implement this functionality, as it 
is headless chrome here may be it's not possible to open in the same 
browser session. 


If this can't be the perfect solution, then please if anyone have some 
other solution I will be very thankful,

Thanks you very much

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fc2748a8-7d99-4f1d-bf57-d4a0bfa878fdn%40googlegroups.com.


Re: UNIQUE constraint failed: matrixapp_bookplot.user_id

2022-02-06 Thread Sebastian Jung
Hello,

Because your implementation is wrong.

Please read this https://tech.serhatteker.com/post/2020-01/uuid-primary-key/

Jason  schrieb am So., 6. Feb. 2022, 00:27:

> A bit of a hint about your db schema, do you want a user ID to be one to
> one with each book plot?  also, why is your primary key a string field?
> On Saturday, February 5, 2022 at 10:43:05 AM UTC-5 armaan...@gmail.com
> wrote:
>
>> Hello everyone,
>>
>> when i am trying to add uuid primary key , I am getting this error UNIQUE
>> constraint failed: matrixapp_bookplot.user_id
>>
>> what is wrong here
>>
>> class BookPlot(models.Model):
>>
>> ref_id = models.CharField(max_length=25)
>> code = str(uuid.uuid4()).replace("-", "")[:4]
>> user_id=models.CharField(primary_key=True,max_length=50,
>> default=code, editable=False)
>> plot_number = models.CharField(max_length=25)
>> Payable_amout = models.IntegerField(null=True, blank=True)
>> Mnthly_Installment = models.IntegerField(null=True, blank=True)
>> number_of_Installment = models.IntegerField()
>> name = models.CharField(max_length=100)
>> father_name = models.CharField(max_length=100)
>> mobile_no = models.IntegerField()
>> payment_mode = models.CharField(max_length=10)
>> remarks = models.CharField(max_length=100)
>> receipt = models.ImageField(upload_to = 'receipt/', null= True,
>> blank=True)
>>
>> joinig_date=models.DateField(auto_now_add=True,null=True,blank=True)
>>
>>
>>
>>
>> def  bookplot(request):
>>
>>
>> if request.method =="POST":
>> ref_id = request.POST.get('ref_id')
>>
>> plot_number = request.POST.get('plot_number')
>> amount = request.POST.get('amount')
>> Mnthly_Installment = request.POST.get('Mnthly_installment')
>> no_Installment = request.POST.get('no_Installment')
>> name = request.POST.get('name')
>> father_name = request.POST.get('father_name')
>> mobile_number = request.POST.get('mobile_number')
>> payment_mode = request.POST.get('payment_mode')
>> remarks = request.POST.get('remarks')
>> receipt = request.FILES.get('receipt')
>> print(ref_id)
>> book_plot = BookPlot(ref_id= ref_id,plot_number =
>> plot_number, Payable_amout = amount,Mnthly_Installment =
>> Mnthly_Installment, number_of_Installment = no_Installment, name =
>> name,father_name = father_name , mobile_no = mobile_number, payment_mode =
>> payment_mode ,remarks=remarks,receipt=receipt )
>> book_plot.save()
>>
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/8e0d1acf-a7c2-4a6b-9b04-001856d47071n%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAKGT9my2cwrWhGOty3H6Vn%3Du7xQqFh242m8YHV_vZ7QV9gBsiA%40mail.gmail.com.


Re: Formsets

2022-02-06 Thread Steven Mapes
For me using select_related, prefetch_related and defer generally soft the 
issues. If that's still too slow then, if possible, you could look at using 
caching the queryset(s) you need the values. Have you run debug toolbar on 
the page to check what queries are running?

On Saturday, 5 February 2022 at 20:27:10 UTC stevesm...@hotmail.com wrote:

> Hello all!   
>
> I find formsets wildly useful...but very difficult to architect.  I have 
> them working...But I am running into a commonly documented problem...They 
> are slow as you build up the number of fields and queries.  Are there any 
> general tips that can be used or share on how to improve this issue?  I 
> have tried all of the commonly prescribed 
> solutions...select_related...prefetch_related...etc...But nothing seems to 
> help.  
>
> I realize that Queries take timebut I'm just trying to see if there is 
> a way to streamline them a bit.  It seems to me that formsets use a lot of 
> queries depending on the amount of data and that's the trade off. 
>
> Again thanks for any thoughts or comments.
>
> Steve
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6513c105-8151-4c7a-8fd2-e692d5c5dcb5n%40googlegroups.com.


Re: Formsets

2022-02-06 Thread Steve Smith
HI Steve!

Thanks for the reply.  I have tried select related and prefetch relatedbut 
didn't know about deferwill look into...my current formset scenario is 
440ish queries and it takes about 19 seconds to load.  Some have suggested 
Celery and RabbitMQ and other alternatives which I'm not familiar with.  I need 
to explore those things further.  I have used the debug toolbar as wellit 
shows me that there are lots of duplicate queries...but I'm unclear on how to 
go about fixing them...as the select related and prefetch hasn't seemed to help 
either.

I'm using class based views with formsets and just kind of at a loss right now 
as to if there is anything that can be done to speed up these queries.  I 
opened up a SO on the issue...and got some suggestions on how to go about 
improving my dictionary look up...but after trying some of those suggestions 
the performance issue remains.

Thanks again for taking the time to respond.

Steve

From: django-users@googlegroups.com  on behalf 
of Steven Mapes 
Sent: Sunday, February 6, 2022 11:47 AM
To: Django users 
Subject: Re: Formsets

For me using select_related, prefetch_related and defer generally soft the 
issues. If that's still too slow then, if possible, you could look at using 
caching the queryset(s) you need the values. Have you run debug toolbar on the 
page to check what queries are running?

On Saturday, 5 February 2022 at 20:27:10 UTC stevesm...@hotmail.com wrote:
Hello all!

I find formsets wildly useful...but very difficult to architect.  I have them 
working...But I am running into a commonly documented problem...They are slow 
as you build up the number of fields and queries.  Are there any general tips 
that can be used or share on how to improve this issue?  I have tried all of 
the commonly prescribed 
solutions...select_related...prefetch_related...etc...But nothing seems to help.

I realize that Queries take timebut I'm just trying to see if there is a 
way to streamline them a bit.  It seems to me that formsets use a lot of 
queries depending on the amount of data and that's the trade off.

Again thanks for any thoughts or comments.

Steve


--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6513c105-8151-4c7a-8fd2-e692d5c5dcb5n%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CH0PR18MB42921F540CB239D4F5E250CCD22B9%40CH0PR18MB4292.namprd18.prod.outlook.com.


how to report an issue in the documentation

2022-02-06 Thread Sirajudeen Samsudeen
Hi fellow Djangoers,

I spotted an error in the docs for the collectstatic command and spent 
sometime figuring out how to make it work only to realize that there is a 
typo in the docs. I would like to report it so that it gets fixed. I am 
quite new to Django. So, how do I do it? 

Here is the error 
in 
https://docs.djangoproject.com/en/4.0/ref/contrib/staticfiles/#django-admin-collectstatic

At the top it specifies the command as 
`django-admin collectstatic` which is wrong - when I tried this, I got the 
error message 
"No Django settings specified. Unknown command: 'collectstatic' Type 
'django-admin help' for usage."

At the bottom of the section, it lists the right command using manage.py

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1cd1e769-cf97-4c00-9432-51af71a9b1f5n%40googlegroups.com.


Media Files - local network share

2022-02-06 Thread Swelan Auguste
Good day all,


I am trying to figure out how to attach a Django app to a local network
server/share.

I do not want to host the media files on the same server so that the server
doesn't run out of space and I can and I can grow my media file host
share/server as it grows.
Kindly,

Swelan R. Auguste (Mr.)
KingShip
Technical Information Officer
758-489-3909
Webpage 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAKj-cedrdvqRmGZ29cMNsk0%2BypXy5fRzRsMx%3DziiPpVr1JOHfA%40mail.gmail.com.


Re: how to report an issue in the documentation

2022-02-06 Thread Enkh-Amar Ganbat
I think You can make a pull request on its documentation of GitHub.
https://github.com/django/django/tree/main/docs

On Monday, February 7, 2022 at 8:59:36 AM UTC+8 mail...@gmail.com wrote:

> Hi fellow Djangoers,
>
> I spotted an error in the docs for the collectstatic command and spent 
> sometime figuring out how to make it work only to realize that there is a 
> typo in the docs. I would like to report it so that it gets fixed. I am 
> quite new to Django. So, how do I do it? 
>
> Here is the error in 
> https://docs.djangoproject.com/en/4.0/ref/contrib/staticfiles/#django-admin-collectstatic
>
> At the top it specifies the command as 
> `django-admin collectstatic` which is wrong - when I tried this, I got the 
> error message 
> "No Django settings specified. Unknown command: 'collectstatic' Type 
> 'django-admin help' for usage."
>
> At the bottom of the section, it lists the right command using manage.py
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/334965c0-e4ae-4f89-b749-bb89c97d1857n%40googlegroups.com.


Re: Media Files - local network share

2022-02-06 Thread Yeboah Dominic
You can try dropbox that is what I used to serve my media files in django

On Sun, 6 Feb 2022 at 20:07, Swelan Auguste  wrote:

>
> Good day all,
>
>
> I am trying to figure out how to attach a Django app to a local network
> server/share.
>
> I do not want to host the media files on the same server so that the
> server doesn't run out of space and I can and I can grow my media file host
> share/server as it grows.
> Kindly,
>
> Swelan R. Auguste (Mr.)
> KingShip
> Technical Information Officer
> 758-489-3909
> Webpage 
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAKj-cedrdvqRmGZ29cMNsk0%2BypXy5fRzRsMx%3DziiPpVr1JOHfA%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPVAacjQwHJ2kUSWhB3FZTTw2c03RMcbiNyP1cpDcvXbGhaKzw%40mail.gmail.com.


Re: Media Files - local network share

2022-02-06 Thread Swelan Auguste
Good day,

Thanks. I was more looking for a local solutions (within a closed network)

Kindly,

Swelan R. Auguste (Mr.)
KingShip
Technical Information Officer
758-489-3909
Webpage 



On Sun, Feb 6, 2022 at 9:19 PM Yeboah Dominic  wrote:

> You can try dropbox that is what I used to serve my media files in django
>
> On Sun, 6 Feb 2022 at 20:07, Swelan Auguste 
> wrote:
>
>>
>> Good day all,
>>
>>
>> I am trying to figure out how to attach a Django app to a local network
>> server/share.
>>
>> I do not want to host the media files on the same server so that the
>> server doesn't run out of space and I can and I can grow my media file host
>> share/server as it grows.
>> Kindly,
>>
>> Swelan R. Auguste (Mr.)
>> KingShip
>> Technical Information Officer
>> 758-489-3909
>> Webpage 
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAKj-cedrdvqRmGZ29cMNsk0%2BypXy5fRzRsMx%3DziiPpVr1JOHfA%40mail.gmail.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAPVAacjQwHJ2kUSWhB3FZTTw2c03RMcbiNyP1cpDcvXbGhaKzw%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAKj-ceeHSV2GE8Px5bTph5pS_bvW2WNhUKMZV_aiWreU%3D4wmkQ%40mail.gmail.com.


Off topic slightly - Apache https redirect

2022-02-06 Thread Mike Dewhirst
There seems to be a multitude of ways to redirect from http to 
https.Letsencrypt rewrote my conf for port 80 traffic to https but when a 
customer used http://mysite.com it brought up the Apache "this is working" 
page.Any pointers to the absolutely correct way?ThanksMike--(Unsigned mail from 
my phone)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/62007f89.1c69fb81.6f671.d033SMTPIN_ADDED_MISSING%40gmr-mx.google.com.