Просмотр исходного кода

dialog.js: if fieldname is not given it taken from label

version-14
Rushabh Mehta 13 лет назад
Родитель
Сommit
39e38a0c8a
5 измененных файлов: 32 добавлений и 11 удалений
  1. +3
    -0
      js/wn/ui/dialog.js
  2. +4
    -1
      py/webnotes/__init__.py
  3. +6
    -0
      py/webnotes/tests/test_email.py
  4. +17
    -9
      py/webnotes/utils/email_lib/bulk.py
  5. +2
    -1
      py/webnotes/utils/email_lib/smtp.py

+ 3
- 0
js/wn/ui/dialog.js Просмотреть файл

@@ -35,6 +35,9 @@ wn.widgets.FieldGroup = function() {
this.fields_dict = {}; // reset
for(var i=0; i<fl.length; i++) {
var df = fl[i];
if(!df.fieldname && df.label) {
df.fieldname = df.label.replace(/ /g, '_').toLowerCase();
}
var div = $a(body, 'div', '', {margin:'6px 0px'})
f = make_field(df, null, div, null);
f.not_in_form = 1;


+ 4
- 1
py/webnotes/__init__.py Просмотреть файл

@@ -98,7 +98,10 @@ def msgprint(msg, small=0, raise_exception=0, as_table=False):
message_log.append((small and '__small:' or '')+cstr(msg or ''))
if raise_exception:
raise ValidationError, msg
if issubclass(raise_exception, Exception):
raise raise_exception, msg
else:
raise ValidationError, msg

def get_index_path():
import os


+ 6
- 0
py/webnotes/tests/test_email.py Просмотреть файл

@@ -58,6 +58,12 @@ class TestEmail(unittest.TestCase):
self.assertFalse('rmehta@gmail.com' in [d['recipient'] for d in bulk])
self.assertTrue('rushabh@erpnext.com' in [d['recipient'] for d in bulk])
self.assertTrue('Unsubscribe' in bulk[0]['message'])
def test_bulk_limit(self):
from webnotes.utils.email_lib.bulk import unsubscribe, send, BulkLimitCrossedError
self.assertRaises(BulkLimitCrossedError, send, recipients=['rmehta@gmail.com']*1000,
doctype='Lead', email_field='email_id', first_name_field='lead_name',
last_name_field=None, subject='Testing Bulk', message='This is a bulk mail!')
if __name__=='__main__':


+ 17
- 9
py/webnotes/utils/email_lib/bulk.py Просмотреть файл

@@ -22,6 +22,8 @@

import webnotes

class BulkLimitCrossedError(webnotes.ValidationError): pass

def send(recipients=[], doctype='Profile', email_field='email', first_name_field="first_name",
last_name_field="last_name", subject='[No Subject]', message='[No Content]'):
"""send bulk mail if not unsubscribed and within conf.bulk_mail_limit"""
@@ -31,18 +33,24 @@ def send(recipients=[], doctype='Profile', email_field='email', first_name_field
return rdata[0]['unsubscribed']

def check_bulk_limit(new_mails):
import conf
import conf, startup
from webnotes.utils import nowdate
todays_bulk = webnotes.conn.sql("""select count(*) from `tabBulk Email` where
datediff(%s, creation)<1""" % nowdate())[0][0]
this_month = webnotes.conn.sql("""select count(*) from `tabBulk Email` where
month(creation)=month(%s)""" % nowdate())[0][0]

if hasattr(startup, 'get_monthly_bulk_mail_limit'):
monthly_bulk_mail_limit = startup.get_monthly_bulk_mail_limit()
else:
monthly_bulk_mail_limit = getattr(conf, 'monthly_bulk_mail_limit', 500)

bulk_mail_limit = getattr(conf, 'bulk_mail_limit', 200)
if todays_bulk + len(recipients) > bulk_mail_limit:
webnotes.msgprint("""Buik Mail Limit Crossed""", raise_exception=1)
if this_month + len(recipients) > monthly_bulk_mail_limit:
webnotes.msgprint("""Monthly Bulk Mail Limit (%s) Crossed""" % monthly_bulk_mail_limit,
raise_exception=BulkLimitCrossedError)

def add_unsubscribe_link(email):
from webnotes.utils import get_request_site_address
return message + """<div style="padding: 7px; border-top: 1px solid #aaa>">
return message + """<div style="padding: 7px; border-top: 1px solid #aaa;
margin-top: 17px;">
<small><a href="http://%s/server.py?cmd=%s&email=%s&type=%s&email_field=%s">
Unsubscribe</a> from this list.</small></div>""" % (get_request_site_address(),
'webnotes.utils.email_lib.bulk.unsubscribe', email, doctype, email_field)
@@ -113,6 +121,6 @@ def flush():
where name=%s""", (str(e), email["name"]), auto_commit=True)

def clear_outbox():
"""remove mails older than 7 days in Outbox"""
"""remove mails older than 30 days in Outbox"""
webnotes.conn.sql("""delete from `tabBulk Email` where
datediff(now(), creation) > 7""", (str(e), email["name"]), auto_commit=True)
datediff(now(), creation) > 30""", (str(e), email["name"]), auto_commit=True)

+ 2
- 1
py/webnotes/utils/email_lib/smtp.py Просмотреть файл

@@ -115,8 +115,9 @@ class EMail:
def get_footer(self):
"""append a footer"""
import startup
footer = webnotes.conn.get_value('Control Panel',None,'mail_footer') or ''
footer += (webnotes.conn.get_global('global_mail_footer') or '')
footer += getattr(startup, 'mail_footer', '')
return unicode(footer)
def attach_file(self, n):


Загрузка…
Отмена
Сохранить