Re: How to hash fields and detect changes in a record

2022-06-14 Thread Mike Dewhirst

On 14/06/2022 11:20 pm, Ryan Nowakowski wrote:


Summing the ordinal of the characters won't catch transposition:

>>> chars = 'ab'
>>> sum([ord(c) for c in chars])
195
>>> chars = 'ba'
>>> sum([ord(c) for c in chars])
195

Better to use a real hash algorithm if you're trying to detect 
changes.  My note above about hashing not being required is because 
you don't need to detect changes because you explicitly already know 
when changes are being made.




Thanks Ryan.

It is all working now. I append " - No longer relevant" to the note 
title if any change is detected. Otherwise the note gets deleted.


Cheers

Mike




--
Signed email is an absolute defence against phishing. This email has
been signed with my private key. If you import my public key you can
automatically decrypt my signature and be sure it came from me. Just
ask and I'll send it to you. Your email software can handle signing.

--
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/75458bb4-bb4b-0e44-54c1-59768d34d403%40dewhirst.com.au.


OpenPGP_signature
Description: OpenPGP digital signature


Looking for a PHOTOLogue Expert

2022-06-14 Thread pamela grossman
Hi,

I am looking for someone to help me upload images to save on a drive that 
are on photologue i have no idea how to use it. 

-- 
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/5abf7cc8-1ce4-45c6-aa2b-901b050f8e98n%40googlegroups.com.


Re: how to create icon img api

2022-06-14 Thread 'Kasper Laudrup' via Django users

On 14/06/2022 18.03, Mahesh Ghule wrote:

how to create image icon api ..please support me



This is a good place to start:

https://www.propublica.org/nerds/how-to-ask-programming-questions

Kind regards,

Kasper Laudrup

--
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/76e01be1-5e45-6ab2-1e5c-7a48c1416c40%40stacktrace.dk.


OpenPGP_0xE5D9CAC64AAA55EB.asc
Description: OpenPGP public key


OpenPGP_signature
Description: OpenPGP digital signature


Re: I can't use accented letters in my model

2022-06-14 Thread Ryan Nowakowski
This is a good primer on bytes vs strings:

https://www.joelonsoftware.com/2003/10/08/the-absolute-minimum-every-software-developer-absolutely-positively-must-know-about-unicode-and-character-sets-no-excuses/


On June 14, 2022 2:43:54 AM CDT, Antonis Christofides 
 wrote:
>Exactly. The important thing to remember here is that, in Python 2, a "string" 
>is actually a list of bytes, whereas a "unicode string" is actually a list of 
>characters (not a list of unicode characters—just a list of characters). The 
>confusion arises because, when Python was created, i.e. in 1990, multi-byte 
>characters were in their infancy, and we mostly assumed that a character and a 
>byte was more or less the same thing.
>
>In Python 3, the Python 2 "strings" were renamed to "bytes", and the Python 2 
>"unicode strings" were renamed to "strings"—and the syntax for the literals of 
>these types also changed. This made it way better.
>
>More information about all this is in 
>https://djangodeployment.com/2017/06/19/encodings-part-1/.
>
>
>
>On 12/06/2022 12.07, Virgilio Ravagli wrote:
>> I found a way: book.title = titolo.decode('unicode_escape')
>> it works fine
>> 
>> Il giorno venerdì 10 giugno 2022 alle 21:45:46 UTC+2 Virgilio Ravagli ha 
>> scritto:
>> 
>> Thank you, Antonis, it works !
>> book.title = u'Verità' doesn't give any errors.
>> 
>> Just another step: suppose that the title with accented letters stays in 
>> a
>> variable, say titolo, and I want to write
>> book.title = titolo. It gives error. How can I do, when the assignment on
>> the right is not a constant ?
>> Thanks in advance
>> 
>> Il giorno venerdì 10 giugno 2022 alle 15:25:51 UTC+2 Antonis Christofides
>> ha scritto:
>> 
>> Hello,
>> 
>> try this:
>> 
>> book.title = u'Verità'
>> 
>> Regards,
>> 
>> Antonis
>> 
>> P.S. Sorry I was a bit harsh yesterday—I had drunk too much beer :-)
>> 
>> 
>> On 10/06/2022 10.50, Virgilio Ravagli wrote:
>>> I have surround book.save with a try...catch...; the exception is:
>>> You must not use 8-bit bytestrings unless you use a text_factory 
>>> that
>>> can interpret 8-bit bytestrings (like text_factory = str). It is
>>> highly recommended that you instead just switch your application to
>>> Unicode strings.
>>> Without the try...catch, here is the traceback:
>>> Environment:
>>> 
>>> 
>>> Request Method: POST
>>> Request URL: http://localhost:8000/uti/dataLoading/
>>> 
>>> Django Version: 1.8.5
>>> Python Version: 2.7.10
>>> Installed Applications:
>>> ('django.contrib.admin',
>>>  'django.contrib.auth',
>>>  'django.contrib.contenttypes',
>>>  'django.contrib.sessions',
>>>  'django.contrib.messages',
>>>  'django.contrib.staticfiles',
>>>  'uti')
>>> Installed Middleware:
>>> ('django.contrib.sessions.middleware.SessionMiddleware',
>>>  'django.middleware.common.CommonMiddleware',
>>>  'django.middleware.csrf.CsrfViewMiddleware',
>>>  'django.contrib.auth.middleware.AuthenticationMiddleware',
>>>  'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
>>>  'django.contrib.messages.middleware.MessageMiddleware',
>>>  'django.middleware.clickjacking.XFrameOptionsMiddleware',
>>>  'django.middleware.security.SecurityMiddleware')
>>> 
>>> 
>>> Traceback:
>>> File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in
>>> get_response
>>>   132.                     response = wrapped_callback(request,
>>> *callback_args, **callback_kwargs)
>>> File
>>> "C:\Users\RavagliV\eclipse-workspace-saved\librarian\uti\views.py" 
>>> in
>>> datLoading
>>>   34.                 msg = do_dat_loading()
>>> File
>>> "C:\Users\RavagliV\eclipse-workspace-saved\librarian\uti\views.py" 
>>> in
>>> do_dat_loading
>>>   79.             book.save()
>>> File "C:\Python27\lib\site-packages\django\db\models\base.py" in 
>>> save
>>>   734.  force_update=force_update, update_fields=update_fields)
>>> File "C:\Python27\lib\site-packages\django\db\models\base.py" in
>>> save_base
>>>   762.             updated = self._save_table(raw, cls, 
>>> force_insert,
>>> force_update, using, update_fields)
>>> File "C:\Python27\lib\site-packages\django\db\models\base.py" in
>>> _save_table
>>>   827. forced_update)
>>> File "C:\Python27\lib\site-packages\django\db\models\base.py" in
>>> _do_update
>>>   877.         return filtered._update(values) > 0
>>> File "C:\Python27\lib\site-packages\django\db\models\query.py" in 
>>> _update
>>>   580.         return 
>>> query.get_compiler(self.db).execute_sql(CURSOR)
>>> 

Re: Does django supports dynamic allowlist in EmailValidator

2022-06-14 Thread Sebastian Jung
Hello,

You can create a new validator where domains are validate and insert it as
second validator.

Regards

Sencer Hamarat  schrieb am Di., 14. Juni 2022,
15:16:

> Hi,
>
> Say, I have an email field in a model and need to add an email validator
> for email domain validation.
> For this, allowlist property needs to be append to email validator like:
>
> email = models.EmailField(
> validators=[
> EmailValidator(allowlist=['example1.com', 'example2.com',...])
> ]
> )
>
> Can I dynamically fetch domains from another model and assign to allowlist?
> "allowlist" must be altered instantly if related domain list model records
> are changed.
>
> Regards,
> Sencer HAMARAT
>
> --
> 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/CACp8TZgUP9PFB4Rgbhc2sPBvUZ56fy-HFB5AuAxCs8bejo-ahQ%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/CAKGT9mzdV9urxOA-vsYSmMbHT6BBPSSnKZCGPAG%3DEwOj47dw7A%40mail.gmail.com.


Re: How to hash fields and detect changes in a record

2022-06-14 Thread Ryan Nowakowski

On 6/12/22 11:40 PM, Mike Dewhirst wrote:


 Original message 
From: Ryan Nowakowski 
Date: 13/6/22 07:09 (GMT+10:00)
To: django-users@googlegroups.com
Subject: Re: How to hash fields and detect changes in a record

On Sat, Jun 11, 2022 at 12:13:16AM +1000, Mike Dewhirst wrote:
> On 10/06/2022 11:24 pm, Ryan Nowakowski wrote:
> > On Fri, Jun 10, 2022 at 05:52:48PM +1000, Mike Dewhirst wrote:
> > > I think the solution might be to hash note.title and note.note 
into a new
> > > field note.hash on being auto-created. On subsequent saves, 
compare the
> > > latest hash with note.hash to decide whether to delete 
auto-inserted notes
> > > prior to generating the next set. Those subsequent saves could 
be months or

> > > years later.
> > Hashing is useful if you want to check that something has been
> > unexpectedly changed.  I assume the note can only be changed through
> > your web app so you know when a user is changing a note.
>
> These are automatically generated notes which taken together constitute
> advice on how to deal with the analysis. Users can edit them. For 
example,
> someone might record some action taken regarding the advice. I don't 
want to

> delete that. If nothing has been edited, it is safe to delete.
>
> So how do I know it is the same as when originally generated - and 
safe to

> delete - except by storing a hash of the interesting fields.

Because when the user edits a note, during the form.save()(assuming
you're using Django forms), you'll set `altered_by_user` to True.

Notes can also be altered in the Admin



You have a couple of choices then.  You could alter the note details 
view in the admin to set the altered_by_user field. Alternatively and 
more generically, you could check the pk field in your model save 
method.  If it is None, then you are creating a new note.  If the pk 
field is not None, then you are updating an existing note so you can set 
altered_by_user to True.



> And if that is the best approach, what sort of hashing will survive 
Python

> upgrades etc?

Pick a hash algorithm[1](ex: sha256).  The output will remain the same
even with Python upgrades.

So the mechanism doesn't need to be a hash - as you said.I now just 
sum ord(char) for the title and the note and keep that in a flag field.


Summing the ordinal of the characters won't catch transposition:


chars = 'ab'
sum([ord(c) for c in chars])

195

chars = 'ba'
sum([ord(c) for c in chars])

195

Better to use a real hash algorithm if you're trying to detect changes.  
My note above about hashing not being required is because you don't need 
to detect changes because you explicitly already know when changes are 
being made.


--
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/a0d61798-d885-dffd-bfbb-b23a63fbd820%40fattuba.com.


Does django supports dynamic allowlist in EmailValidator

2022-06-14 Thread Sencer Hamarat
Hi,

Say, I have an email field in a model and need to add an email validator
for email domain validation.
For this, allowlist property needs to be append to email validator like:

email = models.EmailField(
validators=[
EmailValidator(allowlist=['example1.com', 'example2.com',...])
]
)

Can I dynamically fetch domains from another model and assign to allowlist?
"allowlist" must be altered instantly if related domain list model records
are changed.

Regards,
Sencer HAMARAT

-- 
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/CACp8TZgUP9PFB4Rgbhc2sPBvUZ56fy-HFB5AuAxCs8bejo-ahQ%40mail.gmail.com.


Re: python instagram bot to upload posts

2022-06-14 Thread 'Kasper Laudrup' via Django users

On 14/06/2022 08.06, Abhinandan K wrote:
hello every one i'm trying to create a python instagram bot to upload 
posts..




That's great but how is this related to Django?

Maybe you should consider finding another place for all your questions 
as none of them really fit here.


Before doing that I would also strongly recommend reading something like 
this:


https://www.propublica.org/nerds/how-to-ask-programming-questions

Kind regards,

Kasper Laudrup

--
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/76cfacd6-da78-f5e6-f55e-fee7ecd895aa%40stacktrace.dk.


Re: I can't use accented letters in my model

2022-06-14 Thread Antonis Christofides
Exactly. The important thing to remember here is that, in Python 2, a "string" 
is actually a list of bytes, whereas a "unicode string" is actually a list of 
characters (not a list of unicode characters—just a list of characters). The 
confusion arises because, when Python was created, i.e. in 1990, multi-byte 
characters were in their infancy, and we mostly assumed that a character and a 
byte was more or less the same thing.


In Python 3, the Python 2 "strings" were renamed to "bytes", and the Python 2 
"unicode strings" were renamed to "strings"—and the syntax for the literals of 
these types also changed. This made it way better.


More information about all this is in 
https://djangodeployment.com/2017/06/19/encodings-part-1/.




On 12/06/2022 12.07, Virgilio Ravagli wrote:

I found a way: book.title = titolo.decode('unicode_escape')
it works fine

Il giorno venerdì 10 giugno 2022 alle 21:45:46 UTC+2 Virgilio Ravagli ha 
scritto:

Thank you, Antonis, it works !
book.title = u'Verità' doesn't give any errors.

Just another step: suppose that the title with accented letters stays in a
variable, say titolo, and I want to write
book.title = titolo. It gives error. How can I do, when the assignment on
the right is not a constant ?
Thanks in advance

Il giorno venerdì 10 giugno 2022 alle 15:25:51 UTC+2 Antonis Christofides
ha scritto:

Hello,

try this:

book.title = u'Verità'

Regards,

Antonis

P.S. Sorry I was a bit harsh yesterday—I had drunk too much beer :-)


On 10/06/2022 10.50, Virgilio Ravagli wrote:

I have surround book.save with a try...catch...; the exception is:
You must not use 8-bit bytestrings unless you use a text_factory that
can interpret 8-bit bytestrings (like text_factory = str). It is
highly recommended that you instead just switch your application to
Unicode strings.
Without the try...catch, here is the traceback:
Environment:


Request Method: POST
Request URL: http://localhost:8000/uti/dataLoading/

Django Version: 1.8.5
Python Version: 2.7.10
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'uti')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware')


Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in
get_response
  132.                     response = wrapped_callback(request,
*callback_args, **callback_kwargs)
File
"C:\Users\RavagliV\eclipse-workspace-saved\librarian\uti\views.py" in
datLoading
  34.                 msg = do_dat_loading()
File
"C:\Users\RavagliV\eclipse-workspace-saved\librarian\uti\views.py" in
do_dat_loading
  79.             book.save()
File "C:\Python27\lib\site-packages\django\db\models\base.py" in save
  734.  force_update=force_update, update_fields=update_fields)
File "C:\Python27\lib\site-packages\django\db\models\base.py" in
save_base
  762.             updated = self._save_table(raw, cls, force_insert,
force_update, using, update_fields)
File "C:\Python27\lib\site-packages\django\db\models\base.py" in
_save_table
  827. forced_update)
File "C:\Python27\lib\site-packages\django\db\models\base.py" in
_do_update
  877.         return filtered._update(values) > 0
File "C:\Python27\lib\site-packages\django\db\models\query.py" in 
_update
  580.         return query.get_compiler(self.db).execute_sql(CURSOR)
File "C:\Python27\lib\site-packages\django\db\models\sql\compiler.py"
in execute_sql
  1062.         cursor = super(SQLUpdateCompiler,
self).execute_sql(result_type)
File "C:\Python27\lib\site-packages\django\db\models\sql\compiler.py"
in execute_sql
  840.             cursor.execute(sql, params)
File "C:\Python27\lib\site-packages\django\db\backends\utils.py" in
execute
  79.             return super(CursorDebugWrapper, self).execute(sql,
params)
File "C:\Python27\lib\site-packages\django\db\backends\utils.py" in
execute
  64.                 re