Skip to content

Commit

Permalink
Merging master into ach_issue30 (working on #30)
Browse files Browse the repository at this point in the history
  • Loading branch information
accaminero committed May 16, 2014
1 parent 7a19360 commit 53dbc54
Show file tree
Hide file tree
Showing 9 changed files with 781 additions and 222 deletions.
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')
48 changes: 46 additions & 2 deletions labmanager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,65 @@ class RLMS(Base, SBBase):
location = Column(Unicode(50), nullable = False)
url = Column(Unicode(300), nullable = False)
version = Column(Unicode(50), nullable = False)

# validated: true or false. True means that the last time that the validation process took place it was a success. The validation process involves that the labmanager admin checks the correctness of the credentials provided during the RLMS creation. False means that the last time that the validation took place, it did not succeed.

validated = Column(Boolean, default = False)

# newrlms is true for all the rlms when they are created. After the completion process (for HTTP RLMSs) or validation process (for all RLMSs), newrlms = false. newrlms is only usefull for HTTP, not for any of the other RLMS kinds.

newrlms = Column(Boolean, default = True)


configuration = Column(Unicode(10 * 1024))

def __init__(self, kind = None, url = None, location = None, version = None, configuration = '{}'):
def __init__(self, kind = None, url = None, location = None, version = None, newrlms = True, configuration = '{}'):
self.kind = kind
self.location = location
self.url = url
self.version = version
self.configuration = configuration

self.validated = False
self.newrlms = True

def __repr__(self):
return "RLMS(kind = %(rlmskind)r, url=%(rlmsurl)r, location=%(rlmslocation)r, version=%(rmlsversion)r, configuration=%(rmlsconfiguration)r)" % dict(rmlskind=self.kind, rmlsurl=self.url, rmlslocation=self.location, rlmsversion=self.version, rmlsconfiguration=self.configuration)
return "RLMS(kind = %(rlmskind)r, url=%(rlmsurl)r, location=%(rlmslocation)r, version=%(rmlsversion)r, validated=%(rlmsvalidated)r, newrlms=%(newrlms)r , configuration=%(rmlsconfiguration)r)" % dict(rmlskind=self.kind, rmlsurl=self.url, rmlslocation=self.location, rlmsversion=self.version, rlmsvalidated=self.validated, newrlms=self.newrlms, rmlsconfiguration=self.configuration)

def __unicode__(self):
return gettext(u"%(kind)s on %(location)s", kind=self.kind, location=self.location)

#########################################################
#
# HTTP_RLMS_Property: Properties that a HTTP RLMS may have
#
# 1 RLMS (of HTTP kind) may have 1 or multiple HTTP_RLMS_Properties
#

class HTTP_RLMS_Property(Base, SBBase):
__tablename__ = 'http_rlms_property'
__table_args__ = (UniqueConstraint('name', 'rlms_id'), )

id = Column(Integer, primary_key = True)
rlms_id = Column(Integer, ForeignKey('rlmss.id'), nullable = False)
name = Column(Unicode(50), nullable = False)
value = Column(Unicode(50), nullable = False, default = u"")

rlms = relation(RLMS.__name__, backref = backref('http_properties', order_by=id, cascade = 'all,delete'))

def __init__(self, name = None, value = None, rlms = None):


self.name = name
self.value = value
self.rlms = rlms

def __unicode__(self):
return u'%s with value %s at %s' % (self.name, self.value, self.rlms)




#######################################################################
#
# Laboratory
Expand Down
1 change: 1 addition & 0 deletions labmanager/rlms/ext/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import virtual
assert virtual is not None # pyflakes warning
import http

def setup():
from flask.exthook import ExtensionImporter
Expand Down
131 changes: 131 additions & 0 deletions labmanager/rlms/ext/http.py
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 labmanager/templates/labmanager_admin/rlms_properties_list.html
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 modified labmanager/translations/es/LC_MESSAGES/messages.mo
Binary file not shown.
Loading

0 comments on commit 53dbc54

Please sign in to comment.