Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def content_post_saved_callback(sender, **kwargs):
- import threading
- if kwargs["created"]:
- class Thrdng(threading.Thread):
- def run (self):
- from core.models import Quser, Notification, Ticket_status, Ticket_status_type
- import settings
- from core.utils import getLanguageCode, getCC
- from django.utils.translation import activate
- from django.utils.translation import ugettext as _
- from django.contrib.sites.models import Site
- from core.templatetags import JS
- kwargs = self.locals["kwargs"]
- sender = self.locals["sender"]
- try:
- #gestituisce la propagazione delle notifiche
- content = kwargs['instance']
- if(type(content).__name__ in ["Qpost", "SegnalazioneToolOdori", "Qalert_zanzare", "Qalert_mosche"]):
- punto = content.point
- if content.visibilityType.name == "Private":
- lista_utenti_notificati = []
- else:
- lista_utenti_notificati = list(Quser.objects \
- .exclude(id = content.userCreatore.id) \
- .exclude(user__is_active = False) \
- .filter(point__distance_lte = (punto, 10000)))
- if content.visibilityType.name == "Custom":
- lista_utenti_notificati = lista_utenti_notificati.filter(user__username__in = content.get_visibility_definition()["users"])
- lista_utenti_notificati.append(Quser.objects.get(user__username = "Qcumber"))
- if settings.URL == "https://www.q-cumber.org/":
- lista_utenti_notificati.append(Quser.objects.get(user__username = "cinzia"))
- lista_utenti_notificati.append(Quser.objects.get(user__username = "Giovanni86"))
- lista_utenti_notificati.append(Quser.objects.get(user__username = "stefyp"))
- default_protocol = getattr(settings, 'DEFAULT_HTTP_PROTOCOL', 'http')
- current_domain = Site.objects.get_current().domain
- site_url = default_protocol + '://' + current_domain
- for Qu in lista_utenti_notificati:
- try:
- langCode = getLanguageCode(Qu)
- activate(langCode)
- mess = None
- if type(content).__name__ == "Qpost":
- if content.isTicket():
- if content.getCurrentTicketStatus() == None:#it's "opened"
- ts = Ticket_status()
- ts.content = content
- ts.status_type = Ticket_status_type.objects.get(codice = "opened")
- ts.changedBy = content.userCreatore
- ts.save()
- mess = {
- "subject": _("New red Qpost near you with notification to institution"),
- "body": _(u'''%(creator_user)s added a new red Qpost near you with the title "%(title)s".
- This Qpost was notified to %(ticket_recipient)s.
- To watch it, to comment on it and to follow the issue evolution visit this link: %(link1)s.
- The current status of the issue is: \"%(status)s\"
- To confirm this report add a new red Qpost in the same point, follow this link: %(link2)s''') % {
- "title": content.titolo,
- "creator_user": content.userCreatore.getAlias(),
- "link1": site_url + "/permalink/Qpost/" + str(content.id) + "/",
- "link2": site_url + "/WorkStation/__oT__/add_Qpost/" + (JS.JS_encodeURI(JS.toJSON({ "type": "rosso", "lng": content.point[0], "lat": content.point[1] }))),
- "ticket_recipient": content.ticket_recipient.getAlias(),
- "status": _("Opened"),
- },
- "body_html": _(u'''<b style="font-size: 11pt;">%(creator_user)s</b> added a new red Qpost near you with the title "<b>%(title)s</b>".<br>
- This Qpost was notified to <b style="font-size: 11pt;">%(ticket_recipient)s</b>.<br>
- To watch it, to comment on it and to follow the issue evolution <a href="%(link1)s" style="color: #082E2C;">Click here</a>.<br>
- <br>
- The current status of the issue is: \"<b style="color: #83BFBC;">%(status)s</b>\"<br>
- <br>
- To confirm this report <a href="%(link2)s" style="color: #082E2C;">add a new red Qpost in the same point</a>''') % {
- "title": content.titolo,
- "creator_user": content.userCreatore.getAlias(),
- "link1": site_url + "/permalink/Qpost/" + str(content.id) + "/",
- "link2": site_url + "/WorkStation/__oT__/add_Qpost/" + (JS.JS_encodeURI(JS.toJSON({ "type": "rosso", "lng": content.point[0], "lat": content.point[1] }))),
- "ticket_recipient": content.ticket_recipient.getAlias(),
- "status": _("Opened"),
- },
- }
- else:
- if content.tipo.codice == "rosso":
- mess = {
- "subject": _("New red Qpost near you"),
- "body": _(u'''%(creator_user)s added a new Qpost near you with the title "%(title)s".
- To watch it and to comment on it follow this link: %(link1)s
- To add a new Red Qpost in the same point follow this link: %(link2)s.''') % {
- "title": content.titolo,
- "creator_user": content.userCreatore.getAlias(),
- "link1": site_url + "/permalink/Qpost/" + str(content.id) + "/",
- "link2": site_url + "/WorkStation/__oT__/add_Qpost/" + (JS.JS_encodeURI(JS.toJSON({ "type": "rosso", "lng": content.point[0], "lat": content.point[1] }))),
- },
- "body_html": _(u'''<b style="font-size: 11pt;">%(creator_user)s</b> added a new Red Qpost near you with the title "<b>%(title)s</b>".<br>
- To watch it and to comment on it <a href="%(link1)s" style="color: #082E2C;">Click here</a><br>
- <br>
- To add a new Red Qpost in the same point <a href="%(link2)s" style="color: #082E2C;">Click here</a>.''') % {
- "title": content.titolo,
- "creator_user": content.userCreatore.getAlias(),
- "link1": site_url + "/permalink/Qpost/" + str(content.id) + "/",
- "link2": site_url + "/WorkStation/__oT__/add_Qpost/" + (JS.JS_encodeURI(JS.toJSON({ "type": "rosso", "lng": content.point[0], "lat": content.point[1] }))),
- },
- }
- elif content.tipo.codice == "verde":
- mess = {
- "subject": _("New green Qpost near you"),
- "body": _(u'''%(creator_user)s added a new Qpost near you with the title "%(title)s".
- To watch it and to comment on it follow this link: %(link1)s.
- To add a new Green Qpost in the same point follow this link: %(link2)s.''') % {
- "title": content.titolo,
- "creator_user": content.userCreatore.getAlias(),
- "link1": site_url + "/permalink/Qpost/" + str(content.id) + "/",
- "link2": site_url + "/WorkStation/__oT__/add_Qpost/" + (JS.JS_encodeURI(JS.toJSON({ "type": "verde", "lng": content.point[0], "lat": content.point[1] }))),
- },
- "body_html": _(u'''<b style="font-size: 11pt;">%(creator_user)s</b> added a new Green Qpost near you with the title "<b>%(title)s</b>".<br>
- To watch it and to comment on it <a href="%(link1)s" style="color: #082E2C;">Click here</a>.<br>
- <br>
- To add a new Green Qpost in the same point <a href="%(link2)s" style="color: #082E2C;">Click here</a>.''') % {
- "title": content.titolo,
- "creator_user": content.userCreatore.getAlias(),
- "link1": site_url + "/permalink/Qpost/" + str(content.id) + "/",
- "link2": site_url + "/WorkStation/__oT__/add_Qpost/" + (JS.JS_encodeURI(JS.toJSON({ "type": "verde", "lng": content.point[0], "lat": content.point[1] }))),
- },
- }
- elif content.tipo.codice == "grigio":
- mess = {
- "subject": _("New grey Qpost near you"),
- "body": _(u'''%(creator_user)s added a new Qpost near you with the title "%(title)s".
- To watch it and to comment on it follow this link: %(link1)s.
- To add a new Grey Qpost in the same point follow this link: %(link2)s.''') % {
- "title": content.titolo,
- "creator_user": content.userCreatore.getAlias(),
- "link1": site_url + "/permalink/Qpost/" + str(content.id) + "/",
- "link2": site_url + "/WorkStation/__oT__/add_Qpost/" + (JS.JS_encodeURI(JS.toJSON({ "type": "grigio", "lng": content.point[0], "lat": content.point[1] }))),
- },
- "body_html": _(u'''<b style="font-size: 11pt;">%(creator_user)s</b> added a new Grey Qpost near you with the title "<b>%(title)s</b>".<br>
- To watch it and to comment on it <a href="%(link1)s" style="color: #082E2C;">Click here</a>.<br>
- <br>
- To add a new Grey Qpost in the same point <a href="%(link2)s" style="color: #082E2C;">Click here</a>.''') % {
- "title": content.titolo,
- "creator_user": content.userCreatore.getAlias(),
- "link1": site_url + "/permalink/Qpost/" + str(content.id) + "/",
- "link2": site_url + "/WorkStation/__oT__/add_Qpost/" + (JS.JS_encodeURI(JS.toJSON({ "type": "grigio", "lng": content.point[0], "lat": content.point[1] }))),
- },
- }
- elif content.tipo.codice == "giallo":
- mess = {
- "subject": _("New yellow Qpost near you"),
- "body": _(u'''%(creator_user)s added a new Qpost near you with the title "%(title)s".
- To watch it and to comment on it follow this link: %(link1)s.
- To add a new Yellow Qpost in the same point follow this link: %(link2)s.''') % {
- "title": content.titolo,
- "creator_user": content.userCreatore.getAlias(),
- "link1": site_url + "/permalink/Qpost/" + str(content.id) + "/",
- "link2": site_url + "/WorkStation/__oT__/add_Qpost/" + (JS.JS_encodeURI(JS.toJSON({ "type": "giallo", "lng": content.point[0], "lat": content.point[1] }))),
- },
- "body_html": _(u'''<b style="font-size: 11pt;">%(creator_user)s</b> added a new Yellow Qpost near you with the title "<b>%(title)s</b>".<br>
- To watch it and to comment on it <a href="%(link1)s" style="color: #082E2C;">Click here</a>.<br>
- <br>
- To add a new Yellow Qpost in the same point <a href="%(link2)s" style="color: #082E2C;">Click here</a>.''') % {
- "title": content.titolo,
- "creator_user": content.userCreatore.getAlias(),
- "link1": site_url + "/permalink/Qpost/" + str(content.id) + "/",
- "link2": site_url + "/WorkStation/__oT__/add_Qpost/" + (JS.JS_encodeURI(JS.toJSON({ "type": "giallo", "lng": content.point[0], "lat": content.point[1] }))),
- },
- }
- elif type(content).__name__ == "Qalert_zanzare":
- mess = {
- "subject": _("New Mosquitoes Qalert near you"),
- "body": _(u'''%(creator_user)s added a new Mosquitoes Qalert near you: amount "%(amount)s".
- To watch it follow this link: %(link1)s''') % {
- "creator_user": content.userCreatore.getAlias(),
- "amount": unicode(content.quantita),
- "link1": site_url + "/WorkStation/__rgT__/WS/vediContenuto/Qalert_zanzare/" + str(content.id) + "/",
- },
- "body_html": _(u'''<b style="font-size: 11pt;">%(creator_user)s</b> added a new Mosquitoes Qalert near you: amount "<b>%(amount)s</b>".<br>
- To watch it <a href="%(link1)s" style="color: #082E2C;">Click here</a>.''') % {
- "creator_user": content.userCreatore.getAlias(),
- "amount": unicode(content.quantita),
- "link1": site_url + "/WorkStation/__rgT__/WS/vediContenuto/Qalert_zanzare/" + str(content.id) + "/",
- },
- }
- elif type(content).__name__ == "Qalert_mosche":
- mess = {
- "subject": _("New Flies Qalert near you"),
- "body": _(u'''%(creator_user)s added a new Flies Qalert near you: amount "%(amount)s".<br>
- To watch it follow this link: %(link1)s''') % {
- "creator_user": content.userCreatore.getAlias(),
- "amount": unicode(content.quantita),
- "link1": site_url + "/WorkStation/__rgT__/WS/vediContenuto/Qalert_mosche/" + str(content.id) + "/",
- },
- "body_html": _(u'''<b style="font-size: 11pt;">%(creator_user)s</b> added a new Flies Qalert near you: amount "<b>%(amount)s</b>".<br>
- To watch it <a href="%(link1)s" style="color: #082E2C;">Click here</a>.''') % {
- "creator_user": content.userCreatore.getAlias(),
- "amount": unicode(content.quantita),
- "link1": site_url + "/WorkStation/__rgT__/WS/vediContenuto/Qalert_mosche/" + str(content.id) + "/",
- },
- }
- elif type(content).__name__ == "SegnalazioneToolOdori":
- mess = {
- "subject": _("New Odour Qalert near you"),
- "body": _(u'''%(creator_user)s added a new Odour Qalert near you: estimation "%(estimation)s".
- To watch it follow this link: %(link1)s
- If you sense smell also in your area follow this link: %(link2)s''') % {
- "creator_user": content.userCreatore.getAlias(),
- "estimation": unicode(content),
- "link1": site_url + "/permalink/QalertOdor/" + str(content.id) + "/",
- "link2": site_url + "/WorkStation/__oT__/add_Qalert/",
- },
- "body_html": _(u'''<b style="font-size: 11pt;">%(creator_user)s</b> added a new Odour Qalert near you: estimation "<b>%(estimation)s</b>".<br>
- To watch it <a href="%(link1)s" style="color: #082E2C;">Click here</a>.<br>
- <br>
- If you sense smell also in your area <a href="%(link2)s" style="color: #082E2C;">Click here</a>.''') % {
- "creator_user": content.userCreatore.getAlias(),
- "estimation": unicode(content),
- "link1": site_url + "/permalink/QalertOdor/" + str(content.id) + "/",
- "link2": site_url + "/WorkStation/__oT__/add_Qalert/",
- },
- }
- if mess:
- n = Notification.create(
- type_name_code = "newContent",
- QuserNotified = Qu,
- metaOpts = {
- "content": {
- "class": type(content).__name__,
- "cc": getCC(content),
- "id": content.id,
- },
- "message": mess,
- }
- )
- except:
- import traceback, time
- logs = open(settings.BASE_PATH + "/var/log/email_sending.txt", "a")
- logs.write('-'*60 + "\n")
- logs.write(time.asctime() + "\n\n")
- traceback.print_exc(limit=3, file=logs)
- logs.write('-'*60 + "\n")
- logs.close()
- except:
- #raise
- pass
- thrdng = Thrdng()
- thrdng.locals = locals()
- thrdng.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement