Skip to content

Commit

Permalink
Merge branch 'master' into MCWEB_STABLE_2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
willend committed Sep 26, 2019
2 parents 1fb5518 + 69bf8e6 commit 68b0871
Show file tree
Hide file tree
Showing 18 changed files with 552 additions and 214 deletions.
7 changes: 5 additions & 2 deletions mcsimrunner/mcweb/settings.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ MXRUN = 'mxrun.pl'
#MCPLOT_CMD = "mcplot-gnuplot-py -s"
#MCPLOT_LOGCMD = "mcplot-gnuplot-py -s -l"
# For Perl + PGPLOT use
MCPLOT_CMD = "mcplot.pl -png"
MCPLOT_LOGCMD = "mcplot.pl -png -log"
#MCPLOT_CMD = "mcplot.pl -png"
MCPLOT_CMD = "mcplot-svg-dev --nobrowse --autosize --libpath='/static'"
#MCPLOT_LOGCMD = "mcplot.pl -png -log"
MCPLOT_LOGCMD = "mcplot-svg-dev --nobrowse --autosize --log --libpath='/static'"
MCPLOT_USE_HTML_PLOTTER = True

MCDISPLAY = "mcdisplay.pl" # should be mcdisplay.pl from mcstas 2.4
MCDISPLAY_WEBGL = "mcdisplay-webgl"
Expand Down
7 changes: 5 additions & 2 deletions mcsimrunner/signupper/templates/man_login.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<!DOCTYPE html>
<html>
<head><title>mcweb: course manage login</title></head>
<head>
<title>mcweb: course manage login</title>
<script>window.onload = function() { document.getElementById("username").focus(); }</script>
</head>
<body style="margin-left:auto;margin-right:auto;width:600px;">
<form method="POST" action="{{ next }}">
{% csrf_token %}
<fieldset>
<table style='margin-left:auto; margin-right:auto;'>
<tr>
<td>Super-username:</td>
<td><input type="text" name="username"></td>
<td><input type="text" name="username" id="username"></td>
</tr>
<tr>
<td>Password:</td>
Expand Down
85 changes: 42 additions & 43 deletions mcsimrunner/signupper/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,64 +611,60 @@ def man_courses(req, menu, post, base_context):
form = req.POST

tmpl = form['tmpl_selector']
site = form['tbx_site']
shortname = form['field_shortname']
title = form['tbx_title']
override = form.get('cbx_override', False)
if title == '':
title = "empty"
username = form['tbx_username']
firstname = form['tbx_firstname']
lastname = form['tbx_lastname']
email = form['tbx_email']

m = re.match('\-\-\sselect\sfrom', shortname)

# override section
if override and shortname != '' and not m:
try:
status = utils.update_course_from_template(templatename=tmpl, shortname=shortname)
req.session['message'] = 'Course "%s" OVERRIDE update or create attempted (no teacher) with message "%s".' % (shortname, status)
except Exception as e:
req.session['message'] = '"%s"' % e.__str__()
# sanity check template selected
if re.match('\-\-\sselect\sfrom', tmpl):
req.session['message'] = 'Please select a course template.'
return redirect("/manage/%s" % menu)

# regular section
if site != '' and shortname != '' and title != '' and not m:
pass
else:
req.session['message'] = 'Please select a proper template and a course name.'
# sanity check shortname exists
if shortname == '':
req.session['message'] = 'Please use a proper shortname.'
return redirect("/manage/%s" % menu)

username = form['tbx_username']
firstname = form['tbx_firstname']
lastname = form['tbx_lastname']
email = form['tbx_email']

# double-check that a user has been selected
if username == '':
req.session['message'] = 'Please assign a teacher for the course.'
return redirect("/manage/%s" % menu)

# search registered ldap users for 'username'
users = ldaputils.listusers(uid=username)
if firstname != '' or email != '':
# sanity check for existence, do not proceed
if len(users) != 0:

# new teacher branch
if firstname != '' or lastname != '' or email != '':
# sanity check for existence
if len(users) == 1:
t = users[0]
req.session['message'] = 'User %s already exists with "%s %s, %s", please clear the name and email fields.' % (username, t.cn, t.sn, t.mail)
return redirect("/manage/%s" % menu)

# course create (before teach assignment) and schedule course restore job
status = utils.create_course_from_template(templatename=tmpl, shortname=shortname, fullname=title)
utils.log_coursecreated(shortname, tmpl, req.user.username)
req.session['message'] = 'Course "%s" creation with teacher "%s" and message "%s".' % (shortname, username, status)

# assign a teacher
if firstname == '' or email == '':
req.session['message'] = req.session['message'] + '\n ' + 'New user creation requires a name and an email.'
return redirect("/manage/%s" % menu)
teacher = Signup(username=username, firstname=firstname, lastname=lastname, email=email, password=utils.get_random_passwd(), courses=[shortname])
teacher.save()

utils.adduser(teacher)
utils.enroluser(teacher, course_sn=shortname, teacher=True)

req.session['message'] = req.session['message'] + '\n ' + 'New user %s has been created.' % username
elif len(users) > 0 and username == users[0].uid:
else:
# course create (before teach assignment) and schedule course restore job
status = utils.create_course_from_template(templatename=tmpl, shortname=shortname, fullname=title)
utils.log_coursecreated(shortname, tmpl, req.user.username)
req.session['message'] = 'Course "%s" creation with teacher "%s" and message "%s".' % (shortname, username, status)

# assign a teacher
if firstname == '' or email == '':
req.session['message'] = req.session['message'] + '\n ' + 'New user creation requires a name and an email.'
return redirect("/manage/%s" % menu)
teacher = Signup(username=username, firstname=firstname, lastname=lastname, email=email, password=utils.get_random_passwd(), courses=[shortname])
teacher.save()

utils.adduser(teacher)
utils.enroluser(teacher, course_sn=shortname, teacher=True)

req.session['message'] = req.session['message'] + '\n ' + 'New user %s has been created.' % username

# existing teacher branch
elif len(users) == 1:
# course create (before teacher assignment) and schedule course restore job
status = utils.create_course_from_template(templatename=tmpl, shortname=shortname, fullname=title)
utils.log_coursecreated(shortname, tmpl, req.user.username)
Expand All @@ -677,15 +673,18 @@ def man_courses(req, menu, post, base_context):
# assign teacher
teacher = utils.get_signup(username)
if not teacher:
# user exists only in ldap, create a signup
t_data = users[0]
t = Signup(username=username, firstname=t_data.cn, lastname=t_data.sn, email=t_data.mail, is_in_ldap=True)
t.save()
utils.adduser(t)
t.password = ''
t.save()
teacher = t
req.session['message'] = req.session['message'] + '\n ' + 'WARNING: ldap and signup db data inconsistence, proceeding with teacher "%s", "%s", "%s", "%s".' % (username, t_data.cn, t_data.sn, t_data.mail)
req.session['message'] = req.session['message'] + '\n ' + 'WARNING: username existed only in ldap, proceeding with teacher "%s", "%s", "%s", "%s".' % (username, t_data.cn, t_data.sn, t_data.mail)
utils.enroluser(teacher, course_sn=shortname, teacher=True)

# invalid username branch
else:
# username does not exist, but user did not enter name etc.
req.session['message'] = 'Username "%s" not found. Please enter the name and email of the teacher of this course, and a new user will be created.' % username
Expand Down
Loading

0 comments on commit 68b0871

Please sign in to comment.