Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
marketing_campaign_tracker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
XCG
Odoo modules
marketing_campaign_tracker
Commits
09f99957
Commit
09f99957
authored
12 years ago
by
Florent Aide,
Browse files
Options
Downloads
Patches
Plain Diff
Port to openerp V7
parent
904d68f7
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
marketing_campaign_tracker.py
+55
-69
55 additions, 69 deletions
marketing_campaign_tracker.py
trackitem.py
+4
-9
4 additions, 9 deletions
trackitem.py
with
59 additions
and
78 deletions
marketing_campaign_tracker.py
+
55
−
69
View file @
09f99957
...
...
@@ -21,8 +21,8 @@
##############################################################################
from
md5
import
md5
from
osv
import
osv
,
fields
from
openerp.
osv
import
osv
,
fields
from
openerp.tools
import
config
from
replace
import
insert_tracker_in_html
,
insert_tracker_in_text
...
...
@@ -25,9 +25,9 @@
from
openerp.tools
import
config
from
replace
import
insert_tracker_in_html
,
insert_tracker_in_text
class
hooked_email_template
(
osv
.
osv
):
class
hooked_email_template
(
osv
.
Model
):
"""
overrides the base email template to hook the URL tracker
"""
_inherit
=
'
email.template
'
...
...
@@ -30,13 +30,8 @@
"""
overrides the base email template to hook the URL tracker
"""
_inherit
=
'
email.template
'
def
send_mail
(
self
,
cr
,
uid
,
template_id
,
res_id
,
context
=
None
):
"""
Generates a new mail message for the given template and record,
and schedule it for delivery through the ``mail`` module
'
s scheduler.
:param int template_id: id of the template to render
:param int res_id: id of the record to render the template with
(model is taken from the template)
def
generate_email
(
self
,
cr
,
uid
,
template_id
,
res_id
,
context
=
None
):
"""
override generate_email() from our parent to substitute URLs
"""
...
...
@@ -41,8 +36,5 @@
"""
mail_message
=
self
.
pool
.
get
(
'
mail.message
'
)
ir_attachment
=
self
.
pool
.
get
(
'
ir.attachment
'
)
template
=
self
.
browse
(
cr
,
uid
,
template_id
,
context
)
values
=
self
.
generate_email
(
cr
,
uid
,
template_id
,
res_id
,
context
=
context
)
values
=
super
(
hooked_email_template
,
self
).
generate_email
(
cr
,
uid
,
template_id
,
res_id
,
context
=
context
)
...
...
@@ -48,5 +40,7 @@
## Change from original send_mail
if
context
is
None
:
context
=
dict
()
if
context
.
get
(
'
use_tracker
'
,
False
):
# here we need to use tracker so let's do it
tracker_base
=
context
.
get
(
'
tracker_base
'
)
...
...
@@ -50,7 +44,10 @@
if
context
.
get
(
'
use_tracker
'
,
False
):
# here we need to use tracker so let's do it
tracker_base
=
context
.
get
(
'
tracker_base
'
)
#### TODO hostbame_bu configuration with configure option menu.
# here we add a hash that contains informations about our
# business unit... this is necessary to be able to have
# a tracker serve multiple business units
hostname_bu
=
config
.
get
(
'
xmlrpc_interface
'
)
if
not
hostname_bu
:
hostname_bu
=
"
localhost
"
...
...
@@ -59,14 +56,6 @@
id_bu
=
"
%s:%s/%s
"
%
(
hostname_bu
,
port_bu
,
database_bu
)
tracker_base
+=
'
/
'
+
md5
(
id_bu
).
hexdigest
()
if
values
[
'
body_text
'
]:
values
[
'
body_text
'
],
tracks
=
insert_tracker_in_text
(
values
[
'
body_text
'
],
tracker_base
,
context
[
'
activity_id
'
])
if
values
[
'
body_html
'
]:
values
[
'
body_html
'
],
tracks
=
insert_tracker_in_html
(
values
[
'
body_html
'
],
tracker_base
,
context
[
'
activity_id
'
])
trackitem_osv
=
self
.
pool
.
get
(
'
marketing_campaign_tracker.trackitem
'
)
...
...
@@ -72,4 +61,6 @@
trackitem
=
self
.
pool
.
get
(
'
marketing_campaign_tracker.trackitem
'
)
new_body_text
,
tracks
=
insert_tracker_in_text
(
values
.
get
(
'
body
'
),
tracker_base
,
context
[
'
activity_id
'
])
for
trackvalues
in
tracks
:
# create a trackitem for each URL that is replaced
...
...
@@ -74,6 +65,4 @@
for
trackvalues
in
tracks
:
# create a trackitem for each URL that is replaced
trackitem
.
create
(
cr
,
uid
,
trackvalues
,
context
=
None
)
## End Change from original send_mail
trackitem_osv
.
create
(
cr
,
uid
,
trackvalues
,
context
=
None
)
...
...
@@ -79,7 +68,6 @@
#values = self.add_tracker(cr, uid, template_id, res_id,
# context=context)
attachments
=
values
.
pop
(
'
attachments
'
)
or
{}
message_id
=
mail_message
.
create
(
cr
,
uid
,
values
,
context
=
context
)
# link attachments
values
[
"
body
"
]
=
new_body_text
new_body_html
,
tracks
=
insert_tracker_in_html
(
values
.
get
(
'
body_html
'
),
tracker_base
,
context
[
'
activity_id
'
])
...
...
@@ -85,17 +73,5 @@
attachment_ids
=
[]
for
fname
,
fcontent
in
attachments
.
iteritems
():
attachment_data
=
{
'
name
'
:
fname
,
'
datas_fname
'
:
fname
,
'
datas
'
:
fcontent
,
'
res_model
'
:
mail_message
.
_name
,
'
res_id
'
:
message_id
,
}
if
'
default_type
'
in
context
:
del
context
[
'
default_type
'
]
attachment_ids
.
append
(
ir_attachment
.
create
(
cr
,
uid
,
attachment_data
,
context
))
for
trackvalues
in
tracks
:
# create a trackitem for each URL that is replaced
trackitem_osv
.
create
(
cr
,
uid
,
trackvalues
,
context
=
None
)
...
...
@@ -101,4 +77,6 @@
hooked_email_template
()
values
[
"
body_html
"
]
=
new_body_html
return
values
...
...
@@ -103,10 +81,11 @@
class
marketing_campaign_activity
(
osv
.
osv
):
# we want to change the marketing campaign activity...
class
marketing_campaign_activity
(
osv
.
Model
):
# we want to change the marketing campaign activity to inject our new
# options
_inherit
=
'
marketing.campaign.activity
'
# here we add a new field to the marketing campaign activity
# the use_tracker boolean will activate the tracking for URLs if is
# set to True. The default value will be False in order to avoid any
# problem with existing activities previous to this module installation.
...
...
@@ -107,16 +86,17 @@
_inherit
=
'
marketing.campaign.activity
'
# here we add a new field to the marketing campaign activity
# the use_tracker boolean will activate the tracking for URLs if is
# set to True. The default value will be False in order to avoid any
# problem with existing activities previous to this module installation.
_columns
=
{
'
use_tracker
'
:
fields
.
boolean
(
'
Use Tracker
'
,
help
=
'
This option activates the usage of
'
+
'
the external
"
Bounced
"
click tracker
'
),
'
tracker_base
'
:
fields
.
char
(
"
Tracker Base URL
"
,
size
=
200
,
help
=
"
The base URL on which the tracker listens
"
),
}
_columns
=
dict
(
use_tracker
=
fields
.
boolean
(
'
Use Tracker
'
,
help
=
'
Activates the usage of an external
"
Bounced
"
click tracker
'
),
tracker_base
=
fields
.
char
(
"
Tracker Base URL
"
,
size
=
200
,
help
=
"
The base URL on which the tracker listens
"
),
)
# make sure our new field has a sensible default.
# see comment above the _columns definition for more
...
...
@@ -120,7 +100,10 @@
# make sure our new field has a sensible default.
# see comment above the _columns definition for more
_defaults
=
dict
(
use_tracker
=
False
,
tracker_base
=
None
)
_defaults
=
dict
(
use_tracker
=
False
,
tracker_base
=
None
,
)
# make sure an activity which uses a tracker always has a tracker
# base defined...
...
...
@@ -137,12 +120,14 @@
return
True
_constraints
=
[
(
_check_baseurl
,
'
If you activate tracking you must give a tracker base
'
,
[
'
tracker_base
'
])
(
_check_baseurl
,
'
If you use tracking you must give a tracker base URL
'
,
[
'
tracker_base
'
]
)
]
# override the _process_wi_email to replace all the URLs in the template
# body by our tracker URL and store the corresponding keys in database
def
_process_wi_email
(
self
,
cr
,
uid
,
activity
,
workitem
,
context
=
None
):
if
context
is
None
:
...
...
@@ -143,12 +128,12 @@
]
# override the _process_wi_email to replace all the URLs in the template
# body by our tracker URL and store the corresponding keys in database
def
_process_wi_email
(
self
,
cr
,
uid
,
activity
,
workitem
,
context
=
None
):
if
context
is
None
:
context
=
{}
context
=
dict
()
context
[
'
use_tracker
'
]
=
activity
.
use_tracker
if
activity
.
use_tracker
:
# remove any trailing slash that could be present in the base_url
...
...
@@ -150,8 +135,9 @@
context
[
'
use_tracker
'
]
=
activity
.
use_tracker
if
activity
.
use_tracker
:
# remove any trailing slash that could be present in the base_url
# and inject the necessary keys into our context
context
[
'
tracker_base
'
]
=
activity
.
tracker_base
.
rstrip
(
'
/
'
)
context
[
'
activity_id
'
]
=
activity
.
id
...
...
@@ -155,7 +141,7 @@
context
[
'
tracker_base
'
]
=
activity
.
tracker_base
.
rstrip
(
'
/
'
)
context
[
'
activity_id
'
]
=
activity
.
id
return
s
elf
.
pool
.
get
(
'
email.template
'
).
send_mail
(
cr
,
uid
,
activity
.
email_template_id
.
id
,
workitem
.
res_id
,
context
=
context
)
return
s
uper
(
marketing_campaign_activity
,
self
).
_process_wi_email
(
cr
,
uid
,
activity
,
workitem
,
context
=
context
)
...
...
@@ -161,4 +147,3 @@
marketing_campaign_activity
()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
...
...
@@ -163,2 +148,3 @@
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
This diff is collapsed.
Click to expand it.
trackitem.py
+
4
−
9
View file @
09f99957
...
...
@@ -20,7 +20,7 @@
#
##############################################################################
from
osv
import
osv
,
fields
from
openerp.
osv
import
osv
,
fields
import
time
...
...
@@ -24,7 +24,7 @@
import
time
class
trackitem
(
osv
.
osv
):
class
trackitem
(
osv
.
Model
):
"""
a trackitem is a simple link between a real URL and a UUID URL that
was sent in an email. When the person clicks on the UUID URL the tracker
server will hit the database with the UUID to try and find the real URL
...
...
@@ -38,8 +38,7 @@
_name
=
'
marketing_campaign_tracker.trackitem
'
_columns
=
{
'
trackitem_uuid
'
:
fields
.
char
(
"
uuid
"
,
size
=
36
,
required
=
True
,
select
=
1
),
'
trackitem_uuid
'
:
fields
.
char
(
"
uuid
"
,
size
=
36
,
required
=
True
,
select
=
1
),
'
real_url
'
:
fields
.
char
(
"
Real URL
"
,
size
=
500
),
# we only need the activity because an activity obj has a campaign_id
# attribute referencing the campaign it belongs to.
...
...
@@ -49,5 +48,4 @@
),
}
trackitem
()
...
...
@@ -53,6 +51,5 @@
class
trackvisit
(
osv
.
osv
):
class
trackvisit
(
osv
.
Model
):
"""
a trackvisit is a small timestamp associated to a trackitem
Basically each time a client clicks on a tracked URL and gets redirected
by the tracker a trackvisit will be recorded for the action. This opens-up
...
...
@@ -75,5 +72,3 @@
# format the datetime for PG backend storage in a timestamp
visit_time
=
lambda
*
a
:
time
.
strftime
(
"
%Y-%m-%d %H:%M:%S.000000
"
),
)
trackvisit
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment