from flask import request
from flask.ext.admin.contrib.sqla import ModelView
from flask.ext import login
from wtforms.fields import (
    TextAreaField,
    TextField,
)
from rdalchemy.rdalchemy import SmilesMolElement
from aggregatoradvisor import (
    admin,
    app,
    db,
)
from aggregatoradvisor.models import (
    Aggregator,
    Citation,
    ReportedAggregator,
)


class AuthenticatedModelView(ModelView):
    def is_accessible(self):
        return login.current_user.is_authenticated()


class AggregatorView(AuthenticatedModelView):
    column_list = ('id', 'smiles', 'logp', 'added', 'name')

    form_columns = ('structure', 'added', 'name', 'citations')
    #form_columns = ('structure', 'inchikey', 'added', 'name', 'citations')
    #form_extra_columns = ('inchikey',)
    form_exclude_columns = ('reports',)
    form_overrides = {'structure': TextField}


class CitationView(AuthenticatedModelView):
    column_list = ('id', 'short_reference', 'title')
    form_columns = ('title', 'short_reference', 'full_reference', 'doi', 'published', 'aggregators')
    form_exclude_columns = ('reports',)
    form_overrides = {'full_refrence': TextAreaField}


admin.add_view(AggregatorView(Aggregator, db.session))
admin.add_view(CitationView(Citation, db.session))
admin.add_view(AuthenticatedModelView(ReportedAggregator, db.session))

@@ -367,24 +367,94 @@
 egator,%0A)%0A%0A%0A
+# Require administrator access to admin forms (trivial but important)%0A
 class Authen
@@ -669,16 +669,19 @@
 ', '
-name
+inchikey
 ')%0A
-%0A
     
@@ -743,22 +743,29 @@
 s')%0A    
-#
 form_
+exclude_
 columns 
@@ -772,141 +772,54 @@
 = ('
-structure', 'inchikey', 'added', 'name', 'citations')%0A    #form_extra_columns = ('inchikey',)%0A    form_exclude_columns = ('reports',)
+reports',)        # Don't show report mappings
 %0A   
@@ -860,16 +860,55 @@
 xtField%7D
+  # Structure should be input as SMILES
 %0A%0A%0Aclass
@@ -1139,16 +1139,61 @@
 ports',)
+                 # Don't show report mappings
 %0A    for
@@ -1216,16 +1216,17 @@
 full_ref
+e
 rence': 
@@ -1239,16 +1239,54 @@
 eaField%7D
+  # Allow full_reference as multi-line
 %0A%0A%0Aadmin

Update admin_ui.py