Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
piks3l
Respect My Net
Commits
e6238699
Commit
e6238699
authored
Jun 20, 2011
by
stef
Browse files
[enh] added confirmation of reports
parent
6ec7b34d
Changes
5
Hide whitespace changes
Inline
Side-by-side
bt/models.py
View file @
e6238699
...
...
@@ -63,6 +63,9 @@ class Violation(models.Model):
loophole
=
models
.
BooleanField
()
activationid
=
models
.
CharField
(
max_length
=
128
)
def
confirmations
(
self
):
return
self
.
confirmation_set
.
filter
(
key
=
''
).
count
()
class
Comment
(
models
.
Model
):
submitter_email
=
models
.
EmailField
()
submitter_name
=
models
.
CharField
(
max_length
=
20
)
...
...
@@ -75,6 +78,11 @@ class Attachment(models.Model):
name
=
models
.
CharField
(
max_length
=
512
)
comment
=
models
.
ForeignKey
(
Comment
)
class
Confirmation
(
models
.
Model
):
key
=
models
.
CharField
(
max_length
=
64
)
email
=
models
.
EmailField
()
violation
=
models
.
ForeignKey
(
Violation
)
class
ViolationModerator
(
CommentModerator
):
email_notification
=
True
moderate_after
=
0
...
...
bt/views.py
View file @
e6238699
...
...
@@ -7,7 +7,8 @@ from django.conf import settings
from
django.core.paginator
import
Paginator
,
EmptyPage
,
PageNotAnInteger
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.contrib
import
messages
from
models
import
Violation
,
Attachment
,
Comment
from
django.utils.translation
import
ugettext_lazy
as
_
from
models
import
Violation
,
Attachment
,
Comment
,
Confirmation
from
tempfile
import
mkstemp
from
datetime
import
datetime
import
hashlib
,
os
,
re
,
json
,
smtplib
...
...
@@ -48,18 +49,35 @@ def activate(request):
messages
.
add_message
(
request
,
messages
.
INFO
,
_
(
'Thank you for verifying your submission.'
))
return
HttpResponseRedirect
(
'/'
)
# Redirect after POST
def
confirm
(
request
,
id
,
name
=
None
):
if
name
:
if
Confirmation
.
objects
.
filter
(
email
=
name
,
violation
=
id
).
count
()
==
0
:
actid
=
sendverifymail
(
'confirm/'
,
name
)
c
=
Confirmation
(
key
=
actid
,
email
=
name
,
violation
=
Violation
.
objects
.
get
(
pk
=
id
))
c
.
save
()
return
HttpResponse
(
'<div class="confirm_thanks">Thank you for your confirmation</div>'
)
c
=
Confirmation
.
objects
.
get
(
key
=
id
)
if
c
:
c
.
key
=
''
c
.
save
()
return
HttpResponse
(
'<div class="confirm_thanks">Thank you for verifying your confirmation</div>'
)
def
sendverifymail
(
service
,
to
):
actid
=
hashlib
.
sha1
(
''
.
join
([
chr
(
randint
(
32
,
122
))
for
x
in
range
(
12
)])).
hexdigest
()
msg
=
MIMEText
(
_
(
"Your verification key is %s/%s%s
\n
"
)
%
(
settings
.
ROOT_URL
or
'http://localhost:8001/'
,
service
,
actid
))
msg
[
'Subject'
]
=
_
(
'NNMon submission verification'
)
msg
[
'From'
]
=
'nnmon@nnmon.lqdn.fr'
msg
[
'To'
]
=
to
s
=
smtplib
.
SMTP
(
'localhost'
)
s
.
sendmail
(
'nnmon@nnmon.lqdn.fr'
,
[
to
],
msg
.
as_string
())
s
.
quit
()
return
actid
def
add
(
request
):
if
request
.
method
==
'POST'
:
form
=
AddViolation
(
request
.
POST
)
if
form
.
is_valid
():
actid
=
hashlib
.
sha1
(
''
.
join
([
chr
(
randint
(
32
,
122
))
for
x
in
range
(
12
)])).
hexdigest
()
msg
=
MIMEText
(
_
(
"Your verification key is %s/activate?key=%s
\n
"
)
%
(
settings
.
ROOT_URL
or
'http://localhost:8001/'
,
actid
))
msg
[
'Subject'
]
=
_
(
'NNMon submission verification'
)
msg
[
'From'
]
=
'nnmon@nnmon.lqdn.fr'
msg
[
'To'
]
=
form
.
cleaned_data
[
'email'
]
s
=
smtplib
.
SMTP
(
'localhost'
)
s
.
sendmail
(
'nnmon@nnmon.lqdn.fr'
,
[
form
.
cleaned_data
[
'email'
]],
msg
.
as_string
())
s
.
quit
()
actid
=
sendverifymail
(
'activate?key='
,
form
.
cleaned_data
[
'email'
])
v
=
Violation
(
country
=
form
.
cleaned_data
[
'country'
],
operator
=
form
.
cleaned_data
[
'operator'
],
...
...
media/css/style.css
View file @
e6238699
...
...
@@ -21,6 +21,11 @@ li { list-style: none; }
#report
dd
{
display
:
inline
;
}
#auth
{
float
:
right
;
clear
:
both
;
}
.confirm
{
display
:
inline
;
position
:
relative
;
}
.confirm
:hover
>
div
{
display
:
block
;
}
.confirm_popup
{
display
:
none
;
position
:
absolute
;
right
:
0
;
border
:
2px
solid
#454545
;
padding
:
10px
;
background
:
#F7F7F7
;
z-index
:
20
;
}
.confirm_thanks
{
width
:
17.2em
;
height
:
6.7em
;
}
table
.listing
,
.pagination
{
width
:
90%
;
margin
:
auto
;
}
table
.listing
thead
td
{
font-weight
:
bold
;
border-bottom
:
1px
solid
black
;
}
...
...
templates/list.html
View file @
e6238699
...
...
@@ -9,7 +9,12 @@
<script
type=
"text/javascript"
>
$
(
document
).
ready
(
function
()
{
$
(
"
#sortedlist
"
).
tablesorter
();
});
$
(
'
.confirm_form
'
).
submit
(
function
()
{
var
self
=
this
;
$
.
ajax
({
url
:
'
/confirm/
'
+
$
(
this
).
attr
(
'
id
'
)
+
'
/
'
+
$
(
this
).
children
(
'
input:first
'
).
attr
(
'
value
'
),
success
:
function
(
data
)
{
$
(
self
).
html
(
data
);
}});
return
false
;
});
});
</script>
{% endblock %}
...
...
@@ -35,6 +40,7 @@
<th>
{% trans "contractual" %}
</th>
<th>
{% trans "contractual_excerpt" %}
</th>
<th>
{% trans "loophole" %}
</th>
<th>
{% trans "confirmations" %}
</th>
</tr>
</thead>
<tbody>
...
...
@@ -51,6 +57,20 @@
<td>
{{ violation.contractual }}
</td>
<td>
{{ violation.contractual_excerpt }}
</td>
<td>
{{ violation.loophole }}
</td>
<td>
{{ violation.confirmations }}
<div
class=
"confirm"
><a>
Confirm this violation
</a>
<div
class=
"hidden confirm_popup"
>
<h3>
Confirmation
</h3>
<p>
<form
method=
"get"
class=
"confirm_form"
id=
"{{ violation.pk }}"
>
E-mail:
<input
type=
"text"
name=
"email"
/><br
/>
//required
<br
/>
<input
type=
"hidden"
value=
"{{ violation.pk }}"
/>
<input
type=
"submit"
value=
"confirm"
/>
</form>
</p>
</div>
</div>
</td>
</tr>
{% endfor %}
</tbody>
...
...
urls.py
View file @
e6238699
...
...
@@ -11,6 +11,8 @@ urlpatterns = patterns('',
(
r
'^add/$'
,
bt
.
add
),
(
r
'^view/(?P<id>[0-9]*)$'
,
bt
.
view
),
(
r
'^activate/$'
,
bt
.
activate
),
(
r
'^confirm/(?P<id>[0-9a-z]*)$'
,
bt
.
confirm
),
(
r
'^confirm/(?P<id>[0-9]*)/(?P<name>.*)$'
,
bt
.
confirm
),
(
r
'^accounts/logout$'
,
'django.contrib.auth.views.logout'
,
{
'next_page'
:
'/'
}),
(
r
'^accounts/'
,
include
(
'registration.urls'
)),
(
r
'^comments/'
,
include
(
'django.contrib.comments.urls'
)),
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment