Re: htmx progress indicator problem - might be caching

2023-12-01 Thread Mike Dewhirst

On 2/12/2023 12:19 am, Thomas Couch wrote:

Can I just check I understand the broader requirements here:

* The user completes the form, which includes a list of items, and 
clicks submit
* For each item in the list you want Django to create a new object and 
save it to the database
* It tends to be a very long list and/or each item takes a long time 
to process
* The user should see a progress bar while the server is working its 
way through the list
* When all items have been processed the progress bar should be 
replaced with a done message


If that's the case


Yes it is.



I think you should think about using Celery


I looked at the docs for Celery and hesitate to add so much technology 
just to kick off a progress bar, or actually now a spinner will 
temporarily suffice as mentioned earlier.


It is why I looked at htmx.

I'm now thinking/wondering if a htmx timed execution - say every one or 
two seconds - might call a view which monitors a singleton being updated 
by the main view kicked off by the form's submit button.


What pushes me in that direction is that a singleton could be updated 
with number processed which would be needed if it ever gets to become a 
progress bar.


I think Celery might be overkill until needed for scaling up.

I do accept that Celery is the obvious solution and used everywhere. I 
just need to exhaust potentially simpler methods.


Many thanks Thomas for persisting.

Cheers

Mike

to create tasks for each item. That'll allow your initial htmx post to 
return without being blocked. The htmx endpoint for the progress bar 
can then check completed count for the task group.


On Thursday, November 30, 2023 at 3:42:39 AM UTC Mike Dewhirst wrote:

On 29/11/2023 9:56 pm, Thomas Couch wrote:

Not sure if it's related, but you've got a div inside a p element
there:


That'll probably get corrected by the browser to:
  


It all seems OK to my untrained eye and things stop working if I
play with those elements. I'll take them out later and resort to
css for positioning once it is all working. I didn't know div
inside a p was wrong.






Another thing is, it doesn't look like there's anything linking
the submit button click to the initial htmx


You are right. That button is in an unbound Django forms.Form and
submit triggers the database processing - which is all working
fine returning correct results.

As an enhancement I tried to detect something else to trigger htmx
for a progress indicator.




request, and there's no htmx in the response.


The response is either a downloaded .csv file or a table of comma
separated values for the user to copy and paste into a spreadsheet
- depending on whether the input was pasted into a text field or
uploaded as a file (list or csv).

Sadly, the response doesn't return until the processing is
complete. So it cannot kick off a progress bar.

Perhaps I need to embark on the async ship? That's a strange land
for me.



Have you tried replicating the progress bar example?
https://htmx.org/examples/progress-bar/


I looked at that and felt it was too heavily contrived generating
time increments to expand the bar across the page. It didn't seem
the right place to start.

If I was going to use it (and I would/will) I first need to obtain
progress numbers based on my incrementing count as records are
created in the database. I can easily put them into the user
instance. That works well within the main view called by the
submit button as indicated by print statements as it loops.

I cannot find a way to get the incrementing number across into the
htmx view even though it is the same user in the hx-request - as
indicated by a print statement.

In breaking news, I have tried to get a spinner going to amuse the
user while database records are being created. Not properly
successful. It does start spinning if I click the submit button a
second time but that is less than satisfactory. I have to
experiment after studying the htmx docs some more.

Here is the current form html ... you can see if there IS a
result, the waiting is over and I use htmx to stop the spinner.



    {% csrf_token %}

    {% if form.non_field_errors %}

    {{ form.non_field_errors }}

    {% endif %}

    

    

    {% for field in form %}

    

     

    {{ field }}

    

    {% if field.help_text %}

    

    {{ field.help_text }}

    

    {% endif %}

    {% endfor %}

    

     

    

    {% if not result %}

  

  

  

    

  

    

  

  

    {% else %}

   

  

  

 

Re: bonjour tout le monde Je suis confronte a cette erreur depuis 2 jours....besoins d'aide svp

2023-12-01 Thread Dawda Borje Kujabi
Eh bien, je ne parle pas français, donc je fais appel à un traducteur. Cela 
est dû au fait que vous n’aviez pas de fichier html de modèle dans votre 
chemin 

On Sunday, November 26, 2023 at 2:50:37 PM UTC fabrice ayissi awono wrote:

> [image: Capture d’écran du 2023-11-26 12-54-34.png]
>

