-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merging master into ach_issue30 (working on #30)
- Loading branch information
1 parent
7a19360
commit 53dbc54
Showing
9 changed files
with
781 additions
and
222 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
alembic/versions/33058c41765c_validation_and_completion_of_http_rlms.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"""Validation and completion of HTTP RLMS | ||
Revision ID: 33058c41765c | ||
Revises: 3ee46f95bcce | ||
Create Date: 2014-05-16 10:00:23.411755 | ||
""" | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '33058c41765c' | ||
down_revision = '3ee46f95bcce' | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
def upgrade(): | ||
|
||
op.add_column('rlmss', sa.Column('validated', sa.Boolean(), nullable=False)) | ||
op.add_column('rlmss', sa.Column('newrlms', sa.Boolean(), nullable=False)) | ||
|
||
op.create_table('http_rlms_property', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('rlms_id', sa.Integer(), nullable=False), | ||
sa.Column('name', sa.Unicode(length=50), nullable=False), | ||
sa.Column('value', sa.Unicode(length=50), nullable=False), | ||
sa.ForeignKeyConstraint(['rlms_id'], ['rlmss.id'], ), | ||
sa.PrimaryKeyConstraint('id'), | ||
sa.UniqueConstraint('name','rlms_id') | ||
) | ||
|
||
def downgrade(): | ||
op.drop_column('rlmss', 'validated') | ||
op.drop_column('rlmss', 'newrlms') | ||
|
||
op.drop_table('http_rlms_property') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
# -*-*- encoding: utf-8 -*-*- | ||
|
||
import sys | ||
import json | ||
|
||
from flask import request, Blueprint | ||
from flask.ext.wtf import TextField, PasswordField, Required, URL, ValidationError, BooleanField | ||
|
||
from labmanager.forms import AddForm, RetrospectiveForm, GenericPermissionForm | ||
from labmanager.rlms import register, Laboratory, BaseRLMS, BaseFormCreator, register_blueprint, Capabilities, Versions | ||
from labmanager import app | ||
|
||
|
||
def get_module(version): | ||
"""get_module(version) -> proper module for that version | ||
Right now, a single version is supported, so this module itself will be returned. | ||
When compatibility is required, we may change this and import different modules. | ||
""" | ||
# TODO: check version | ||
return sys.modules[__name__] | ||
|
||
|
||
class HTTPAddForm(AddForm): | ||
|
||
remote_login = TextField("Login", validators = [Required()]) | ||
password = PasswordField("Password") | ||
|
||
base_url = TextField("Base URL", validators = [Required(), URL() ]) | ||
# completed = BooleanField('This RLMS is completed') | ||
|
||
def __init__(self, add_or_edit, *args, **kwargs): | ||
super(HTTPAddForm, self).__init__(*args, **kwargs) | ||
self.add_or_edit = add_or_edit | ||
|
||
@staticmethod | ||
def process_configuration(old_configuration, new_configuration): | ||
old_configuration_dict = json.loads(old_configuration) | ||
new_configuration_dict = json.loads(new_configuration) | ||
if new_configuration_dict.get('password', '') == '': | ||
new_configuration_dict['password'] = old_configuration_dict.get('password','') | ||
return json.dumps(new_configuration_dict) | ||
|
||
def validate_password(form, field): | ||
if form.add_or_edit and field.data == '': | ||
raise ValidationError("This field is required.") | ||
|
||
|
||
|
||
class HTTPPermissionForm(RetrospectiveForm): | ||
priority = TextField("Priority") | ||
time = TextField("Time (in seconds)") | ||
|
||
def validate_number(form, field): | ||
if field.data != '' and field.data is not None: | ||
try: | ||
int(field.data) | ||
except: | ||
raise ValidationError("Invalid value. Must be an integer.") | ||
|
||
|
||
validate_priority = validate_number | ||
validate_time = validate_number | ||
|
||
class HTTPLmsPermissionForm(HTTPPermissionForm, GenericPermissionForm): | ||
pass | ||
|
||
class HTTPFormCreator(BaseFormCreator): | ||
|
||
def get_add_form(self): | ||
return HTTPAddForm | ||
|
||
def get_permission_form(self): | ||
return HTTPPermissionForm | ||
|
||
def get_lms_permission_form(self): | ||
return HTTPLmsPermissionForm | ||
|
||
FORM_CREATOR = HTTPFormCreator() | ||
|
||
|
||
|
||
class RLMS(BaseRLMS): | ||
|
||
def __init__(self, configuration): | ||
configuration = json.loads(configuration) | ||
self.http_url = self.configuration['url'] | ||
self.http_user = self.configuration['remote_login'] | ||
self.http_passwd = self.configuration['password'] | ||
self.http_config = self.configuration['config'] # String, a JSON | ||
self.base_url = self.configuration['base_url'] | ||
|
||
if self.login is None or self.password is None or self.base_url is None: | ||
raise Exception("Laboratory misconfigured: fields missing" ) | ||
|
||
|
||
def get_version(self): | ||
|
||
return Versions.VERSION_1 | ||
|
||
def get_capabilities(self): | ||
|
||
return Versions.VERSION_1 | ||
|
||
def test(self): | ||
|
||
return None | ||
|
||
def get_laboratories(self): | ||
|
||
return None | ||
|
||
def reserve(self, laboratory_id, username, institution, general_configuration_str, particular_configurations, request_payload, user_properties, *args, **kwargs): | ||
return None | ||
|
||
def get_http_user(self): | ||
return self.http_user | ||
|
||
|
||
|
||
|
||
|
||
|
||
http_blueprint = Blueprint('http', __name__) | ||
@http_blueprint.route('/') | ||
def index(): | ||
return "This is the index for HTTP" | ||
|
||
register("HTTP", ['0.1'], __name__) | ||
register_blueprint(http_blueprint, '/http') | ||
|
41 changes: 41 additions & 0 deletions
41
labmanager/templates/labmanager_admin/rlms_properties_list.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{% extends 'admin/master.html' %} | ||
{% block body %} | ||
<h3> {{gettext('Properties for')}} <a href="{{rlms.url}}">{{ rlms.kind }} ({{rlms.version }})</a> {{gettext('at')}} {{ rlms.location }} </h3> | ||
|
||
|
||
{% if prop_value_list %} | ||
<form action="." method="POST"> | ||
<table class="table table-bordered table-striped"> | ||
<thead> | ||
<tr> | ||
<th>{{gettext('Property')}}</th> | ||
<th>{{gettext('Value')}}</th> | ||
|
||
</tr> | ||
</thead> | ||
<tbody> | ||
<!-- prop_value[0] is the property name, prop_value[1] is the value currently stored--> | ||
{% for prop_value in prop_value_list %} | ||
<tr> | ||
<td>{{ prop_value[0] }}</td> | ||
<td><input type="text" name="{{ prop_value[0] }}" value="{{prop_value[1]}}"><br> </td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</form> | ||
</table> | ||
<div class="form-actions" align="center"> | ||
<button class="btn btn-primary" name="action" type="submit" value="savechangesreturn"> {{gettext('Save and return')}} </button> | ||
|
||
<button class="btn btn-danger" name="action" type="submit" value="return"> {{gettext('Return')}} </button> | ||
|
||
<!-- <a href="{{ this_url }}">Webpage</a>--> | ||
</div> | ||
</form> | ||
{% else %} | ||
<div class="alert"> | ||
No property found | ||
</div> | ||
{% endif %} | ||
|
||
{% endblock %} |
Binary file not shown.
Oops, something went wrong.