Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
radiopanik
django-panik-newsletter
Commits
f77be91f
Commit
f77be91f
authored
Jan 31, 2021
by
fred
Browse files
store ip and user agent for stats
parent
bc1fd6d8
Changes
3
Hide whitespace changes
Inline
Side-by-side
newsletter/migrations/0005_auto_20210131_1721.py
0 → 100644
View file @
f77be91f
# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2021-01-31 17:21
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'newsletter'
,
'0004_auto_20210131_1714'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'subscriber'
,
name
=
'source_ip'
,
field
=
models
.
CharField
(
blank
=
True
,
max_length
=
100
),
),
migrations
.
AddField
(
model_name
=
'subscriber'
,
name
=
'user_agent'
,
field
=
models
.
CharField
(
blank
=
True
,
max_length
=
1000
),
),
]
newsletter/models.py
View file @
f77be91f
...
...
@@ -35,6 +35,8 @@ class Subscriber(models.Model) :
password
=
models
.
CharField
(
max_length
=
100
)
bot_check1
=
models
.
BooleanField
(
default
=
False
)
bot_check2
=
models
.
BooleanField
(
default
=
False
)
user_agent
=
models
.
CharField
(
max_length
=
1000
,
blank
=
True
)
source_ip
=
models
.
CharField
(
max_length
=
100
,
blank
=
True
)
def
__unicode__
(
self
)
:
return
self
.
email
...
...
newsletter/views.py
View file @
f77be91f
...
...
@@ -38,6 +38,13 @@ class SubscribeView(CreateView):
# but redirect to success page nevertheless
self
.
object
.
bot_check1
=
bool
(
'validation'
in
self
.
request
.
POST
)
self
.
object
.
bot_check2
=
bool
(
'validation2'
not
in
self
.
request
.
POST
)
# keep various data, for bot stats
self
.
object
.
source_ip
=
(
self
.
request
.
META
.
get
(
'HTTP_X_FORWARDED_FOR'
)
or
self
.
request
.
META
.
get
(
'HTTP_X_REAL_IP'
)
or
self
.
request
.
META
.
get
(
'REMOTE_ADDR'
))
self
.
object
.
user_agent
=
self
.
request
.
META
.
get
(
'HTTP_USER_AGENT'
)
self
.
object
.
save
()
if
not
self
.
object
.
is_from_bot
():
self
.
object
.
send_confirmation_email
()
return
resp
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment