Commit 49578bed authored by buttle's avatar buttle

Making progress with mongoengine

parent e2fd649c
venv
config.cfg
notes.txt
*.pyc
......
......@@ -25,7 +25,7 @@ import smtplib, socket
from threading import Thread
def createSmtpObj():
config=g.site.data["smtpConfig"]
config=g.site.smtpConfig
try:
if config["encryption"] == "SSL":
server = smtplib.SMTP_SSL(config["host"], port=config["port"], timeout=2)
......@@ -45,9 +45,9 @@ def sendMail(email, message):
server = createSmtpObj()
if server:
try:
header='To: ' + email + '\n' + 'From: ' + g.site.data["smtpConfig"]["noreplyAddress"] + '\n'
header='To: ' + email + '\n' + 'From: ' + g.site.smtpConfig["noreplyAddress"] + '\n'
message=header + message
server.sendmail(g.site.data["smtpConfig"]["noreplyAddress"], email, message.encode('utf-8'))
server.sendmail(g.site.smtpConfig["noreplyAddress"], email, message.encode('utf-8'))
return True
except Exception as e:
if g.isAdmin:
......@@ -56,7 +56,7 @@ def sendMail(email, message):
def smtpSendConfirmEmail(user, newEmail=None):
link="%suser/validate-email/%s" % (Site().host_url, user.token['token'])
link="%suser/validate-email/%s" % (g.site.host_url, user.token['token'])
message=gettext("Hello %s\n\nPlease confirm your email\n\n%s") % (user.username, link)
message = 'Subject: {}\n\n{}'.format(gettext("GNGforms. Confirm email"), message)
if newEmail:
......@@ -66,16 +66,16 @@ def smtpSendConfirmEmail(user, newEmail=None):
def smtpSendInvite(invite):
site=Site(hostname=invite.data['hostname'])
link="%suser/new/%s" % (site.host_url, invite.data['token']['token'])
message="%s\n\n%s" % (invite.data['message'], link)
site=Site.find()
link="%suser/new/%s" % (site.host_url, invite.token['token'])
message="%s\n\n%s" % (invite.message, link)
message='Subject: {}\n\n{}'.format(gettext("GNGforms. Invitation to %s" % site.hostname), message)
return sendMail(invite.data['email'], message)
return sendMail(invite.email, message)
def smtpSendRecoverPassword(user):
link="%ssite/recover-password/%s" % (Site().host_url, user.token['token'])
link="%ssite/recover-password/%s" % (g.site.host_url, user.token['token'])
message=gettext("Please use this link to recover your password")
message="%s\n\n%s" % (message, link)
message='Subject: {}\n\n{}'.format(gettext("GNGforms. Recover password"), message)
......@@ -84,7 +84,7 @@ def smtpSendRecoverPassword(user):
def smtpSendNewFormEntryNotification(emails, entry, slug):
message=gettext("New form entry in %s at %s\n" % (slug, Site().hostname))
message=gettext("New form entry in %s at %s\n" % (slug, g.site.hostname))
for data in entry:
message="%s\n%s: %s" % (message, data[0], data[1])
message="%s\n" % message
......@@ -94,21 +94,21 @@ def smtpSendNewFormEntryNotification(emails, entry, slug):
sendMail(email, message)
def smtpSendExpiredFormNotification(editorEmails, form):
message=gettext("The form '%s' has expired at %s" % (form.slug, Site().hostname))
message=gettext("The form '%s' has expired at %s" % (form.slug, g.site.hostname))
message='Subject: {}\n\n{}'.format(gettext("GNGforms. A form has expired"), message)
for email in editorEmails:
sendMail(email, message)
def smtpSendNewFormNotification(adminEmails, form):
message=gettext("New form '%s' created at %s" % (form.slug, Site().hostname))
message=gettext("New form '%s' created at %s" % (form.slug, g.site.hostname))
message='Subject: {}\n\n{}'.format(gettext("GNGforms. New form notification"), message)
for email in adminEmails:
sendMail(email, message)
def smtpSendNewUserNotification(adminEmails, username):
message=gettext("New user '%s' created at %s" % (username, Site().hostname))
message=gettext("New user '%s' created at %s" % (username, g.site.hostname))
message='Subject: {}\n\n{}'.format(gettext("GNGforms. New user notification"), message)
for email in adminEmails:
......
This diff is collapsed.
......@@ -20,6 +20,12 @@
</div>
<table class="table table-striped table-condensed">
{% if g.isRootUser %}
<tr>
<td>{%trans%}Form site{%endtrans%}</td>
<td>{{ form.hostname }}</td>
</tr>
{% endif %}
<tr>
<td>{%trans%}Current author{%endtrans%}</td>
<td>{{ form.user.username }}</td>
......@@ -30,7 +36,7 @@
{%trans%}Are you sure?{%endtrans%}
<p>&nbsp;</p>
<form action="/admin/forms/change-author/{{form._id}}" method="POST">
<form action="/admin/forms/change-author/{{form.id}}" method="POST">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<input name="old_author_username" type="text" placeholder="{%trans%}Current author's username{%endtrans%}" class="form-control" required />
<br />
......@@ -39,7 +45,7 @@
<input class="btn-primary btn btn-md" type="submit" value="{%trans%}Change author{%endtrans%}" />
</form>
{% if editors|length > 1 %}
{% if editors|length > 1 %}
<p>&nbsp;</p>
<div style="font-size:1.5em;">
{%trans%}Editors{%endtrans%}
......@@ -57,40 +63,18 @@
<td>{{ editor.email }}</td>
<td class="text-right">
{% if editor.id|string == form.author %}
({%trans%}Author{%endtrans%})
{%trans%}Author{%endtrans%}
{% else %}
<input class="btn btn-xs btn-danger" type="button" value="{%trans%}Remove{%endtrans%}" onClick="js:removeEditor('{{editor._id}}');">
{%trans%}Editor{%endtrans%}
{% endif %}
</td>
</tr>
{% endfor %}
</table>
{% endif %}
{% endif %}
</div>
<div class="row col-md-4"></div>
</div>
<script>
var csrftoken = "{{ csrf_token() }}";
function removeEditor(editor_id){
$.ajax({
url : "/forms/remove-editor/{{form._id}}/"+editor_id,
type: "POST",
dataType: "json",
beforeSend: function(xhr, settings) {
if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type)) {
xhr.setRequestHeader("X-CSRFToken", csrftoken)
}
},
success: function(data, textStatus, jqXHR)
{
if (data == editor_id) {
$('#editor_'+editor_id).hide();
}
}
});
}
</script>
{% endblock %}
......@@ -5,7 +5,7 @@
<div class="container">
<div class="row col-md-3"></div>
<div class="row col-md-6" style="font-size:1.5em">
<input class="btn-primary btn btn-sm" type="button" value="{%trans%}Return to form{%endtrans%}" onClick="location.href='/forms/view/{{ form._id }}'">
<input class="btn-primary btn btn-sm" type="button" value="{%trans%}Return to form{%endtrans%}" onClick="location.href='/forms/view/{{ form.id }}'">
{{ form.slug }}
<hr style="margin-bottom:5px" />
</div>
......@@ -17,8 +17,8 @@
<div class="row col-md-6">
<div id="toggle_notification" class="btn-group btn-toggle">
<button id="notification_true" class="btn btn-xs btn-default {% if form.data.editors[g.current_user._id|string]['notification']['expiredForm'] %}btn-success{% endif %}">{%trans%}True{%endtrans%}</button>
<button id="notification_false" class="btn btn-xs btn-default {% if not form.data.editors[g.current_user._id|string]['notification']['expiredForm'] %}btn-primary{% endif %}">{%trans%}False{%endtrans%}</button>
<button id="notification_true" class="btn btn-xs btn-default {% if form.editors[g.current_user.id|string]['notification']['expiredForm'] %}btn-success{% endif %}">{%trans%}True{%endtrans%}</button>
<button id="notification_false" class="btn btn-xs btn-default {% if not form.editors[g.current_user.id|string]['notification']['expiredForm'] %}btn-primary{% endif %}">{%trans%}False{%endtrans%}</button>
</div>
{%trans%}Notify me when this form expires{%endtrans%}
<p>&nbsp;</p>
......@@ -89,7 +89,7 @@ function dateSet(e){
function setMaxValue(id){
var value=$('#'+id).val();
$.ajax({
url : "/forms/set-field-condition/{{ form._id }}",
url : "/forms/set-field-condition/{{ form.id }}",
type: "POST",
dataType: "json",
data: {"field_name": id, "condition": value},
......@@ -116,7 +116,7 @@ function setMaxValue(id){
}
document.getElementById('toggle_notification').addEventListener('click', function(evt){
$.ajax({
url : "/form/toggle-expiration-notification/{{ form._id }}",
url : "/form/toggle-expiration-notification/{{ form.id }}",
type: "POST",
dataType: "json",
beforeSend: function(xhr, settings) {
......@@ -154,8 +154,8 @@ $(document).on("change", ".condition", function () {
$('#button-'+this.id).addClass('btn-warning');
});
jQuery(function($) {
var savedDate={{form.data['expiryConditions']['expireDate']|tojson}};
if (savedDate != null){
var savedDate={{form.expiryConditions['expireDate']|tojson}};
if (savedDate != false){
fields=savedDate.split(' ');
$('#date').val(fields[0]);
$('#time').val(fields[1].slice(0, 5)); // remove seconds for type="time"
......
......@@ -62,7 +62,7 @@
<table class="table table-condensed">
{% for editor in editors %}
<tr id="editor_{{editor._id}}">
<tr id="editor_{{editor.id}}">
<td>
{{ editor.email }}
</td>
......@@ -70,13 +70,13 @@
{% if editor.id|string == form.author %}
({%trans%}Author{%endtrans%})
{% else %}
<input class="btn btn-xs btn-danger" type="button" value="{%trans%}Remove{%endtrans%}" onClick="js:removeEditor('{{editor._id}}');">
<input class="btn btn-xs btn-danger" type="button" value="{%trans%}Remove{%endtrans%}" onClick="js:removeEditor('{{editor.id}}');">
{% endif %}
</td>
</tr>
{% endfor %}
<tr>
<form action="/forms/add-editor/{{form._id}}" method="POST">
<form action="/forms/add-editor/{{form.id}}" method="POST">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<td>
<input name="email" type="text" placeholder="New editor's email" class="form-control" required >
......
......@@ -16,7 +16,7 @@
</div>
<p></p>
{% if not g.current_user.data.validatedEmail %}
{% if not g.current_user.validatedEmail %}
<div style="font-size:1.25em; padding-bottom:0.5em; display:inline; float:left;">
{%trans%}Your email has not been validated{%endtrans%}
</div>
......@@ -65,7 +65,7 @@
</tr>
<tr>
<td>{%trans%}Preferred language{%endtrans%}</td>
<td>{{ config['LANGUAGES'][g.current_user.data['language']][0] }}</td>
<td>{{ config['LANGUAGES'][g.current_user.language][0] }}</td>
<td class="text-right">
<input class="btn-primary btn btn-xs" type="button" value="{%trans%}Change{%endtrans%}" onClick="location.href='/user/change-language'">
</td>
......@@ -99,13 +99,13 @@
{% for invite in invites %}
<tr>
<td>{{invite.token.created.strftime('%Y-%m-%d') }}</td>
<td>{{invite.data['email']}}</td>
<td>{{invite.email}}</td>
{% if g.isRootUser %}
<td>{{invite.data['hostname']}}</td>
<td>{{invite.hostname}}</td>
{% endif %}
<td>{{invite.data['admin']}}</td>
<td>{{invite.admin}}</td>
<td class="text-right">
<input class="btn btn-xs btn-danger" type="button" value="{%trans%}Delete{%endtrans%}" onClick="location.href='/admin/invites/delete/{{invite._id}}'">
<input class="btn btn-xs btn-danger" type="button" value="{%trans%}Delete{%endtrans%}" onClick="location.href='/admin/invites/delete/{{invite.id}}'">
</td>
</tr>
{% endfor %}
......@@ -125,8 +125,8 @@
<td>{%trans%}Notify me when new user has registered{%endtrans%}</td>
<td class="text-right">
<div id="toggle_notify_newuser" class="btn-group btn-toggle">
<button id="notify_newuser_true" class="btn btn-xs btn-default {% if user.data['admin']['notifyNewUser'] %}btn-success{% endif %}">{%trans%}True{%endtrans%}</button>
<button id="notify_newuser_false" class="btn btn-xs btn-default {% if not user.data['admin']['notifyNewUser'] %}btn-primary{% endif %}">{%trans%}False{%endtrans%}</button>
<button id="notify_newuser_true" class="btn btn-xs btn-default {% if user.admin['notifyNewUser'] %}btn-success{% endif %}">{%trans%}True{%endtrans%}</button>
<button id="notify_newuser_false" class="btn btn-xs btn-default {% if not user.admin['notifyNewUser'] %}btn-primary{% endif %}">{%trans%}False{%endtrans%}</button>
</div>
</td>
</tr>
......@@ -134,8 +134,8 @@
<td>{%trans%}Notify me when new form has been created{%endtrans%}</td>
<td class="text-right">
<div id="toggle_notify_newform" class="btn-group btn-toggle">
<button id="notify_newform_true" class="btn btn-xs btn-default {% if user.data['admin']['notifyNewForm'] %}btn-success{% endif %}">{%trans%}True{%endtrans%}</button>
<button id="notify_newform_false" class="btn btn-xs btn-default {% if not user.data['admin']['notifyNewForm'] %}btn-primary{% endif %}">{%trans%}False{%endtrans%}</button>
<button id="notify_newform_true" class="btn btn-xs btn-default {% if user.admin['notifyNewForm'] %}btn-success{% endif %}">{%trans%}True{%endtrans%}</button>
<button id="notify_newform_false" class="btn btn-xs btn-default {% if not user.admin['notifyNewForm'] %}btn-primary{% endif %}">{%trans%}False{%endtrans%}</button>
</div>
</td>
</tr>
......@@ -235,7 +235,7 @@
<td>{{ site.totalForms }}</td>
{% if total_forms.append(total_forms.pop() + site.totalForms) %}{% endif %}
<td class="text-right">
<input class="btn-primary btn btn-xs" type="button" value="{%trans%}Edit{%endtrans%}" onClick="location.href='/admin/sites/edit/{{site.site.hostname}}'">
<input class="btn-primary btn btn-xs" type="button" value="{%trans%}Edit{%endtrans%}" onClick="location.href='/admin/sites/edit/{{site.hostname}}'">
</td>
</tr>
{% endfor %}
......@@ -254,7 +254,7 @@
<table class="table">
<tr>
<td>{%trans%}Created{%endtrans%}</td>
<td>{{installation.data.created}}</td>
<td>{{installation.created}}</td>
</tr>
<tr>
<td>GNGforms version</td>
......
......@@ -210,7 +210,7 @@ persistentClass may be a User class, or an Invite class, ..
"""
def createToken(persistentClass, **kwargs):
tokenString = getRandomString(length=48)
while persistentClass(token=tokenString):
while persistentClass.find(token=tokenString):
tokenString = getRandomString(length=48)
result={'token': tokenString, 'created': datetime.datetime.now()}
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment