v1k45 / django-notify-x

Notification system for Django
MIT License
187 stars 40 forks source link

django.db.utils.DataError: (1406, "Data too long for column 'verb' at row 1") #47

Open quevon24 opened 6 years ago

quevon24 commented 6 years ago

If you try to set a verb longer than 50 characters drops the error: django.db.utils.DataError: (1406, "Data too long for column 'verb' at row 1")

I suggest to increase the max_length of the verb, or maybe implement a extra validation to trim the text

Also I noticed if the notification box text, if you pass an extra and render it in your box template and then the notification it's added with ajax, it displays fine, but on next ajax call, erases the extra of addef notification in the template.

e.g. I send a notification: notify.send(sender, recipient=recipient, actor=sender, actor_url='http://google.com.mx', verb='commented in here:', nf_type='comment', extra={'order':'ORDER1234'})

and it's rendered with this:

<a href="{{ notification.actor_url }}" data-nf-id="{{ notification.id }}" data-id="{{ notification.id }}" class="mark-notification-mod" target="_blank" data-mark-action="{{ notification.read|yesno:'unread,read' }}">
<div class="notification alert {{ notification.read|yesno:'alert-success,alert-info' }} {{ notification.read|yesno:'read,unread' }} alert-alt">
    <small>Hace {{ notification.created|timesince }}</small>
    <br>
    <strong aria-hidden='true' data-toggle='tooltip' data-original-title='{{ notification.actor }}'>{{ notification.actor.username }}</strong> {{ notification.verb }}&nbsp;<b>{{ notification.extra.order }}</b>
</div>
</a>

And displays like this:

20 minutes ago quevon24 commented in here: ORDER1234

ORDER1234 is the extra, extra={'order':'ORDER1234'}

But when comes the next ajax call to update the list(new or no new notification), now the notificacion it's displayed without the extra, erase the extra of the already added notification, like this:

20 minutes ago quevon24 commented in here:

v1k45 commented 6 years ago

I suggest to increase the max_length of the verb, or maybe implement a extra validation to trim the text

I think we should do both, increase the max_length and have a validation check during sending notifications instead of trimming it.

About the missing extra,

This is probably happening because another template is used to render the notification when using ajax.

See utils.py#12 to know the precedence. By default, the render function will look for <notification_type>_box.html template and then fallback to default. Make sure you have overridden the template.

Feel free to send a pull request for this issue.

quevon24 commented 6 years ago

I think we should do both, increase the max_length and have a validation check during sending notifications instead of trimming it.

About the missing extra,

This is probably happening because another template is used to render the notification when using ajax.

See utils.py#12 to know the precedence. By default, the render function will look for _box.html template and then fallback to default. Make sure you have overridden the template.

Feel free to send a pull request for this issue.

Thanks for your answer, the notifications in my dropdown displays fine with my custom template(I named it mention_box.html) , so I think that is overridden, the problem is that remove the extras of the notifications after an ajax call to get new notifications (keeps my template and my styles but removing the extras)

v1k45 commented 6 years ago

Hmm, that shouldn't be happening. I'll try to reproduce this issue and let you know about it.