-- 
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/01769d97-34fb-4eb6-8fd9-1f0ae883b4c5n%40googlegroups.com.


Re: databases

2023-12-01 Thread Dawda Borje Kujabi
Well you can depending on your databases, what kinda dtatbase do you have? 

On Friday, December 1, 2023 at 2:23:00 PM UTC Karim Dahman wrote:

> Hi,
> how can create python script in terminal to update the data from old 
> databases into new databases automaticaly
>

-- 
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/b5e7f2b1-538d-48a5-a6f2-10ec575d0f31n%40googlegroups.com.


Re: databases

2023-12-01 Thread Dawda Borje Kujabi
Well yes you can dependong on your databases. What kind of databases do you 
have? 

On Friday, December 1, 2023 at 2:43:20 PM UTC Madhusudhan Reddy wrote:

> Bro please explain the scenario and the problem. 
> Nobody will not give proper answer until you proper details.
>
> On Fri, 1 Dec 2023 at 7:52 PM, Karim Dahman  wrote:
>
>> Hi,
>> how can create python script in terminal to update the data from old 
>> databases into new databases automaticaly
>>
>> -- 
>> 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 view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/be7efd5c-c157-4ee1-b9dc-39533eb66414n%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/03b2a2e6-628e-44eb-ba94-be8583f8fd35n%40googlegroups.com.


Re: databases

2023-12-01 Thread Madhusudhan Reddy
Bro please explain the scenario and the problem.
Nobody will not give proper answer until you proper details.

On Fri, 1 Dec 2023 at 7:52 PM, Karim Dahman 
wrote:

> Hi,
> how can create python script in terminal to update the data from old
> databases into new databases automaticaly
>
> --
> 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/be7efd5c-c157-4ee1-b9dc-39533eb66414n%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/CAFwQctJPA%3DZx7BJgd9knXhcU1E%2B9sg-tKL%2BXLtjp-Ym67hKuWg%40mail.gmail.com.


databases

2023-12-01 Thread Karim Dahman
Hi,
how can create python script in terminal to update the data from old 
databases into new databases automaticaly

-- 
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/be7efd5c-c157-4ee1-b9dc-39533eb66414n%40googlegroups.com.


Re: Project together

2023-12-01 Thread Aubdur rob Anik
I'm interested. Add me please.
Phone(WhatsApp): +8801685946475

On Friday, 1 December 2023 at 00:30:44 UTC+6 Talha Malik wrote:

> I'm interested, add me too +923098109886 <+92%20309%208109886>
>
> On Mon, 27 Nov 2023, 9:20 pm Aminu Auwal,  wrote:
>
>> I am interested add me +2438062282242
>>
>> On Mon, Nov 27, 2023 at 4:10 PM okot emmanuel  
>> wrote:
>>
>>> add me +256779815657 <+256%20779%20815657>
>>>
>>>
>>>
>>> On Mon, Nov 27, 2023 at 12:48 AM usman ashir  
>>> wrote:
>>>
 yes pls send us the group link. or pls 2348166997172.add my contact 

 On Sun, Nov 26, 2023, 9:38 PM Jay Senkow  wrote:

> interested.
>
> Sent from my iPhone
>
> On Nov 26, 2023, at 2:46 PM, ekong, emmanuel  
> wrote:
>
> 
> I am interested
>
> Phone ( WhatsApp): +234-8071-505-514
>
> On Thu, 23 Nov 2023 at 7:13 PM, Youssef Bachraoui <
> bachraou...@gmail.com> wrote:
>
>> Hi developer i search to make a group on WhatsApp to begin a project 
>> together anyone interested about that?
>>
>> -- 
>> 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 view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/d5244e76-6bd3-4bde-bf31-a72720bee1acn%40googlegroups.com
>>  
>> 
>> .
>>
>
> *Disclaimer*
> This e-mail is intended solely for the named recipient. The 
> information contained in this message is strictly confidential. 
>
>- If you are not the named recipient, you are hereby notified that 
>any use, dissemination or reproduction of this document and or its 
> content 
>is prohibited and may be deemed unlawful.
>- If you are not the named recipient of this e-mail, please notify 
>the sender by a return e-mail and delete all copies of it from your 
>computer and mail.
>
> Any views expressed in this e-mail are those of the individual sender, 
> except where the sender specifically states them to be those of Landmark 
> University , to whom no liability shall be 
> attached whatsoever.
>
> Thank you 
>
> -- 
> 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/CAAP9wczbDL6n7qW5WARHwGsR8hbVgwV0K%3DdTGJoBqE3aQc4TWA%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...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/ACC804A9-5EF3-4D3A-B11A-6AE171113174%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...@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/django-users/CAHNdQhwinzLUgaUvQNfYOnxbXhtk4shxcSn5zz00Kceiz7Zb%2Bw%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...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/CAHoGtOznPiHRbXdKqJiGQEUgF0i613_%2Bd3ejk%3Dx17EaOXmM%3DUA%40mail.gmail.com
>>>  
>>> 
>>> .
>>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this gr

Re: htmx progress indicator problem - might be caching

2023-12-01 Thread Thomas Couch
Can I just check I understand the broader requirements here:

* The user completes the form, which includes a list of items, and clicks 
submit
* For each item in the list you want Django to create a new object and save 
it to the database
* It tends to be a very long list and/or each item takes a long time to 
process
* The user should see a progress bar while the server is working its way 
through the list
* When all items have been processed the progress bar should be replaced 
with a done message

If that's the case I think you should think about using Celery to create 
tasks for each item. That'll allow your initial htmx post to return without 
being blocked. The htmx endpoint for the progress bar can then check 
completed count for the task group.

On Thursday, November 30, 2023 at 3:42:39 AM UTC Mike Dewhirst wrote:

> On 29/11/2023 9:56 pm, Thomas Couch wrote:
>
> Not sure if it's related, but you've got a div inside a p element there:
> 
>
> That'll probably get corrected by the browser to:
>   
> 
>
>
> It all seems OK to my untrained eye and things stop working if I play with 
> those elements. I'll take them out later and resort to css for positioning 
> once it is all working. I didn't know div inside a p was wrong.
>
>
>
>
>
> Another thing is, it doesn't look like there's anything linking the submit 
> button click to the initial htmx 
>
>
> You are right. That button is in an unbound Django forms.Form and submit 
> triggers the database processing - which is all working fine returning 
> correct results. 
>
> As an enhancement I tried to detect something else to trigger htmx for a 
> progress indicator.
>
>
>
> request, and there's no htmx in the response. 
>
>
> The response is either a downloaded .csv file or a table of comma 
> separated values for the user to copy and paste into a spreadsheet - 
> depending on whether the input was pasted into a text field or uploaded as 
> a file (list or csv). 
>
> Sadly, the response doesn't return until the processing is complete. So it 
> cannot kick off a progress bar.
>
> Perhaps I need to embark on the async ship? That's a strange land for me.
>
>
> Have you tried replicating the progress bar example?
> https://htmx.org/examples/progress-bar/
>
>
> I looked at that and felt it was too heavily contrived generating time 
> increments to expand the bar across the page. It didn't seem the right 
> place to start.
>
> If I was going to use it (and I would/will) I first need to obtain 
> progress numbers based on my incrementing count as records are created in 
> the database. I can easily put them into the user instance. That works well 
> within the main view called by the submit button as indicated by print 
> statements as it loops.
>
> I cannot find a way to get the incrementing number across into the htmx 
> view even though it is the same user in the hx-request - as indicated by a 
> print statement.
>
> In breaking news, I have tried to get a spinner going to amuse the user 
> while database records are being created. Not properly successful. It does 
> start spinning if I click the submit button a second time but that is less 
> than satisfactory. I have to experiment after studying the htmx docs some 
> more.
>
> Here is the current form html ... you can see if there IS a result, the 
> waiting is over and I use htmx to stop the spinner. 
>
> 
>
> {% csrf_token %}
>
> {% if form.non_field_errors %}
>
> {{ form.non_field_errors }}
>
> {% endif %}
>
> 
>
> 
>
> {% for field in form %}
>
> 
>
>  
>
> {{ field }}
>
> 
>
> {% if field.help_text %}
>
> 
>
> {{ field.help_text }}
>
> 
>
> {% endif %}
>
> {% endfor %}
>
> 
>
>  
>
> 
>
> {% if not result %}
>
>   
>
>   
>
>   
>
>  hx-trigger="click">
>
>   
>
> 
>
>   
>
>   
>
> {% else %}
>
>    
>
>   
>
>   
>
>  hx-trigger="every 1s">
>
>    
>
>   
>
>   
>
> {% endif %}
>
> 
>
> 
>
> 
>
> 
>
> 
>
> 
>
> 
>
> {{ result }}
>
> 
>
>
> So I have two problems: One is getting the numbers to animate a progress 
> bar and two is triggering htmx in parallel with the submit button click.
>
> Many thanks for taking an interest.
>
> Cheers
>
> Mike
>
>
>
> On Tuesday, November 28, 2023 at 2:26:20 AM UTC Mike Dewhirst wrote:
>
>> I'm trying but failing to get htmx to deliver a progress indication.
>>
>> The task is creating records in the database for each item in a list 
>> provided by the logged in user.
>>
>> The view with the submit button collects the list and does the database 
>> insertion. I added a "progress" property to the User model as follows ...
>>
>> class User(AbstractUser):
>>
>> def __init__(self, *args, **kwargs):
>>
>> super().__init__(*a

I Want To Create An Api of notification In Django Rest API

2023-12-01 Thread Hamza Bilal
I Want To Create An Api of notification In Django Rest API
![Screenshot from 2023-11-30 
03-30-39|690x388](upload://6RwAUFNKt3TWKgrocOu2t4k2TeJ.png)
I Created AN Notification App By Using The Django Channels, Websockt and 
Successfully Sending Notification To The `Webscoketking.com`, Now I Want To 
Create The API of This App For Sending The Notifications Of the Website
models.py
```
from django.db import models
from django.contrib.auth.models import AbstractUser
from channels.layers import get_channel_layer
from asgiref.sync import async_to_sync
import json
# Create your models here.

class CustomUser(AbstractUser):

"""Model class for users"""

USER_CHOICES = [
('expert', 'Expert'),
('business', 'Business'),
('admin', 'Admin'),
]

username = models.CharField(max_length=40, null=True, blank=True)
full_name = models.CharField(max_length=40)
email = models.EmailField(unique=True)
password = models.CharField(max_length=40, null=False, blank=False)
confirm_password = models.CharField(max_length=40, null=False, 
blank=False)
user_choices = models.CharField(max_length=30, choices=USER_CHOICES, 
default='expert')

USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['username']

def __str__(self) -> str:
return f"{self.email}"


class Notification(models.Model):
account_user = models.ForeignKey(CustomUser, on_delete=models.CASCADE)
message = models.TextField()
is_read = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True)

def save(self, *args, **kwargs):
print('saving notification')
channel_layer = get_channel_layer()
notification_objs = 
Notification.objects.filter(is_read=False).count()
data = {'count': notification_objs, 'current_notification': 
self.message}
async_to_sync(channel_layer.group_send)(
"test_group", {
"type": "send_notification",
"value": json.dumps(data)
}
)
super(Notification, self).save(*args, **kwargs)


class AccountApproval(models.Model):
account_user = models.ForeignKey(CustomUser, on_delete=models.CASCADE)
approved = models.BooleanField(default=False)
approval_message = models.TextField(blank=True, null=True)

```
COnsumers.py
```
from channels.generic.websocket import WebsocketConsumer
from asgiref.sync import async_to_sync
import json

class TestConsumer(WebsocketConsumer):
def connect(self):
self.room_name = "test"
self.room_group_name = "test_group"
async_to_sync(self.channel_layer.group_add)(
self.room_group_name,
self.channel_name,
)
self.accept()
print("connected")
self.send(text_data=json.dumps({'status': 'connected Through Django 
Channels'}))

def receive(self, text_data):
print(text_data)
self.send(text_data=json.dumps({'status': 'We Got You'}))

def disconneted(self, *args, **kwargs):
print("disconnected")

def send_notification(self, event):
print('Send Notification: ')
data = json.loads(event.get('value'))
self.send(text_data=json.dumps({'status': data}))

print('Send Notification: ')



```
asgi.py
```
"""
ASGI config for hamza project.

It exposes the ASGI callable as a module-level variable named 
``application``.

For more information on this file, see
https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/
"""
from channels.routing import ProtocolTypeRouter, URLRouter
from django.urls import path
from bilal.consumers import TestConsumer
import os
from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'hamza.settings')

asgiapplication = get_asgi_application()

ws_pattern = [
path('ws/test/', TestConsumer.as_asgi())
]

application = ProtocolTypeRouter({
'http': get_asgi_application(),
'websocket': URLRouter(ws_pattern)
})
```

-- 
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/6e2c0bdf-b67f-4167-9236-ac310f1a4a52n%40googlegroups.com.