Re: How to hash fields and detect changes in a record
--(Unsigned mail from my phone) 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()(assumingyou're using Django forms), you'll set `altered_by_user` to True.Notes can also be altered in the Admin> 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 sameeven 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.Only the auto-notes get a flag because they are the only ones I would consider deleting. [1] https://docs.python.org/3/library/hashlib.html> > Since you're> > expecting users to change some of the notes and you know when they do,> > hashing might be overkill. Instead, add a boolean `altered_by_user`> > field to the note model. Initially when you automatically create the> > note altered_by_user would be set to False. If a user changes the note,> > set altered_by_user to True.>> Not sure this would work. Note creation and eventually automatic deletion is> all driven from model methods executed on saving.Why wouldn't this work? During note creation, altered_by_user would beset to False automatically because that's the default. Whenautomatically deleting, do: Note.objects.filter(altered_by_user=False).delete()-- 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/20220612210931.GA32625%40fattuba.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/62a6c0f0.1c69fb81.c1d5.c26fSMTPIN_ADDED_MISSING%40gmr-mx.google.com.
Re: Need best tutorial
Use this from Telusko https://youtube.com/playlist?list=PLsyeobzWxl7poL9JTVyndKe62ieoN-MZ3 On 13 Jun 2022, 01:36 +0300, 'Kasper Laudrup' via Django users , wrote: > On 12/06/2022 07.54, Ghalib Raja wrote: > > hi there, i am beginner in python. can anyone share python best tutorial > > for web development please > > > > Learn the basics of Python first then focus on web development later. > > If you already have some experience with other languages I found this > freely licensed book quite useful: > > https://diveintopython3.net/ > > If you are a beginner in programming in general, Python is definitely a > good starting language IMO but there might be better resources for > absolute beginners that someone else can share. > > 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/f8ec44cb-d1c5-99fb-ce5e-3cefcda67fa2%40stacktrace.dk. -- 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/70596932-7b69-40a7-b5b7-f1829e3af851%40Spark.
Re: Need best tutorial
On 12/06/2022 07.54, Ghalib Raja wrote: hi there, i am beginner in python. can anyone share python best tutorial for web development please Learn the basics of Python first then focus on web development later. If you already have some experience with other languages I found this freely licensed book quite useful: https://diveintopython3.net/ If you are a beginner in programming in general, Python is definitely a good starting language IMO but there might be better resources for absolute beginners that someone else can share. 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/f8ec44cb-d1c5-99fb-ce5e-3cefcda67fa2%40stacktrace.dk. OpenPGP_0xE5D9CAC64AAA55EB.asc Description: OpenPGP public key OpenPGP_signature Description: OpenPGP digital signature
Re: Using a lazy value in a queryset filter?
On Sun, Jun 12, 2022 at 11:46:44AM -0700, Sylvain wrote: > Hello, > > I’m trying to use the current language of the user in a queryset, but the > value gets resolved outside of the request-response cycle. I thought this > could work since querysets are lazy, but I guess that doesn’t make the > values they use lazy. Here’s an example of what I’m talking about: > > from django.utils.translation import get_language > > class MyManager(models.Manager): > def get_queryset(self): > return super().get_queryset().filter(language=get_language()) > > class MyModel(models.Model): > ... > objects = MyManager() > > Using this in a code path that’s in the request-response cycle works (eg. > in a view), but using it in a form definition doesn’t (I get the default > language instead of the one from the request): > > class MyForm(forms.Form): > option = forms.ModelChoiceField(queryset=MyModel.objects.all()) Can you post how you're using the form? Are you using the form in a view? Can you post the view code? -- 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/20220612211356.GB32625%40fattuba.com.
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. > 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. [1] https://docs.python.org/3/library/hashlib.html > > Since you're > > expecting users to change some of the notes and you know when they do, > > hashing might be overkill. Instead, add a boolean `altered_by_user` > > field to the note model. Initially when you automatically create the > > note altered_by_user would be set to False. If a user changes the note, > > set altered_by_user to True. > > Not sure this would work. Note creation and eventually automatic deletion is > all driven from model methods executed on saving. Why wouldn't this work? During note creation, altered_by_user would be set to False automatically because that's the default. When automatically deleting, do: Note.objects.filter(altered_by_user=False).delete() -- 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/20220612210931.GA32625%40fattuba.com.
Using a lazy value in a queryset filter?
Hello, I’m trying to use the current language of the user in a queryset, but the value gets resolved outside of the request-response cycle. I thought this could work since querysets are lazy, but I guess that doesn’t make the values they use lazy. Here’s an example of what I’m talking about: from django.utils.translation import get_language class MyManager(models.Manager): def get_queryset(self): return super().get_queryset().filter(language=get_language()) class MyModel(models.Model): ... objects = MyManager() Using this in a code path that’s in the request-response cycle works (eg. in a view), but using it in a form definition doesn’t (I get the default language instead of the one from the request): class MyForm(forms.Form): option = forms.ModelChoiceField(queryset=MyModel.objects.all()) Is there a way to get this working without having to move the queryset call to the form __init__? Using django.utils.functional.lazy doesn’t work either because the value needs to be resolved in the filter. Thanks! Sylvain -- 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/99b62ef4-de2c-45c2-9bec-0d5dcfdb6980n%40googlegroups.com.
Need best tutorial
hi there, i am beginner in python. can anyone share python best tutorial for web development please -- 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/e566ca04-5afc-4c9f-8a96-1e452133131fn%40googlegroups.com.
Re: I can't use accented letters in my model
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. return self.cursor.execute(sql, params) >> File "C:\Python27\lib\site-packages\django\db\utils.py" in __exit__ >> 97. six.reraise(dj_exc_type, dj_exc_value, traceback) >> File "C:\Python27\lib\site-packages\django\db\backends\utils.py" in >> execute >> 64. return self.cursor.execute(sql, params) >> File "C:\Python27\lib\site-packages\django\db\backends\sqlite3\base.py" >> in execute >> 318. return Database.Cursor.execute(self, query, params) >> >> Exception Type: ProgrammingError at /uti/dataLoading/ >> Exception Value: 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. >> >> Il giorno giovedì 9 giugno 2022 alle 23:17:16 UTC+2 Antonis Christofides >> ha scritto: >> >>> Please read my email again. >>> >>> Antonis Christofides+30-6979924665 <+30%20697%20992%204665> (mobile) >>> >>> On 09/06/2022 22.27, Virgilio Ravagli wrote: >>> >>> All right. >>> cl