Re: Necesito orientacion de que debo hacer y como lo debo hacer(procedimiento)

2021-12-03 Thread Rafael Matos Borges
Eu também aprendendo agora django

Em qua., 1 de dez. de 2021 20:22, Amor Zamora 
escreveu:

> Les comento que con la libreria PyPDF2, quiero leer 1 archivo (.pdf) que
> esta en una carpeta, tomar la informacion de ese archivo y enviarla a un
> scrpt, que se procese(ya tengo hechas las funciones del scropt, las pongoa
> aocntinuacion) y luego los resultados los queiro guardar en otro pdf y que
> este se guarde en la misma carpeta, pero con el nombre resultados.
>
> Sugerencias de como puedo hacer esto.
>
> Escrip que va a procesar la informaciond el pdf.
> import pdfAWAM
> import sys, os
> import optparse
> import time
> import config
> import requests
> import io
>
> USAGE="""%s [options] pdffile - Check PDF documents for accessibility"""
>
> def checkAcc(pdffile_or_url, passwd='', verbose=True, report=False,
> developer=False, loglevel='info'):
>
> config.pdfwamloglevel = loglevel
>
> if pdffile_or_url.startswith('http://') or pdffile_or_url.startswith(
> 'https://'):
> data = requests.get(pdffile_or_url).content
> stream = io.BytesIO(data)
> else:
> stream = open(pdffile_or_url, 'rb')
> json_response = pdfAWAM.extractAWAMIndicators(stream, passwd, verbose,
> report, developer, json_value=True, console=True)
>
> print("JSON Response",json_response)
>
> def setupOptions():
> if len(sys.argv)==1:
> sys.argv.append('-h')
> o = optparse.OptionParser(usage=USAGE % sys.argv[0] )
> o.add_option('-p','--password',
> dest='password',help='Optional password for encrypted PDF',default='')
> o.add_option('-q','--quiet',
> dest='quiet',help="Be quiet, won't print debug/informational messages",
> action="store_true",
> default=False)
> o.add_option('-d','--developer',
> dest='developer',help="Print a dictionary of information for the
> developer (please note that this turns off reporting and debug messages
> automatically)",action="store_true",
> default=False)
> o.add_option('-r','--report',
> dest='report',help="Print a report of test results at the end",action=
> "store_true",
> default=False)
> o.add_option('-l','--loglevel',
> dest='loglevel',help="Set logging level (default: info)",
> default='info')
> o.add_option('-j', '--json',
> dest='json', help="Print JSON of result",action="store_true",
> default=False)
>
> options, args = o.parse_args()
> return (args[0], options.__dict__)
>
> def main():
> pdffile, options = setupOptions()
>
> password = options.get('password','')
> quiet = options.get('quiet')
> report = options.get('report')
> developer = options.get('developer')
> loglevel = options.get('loglevel','info')
> json_flag = options.get('json')
>
> if developer:
> print('Developer option turned on, reporting and messages will be
> disabled.')
>
> verbose = (not quiet)
> checkAcc(pdffile, password, verbose, report, developer, loglevel)
>
> if __name__ == "__main__":
> main()
>
>
> --
> 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/6c90af17-0034-41ac-b413-c705269066b7n%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/CAH-G9S4u%3DB6O5vu5vE%3DcM5n5GnEja5UCUqg%3D9RYMK0Gcv6k9LQ%40mail.gmail.com.


Re: for loop + transaction.on_commit + celery = Unexpected Behaviour

2021-12-03 Thread Martin Pätzold
This is an older topic, but for everyone who found this discusion and had 
the same issue: The problem is most likely using "lambda" inside a 
for-loop. If you switch out "lambda" for "functools.partial" it should work 
as expected.
Jani Tiainen schrieb am Donnerstag, 27. April 2017 um 08:27:11 UTC+2:

> Hi,
>
> I think your problem is to use POST['_models_changed']. Django uses 
> specialized version of dictionary there which return _last_ value from 
> list. You need to use special "get_list()" method to get whole list of 
> objects.
> Your code should start working if you do 
> data['_models_changed'].get_list()  in a for-loop.
>
> Also, why you modify request.POST instead of adding class attribute?
>
>
> On 24.04.2017 14:37, Emilio Jimenez Canalejo wrote:
>
> Hi, I've been looking for some time around the internet a problem I have, 
> maybe I'm just dull from all the searching and the answer is pretty 
> obvious, but I can't find it. 
>
> For example, I have code like this:
> @app.task
> def foo(idx):
> print("This is iteration {}".format(idx))
>
> def save_model(self, request, obj, form, change):
> data = request.POST
> result = super(Model, self).save_model(request, obj, form, change)
>
> for pk in data['_models_changed']:
> transaction.on_commit(lambda: foo(pk))
>
> To my astonishment, I thought I would get:
> "This is iteration 1"
> "This is iteration 2"
> "This is iteration 3"
> "This is iteration 4"
>
> But I got:
> "This is iteration 4"
> "This is iteration 4"
> "This is iteration 4"
> "This is iteration 4"
>
> I'm using python 2.7, Django 1.10.5 and Celery 4.0.2.
>
> 'models_changed' is a field in the post added by a custom clean method.
>
> Anyone knows a way to do this?
>
> Thanks for all!
>
> -- 
> 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...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/91e87fb4-69e2-4b4e-bd6b-704eb7567026%40googlegroups.com
>  
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
> -- 
> Jani Tiainen
>
>

-- 
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/2cfba61c-e78a-45c5-87b7-e0cbbdc09165n%40googlegroups.com.


Re: Use previously requested data in another request

2021-12-03 Thread kayhan
Thanks but I did not change the settings.
And to test, SESSION_COOKIE_AGE = 5 * 60,
  I added to the settings but there is still the same problem.

On Fri, Dec 3, 2021 at 8:55 PM Lalit Suthar 
wrote:

> We can save that in any django model in ajax() request if possible.
>
> You can check if you have modified `SESSION_COOKIE_AGE` (
> https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-SESSION_COOKIE_AGE
> )
> if it is too less that might be the reason.
>
> On Fri, 3 Dec 2021 at 16:15, kayhan  wrote:
>
>> Hi
>> I first send a request to Django and save its data with a session.
>> I will send another request to Django later. Here I want to use the data
>> of the previous request.
>> But my code does not work properly. And the value "None" appears in the
>> output.
>> Does anyone know what I should do?
>> Thankful
>>
>> def planing(request): if request.is_ajax(): # Get user location from
>> user location.js file: latitude = request.POST.get('latitude', None)
>> longitude = request.POST.get('longitude', None) print("latitude,
>> longitude = ", latitude,longitude) # To save data request.session[
>> 'latitude'] = latitude request.session['longitude'] = longitude # To
>> retrive data: latitude = request.session.get('latitude') longitude =
>> request.session.get('longitude') print("latitude, longitude = ",
>> latitude,longitude) elif request.method == "GET": return render(request,
>> "tourist/planing.html") elif request.method == "POST": # To retrive data:
>> latitude = request.session.get('latitude') longitude =
>> request.session.get('longitude') print("latitude, longitude = ",
>> latitude,longitude) Output: latitude, longitude = 34.801595 48.499574
>> latitude, longitude = 34.801595 48.499574 latitude, longitude = None None
>>
>> --
>> 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/4bef9d07-cd92-440a-8ec0-dd4c206e6ae7n%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/CAGp2JVEkLiwVEAF3uV%3DBBOQJuUwVBaQGhD7RA7t0aDirh%2BD-ZQ%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/CAO-vjETOG1Nq%3D_Evk7ryvr27eBxtDSQfiygKV%3Djq9TTzkiuPTw%40mail.gmail.com.


Re: Use previously requested data in another request

2021-12-03 Thread Lalit Suthar
We can save that in any django model in ajax() request if possible.

You can check if you have modified `SESSION_COOKIE_AGE` (
https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-SESSION_COOKIE_AGE
)
if it is too less that might be the reason.

On Fri, 3 Dec 2021 at 16:15, kayhan  wrote:

> Hi
> I first send a request to Django and save its data with a session.
> I will send another request to Django later. Here I want to use the data
> of the previous request.
> But my code does not work properly. And the value "None" appears in the
> output.
> Does anyone know what I should do?
> Thankful
>
> def planing(request): if request.is_ajax(): # Get user location from user
> location.js file: latitude = request.POST.get('latitude', None) longitude
> = request.POST.get('longitude', None) print("latitude, longitude = ",
> latitude,longitude) # To save data request.session['latitude'] = latitude
> request.session['longitude'] = longitude # To retrive data: latitude =
> request.session.get('latitude') longitude = request.session.get(
> 'longitude') print("latitude, longitude = ", latitude,longitude) elif
> request.method == "GET": return render(request, "tourist/planing.html")
> elif request.method == "POST": # To retrive data: latitude =
> request.session.get('latitude') longitude = request.session.get(
> 'longitude') print("latitude, longitude = ", latitude,longitude) Output:
> latitude, longitude = 34.801595 48.499574 latitude, longitude = 34.801595
> 48.499574 latitude, longitude = None None
>
> --
> 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/4bef9d07-cd92-440a-8ec0-dd4c206e6ae7n%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/CAGp2JVEkLiwVEAF3uV%3DBBOQJuUwVBaQGhD7RA7t0aDirh%2BD-ZQ%40mail.gmail.com.


Re: How to get a variable from an ajax request and use it in another application in Django?

2021-12-03 Thread kayhan
Hi
Sorry, as you said I used the session.
But my problem has not been solved yet.

I first send a request to Django and save its data with a session.
I will send another request to Django later. Here I want to use the data of
the previous request.
But my code does not work properly. And the value "None" appears in the
output.
Thankful

def planing(request): if request.is_ajax(): # Get user location from user
location.js file: latitude = request.POST.get('latitude', None) longitude =
request.POST.get('longitude', None) print("latitude, longitude = ",
latitude,longitude) # To save data request.session['latitude'] = latitude
request.session['longitude'] = longitude # To retrieve data: latitude =
request.session.get('latitude') longitude = request.session.get('longitude')
print("latitude, longitude = ", latitude,longitude) elif request.method ==
"GET": return render(request, "tourist/planing.html") elif request.method
== "POST": # To retrieve data: latitude = request.session.get('latitude')
longitude = request.session.get('longitude') print("latitude, longitude = ",
latitude,longitude) Output: latitude, longitude = 34.801595 48.499574
latitude, longitude = 34.801595 48.499574 latitude, longitude = None None

On Wed, Dec 1, 2021 at 6:37 PM kayhan  wrote:

> Thank you David
>
> On Wed, Dec 1, 2021 at 3:56 AM David Nugent  wrote:
>
>> That is definitely much more clear.
>>
>> The usual way of doing this is to handle it like a shopping cart (plenty
>> of examples only a google search away).
>> Typically you store this information in the user's session in the first
>> view, then retrieve it in the subsequent view(s).
>>
>> Note that `request.is_ajax` is deprecated and does not even exist anymore
>> in Django 3.x. You can guess that from other info, but you should probably
>> use a
>> different view for handling the ajax request in any case, for clarity and
>> maintainability. The response data would usually use a different format
>> (json vs text/html).
>>
>> Regards, David
>>
>> On Wed, Dec 1, 2021 at 6:04 AM kayhan  wrote:
>>
>>> Sorry I did not ask the question well.
>>> Question:
>>> How to first send some data with an Ajax request to Django view and then
>>> with a post request, send the form information to the same view and use the
>>> data sent in the previous request (Ajax request) in the second request ?
>>>
>>> def planing(request):
>>>
>>> if request.is_ajax():
>>> # Get user location from user location.js file:
>>> latitude = request.POST.get('latitude', None)
>>> longitude = request.POST.get('longitude', None)
>>>
>>>
>>> elif request.method == "GET":
>>> return render(request, "tourist/planing.html")
>>>
>>>
>>> elif request.method == "POST":
>>> # Here I want to take the form data and have
>>> #the previous request data (latitude, longitude) here and do a series of
>>> processing.
>>>
>> --
>> 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/CAE5VhgWbiA8Ayhkss1saVg9my_S%2Bw8e1SYxhwp3xGCTD2L8snA%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/CAO-vjERuNQuJYLB6_67S_yV3AQhHaenoPWdAJwJ183GHYT2rGw%40mail.gmail.com.


Use previously requested data in another request

2021-12-03 Thread kayhan
Hi
I first send a request to Django and save its data with a session.
I will send another request to Django later. Here I want to use the data of 
the previous request.
But my code does not work properly. And the value "None" appears in the 
output.
Does anyone know what I should do?
Thankful

def planing(request): if request.is_ajax(): # Get user location from user 
location.js file: latitude = request.POST.get('latitude', None) longitude = 
request.POST.get('longitude', None) print("latitude, longitude = ", 
latitude,longitude) # To save data request.session['latitude'] = latitude 
request.session['longitude'] = longitude # To retrive data: latitude = 
request.session.get('latitude') longitude = request.session.get('longitude') 
print("latitude, longitude = ", latitude,longitude) elif request.method == 
"GET": return render(request, "tourist/planing.html") elif request.method 
== "POST": # To retrive data: latitude = request.session.get('latitude') 
longitude = request.session.get('longitude') print("latitude, longitude = ", 
latitude,longitude) Output: latitude, longitude = 34.801595 48.499574 
latitude, longitude = 34.801595 48.499574 latitude, longitude = None None

-- 
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/4bef9d07-cd92-440a-8ec0-dd4c206e6ae7n%40googlegroups.com.


Re: gettext vs ugettext_lazy

2021-12-03 Thread David Nugent
Correction, Python 2.x support

On Fri, Dec 3, 2021 at 8:12 PM David Nugent  wrote:

> Don't use ugettext*, they are deprecated and no longer exist in 3.x. m
> They were for Django 2.x support.
>
> On Fri, Dec 3, 2021 at 5:54 PM  wrote:
>
>> Hello
>>
>> Would like to know, what are the difference between gettext and
>> ugettext_lazy?
>>
>> When to use each of them?
>>
>> --
>> 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/00e601d7e812%2482841ab0%24878c5010%24%40gmail.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/CAE5VhgWEgTr9sWyD8wCKYAPo3DpOfjyX03mu0%2BZYaR3JMf9Q7w%40mail.gmail.com.


I need orientation on what to do and how to do it (procedure)

2021-12-03 Thread Amor Zamora
I comment that with the PyPDF2 library, I want to read 1 file (.pdf) that 
is in a folder, take the information from that file and send it to a scrpt, 
which is processed (I already have the scropt functions done, I put them 
here) and then I want to save the results in another pdf and that this be 
saved in the same folder, but with the name results. Suggestions on how I 
can do this. Escrip that will process the information in the pdf.
import pdfAWAM
import sys, os
import optparse
import time
import config
import requests
import io

USAGE="""%s [options] pdffile - Check PDF documents for accessibility"""

def checkAcc(pdffile_or_url, passwd='', verbose=True, report=False, 
developer=False, loglevel='info'):

config.pdfwamloglevel = loglevel

if pdffile_or_url.startswith('http://') or pdffile_or_url.startswith('
https://'):
data = requests.get(pdffile_or_url).content
stream = io.BytesIO(data)
else:
stream = open(pdffile_or_url, 'rb')
json_response = pdfAWAM.extractAWAMIndicators(stream, passwd, verbose, 
report, developer, json_value=True, console=True)

print("JSON Response",json_response)

def setupOptions():
if len(sys.argv)==1:
sys.argv.append('-h')
o = optparse.OptionParser(usage=USAGE % sys.argv[0] )
o.add_option('-p','--password',
dest='password',help='Optional password for encrypted PDF',default='')
o.add_option('-q','--quiet',
dest='quiet',help="Be quiet, won't print debug/informational messages",
action="store_true",
default=False)
o.add_option('-d','--developer',
dest='developer',help="Print a dictionary of information for the developer 
(please note that this turns off reporting and debug messages 
automatically)",action="store_true",
default=False) 
o.add_option('-r','--report',
dest='report',help="Print a report of test results at the end",action=
"store_true",
default=False)
o.add_option('-l','--loglevel',
dest='loglevel',help="Set logging level (default: info)",
default='info')
o.add_option('-j', '--json',
dest='json', help="Print JSON of result",action="store_true",
default=False)

options, args = o.parse_args()
return (args[0], options.__dict__)

def main():
pdffile, options = setupOptions()

password = options.get('password','')
quiet = options.get('quiet')
report = options.get('report')
developer = options.get('developer')
loglevel = options.get('loglevel','info')
json_flag = options.get('json')

if developer:
print('Developer option turned on, reporting and messages will be disabled.'
)

verbose = (not quiet)
checkAcc(pdffile, password, verbose, report, developer, loglevel)

if __name__ == "__main__":
main()

-- 
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/3c640390-fc35-45dc-880d-8f02b980a1e0n%40googlegroups.com.


Re: gettext vs ugettext_lazy

2021-12-03 Thread David Nugent
Don't use ugettext*, they are deprecated and no longer exist in 3.x. m They
were for Django 2.x support.

On Fri, Dec 3, 2021 at 5:54 PM  wrote:

> Hello
>
> Would like to know, what are the difference between gettext and
> ugettext_lazy?
>
> When to use each of them?
>
> --
> 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/00e601d7e812%2482841ab0%24878c5010%24%40gmail.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/CAE5VhgV4jW2FTHgRXdNsPCtOVW-1kU8XRJJZqqWT8333qb0POA%40mail.gmail.com.