Example #1
0
	def __init__(self, model, session, **kwargs):
		# new_label = '<img src="/static/img/new_yellow.ico"> Add a New Module' 
		new_label = '<img src="/static/img/New-16.png"> Add Module' 
		new_button = make_button(model, 'create', 'unit', new_label)
		del_button = make_button(model, 'delete', 'unit', 'Delete Unit', btn='btn-danger')
		self.form_edit_rules = (
		    "name", 
		    "display_name", 
		    "unit_coefficient", 
		    "is_fondamental", 
		    "order", 
		    rules.HTML( new_button  ),
		    rules.HTML( del_button ),
		)
		super(U, self).__init__(model, session, **kwargs)
Example #2
0
class PageAdmin(sqla.ModelView):
    '''form_overrides = {
      'output': HiddenField,
    }'''
    '''Add html for signature pad after name1...
    '''
    form_create_rules = (
        'name1',
        rules.HTML('''
    <p class="drawItDesc">Draw your signature</p>
    <ul class="sigNav">
      <li class="drawIt"><a href="#draw-it" >Draw It</a></li>
      <li class="clearButton"><a href="#clear">Clear</a></li>
    </ul>
    <div class="sig sigWrapper">
      <div class="typed"></div>
      <canvas class="pad" width="298" height="55"></canvas>
      <input type="hidden" name="output" class="output">
    </div><br>
    '''),
    )

    create_template = 'create.html'
    edit_template = 'edit.html'
    action_disallowed_list = ('delete')
Example #3
0
class ControlModelView(AuthorizedModelView):

    column_exclude_list = ['_cls']

    def _list_icon(view, context, model, name):
        if not model.icon:
            return ''

        return Markup(
            '<img src="{}" style="max-width: 30px; max-height: 30px;">'.format(
                model.get_icon_url()))

    column_formatters = {
        'icon': _list_icon,
    }

    form_rules = [
        'name', 'label', 'icon',
        rules.HTML('<div class="form-group">'
                   '<div class="col-md-10 col-md-offset-2">'
                   '<img id="iconImg" class="icon" src="#">'
                   '</div>'
                   '</div>')
    ]

    edit_template = 'admin/edit_control.html'
Example #4
0
class PageAdmin(sqla.ModelView):
    form_overrides = dict(text1=CKTextAreaField)

    form_create_rules = ('name1','text1', rules.HTML('''
    <p class="drawItDesc">Draw your signature</p>
    <ul class="sigNav">
      <li class="drawIt"><a href="#draw-it" >Draw It</a></li>
      <li class="clearButton"><a href="#clear">Clear</a></li>
    </ul>
    <div class="sig sigWrapper">
      <div class="typed"></div>
      <canvas class="pad" width="198" height="55"></canvas> 
          
    '''), 'output', rules.HTML('</div>'))
    
    create_template = 'create.html'
    edit_template = 'edit.html'
Example #5
0
class DepartamentsView(ModelView):
    column_filters = ['title']
    column_searchable_list = ('title', )
    form_subdocuments = {
        'personal': {
            'form_rules': ('name', rules.HTML('<hr>'), 'code')
        }
    }
Example #6
0
 def form_rules(self):
     rv = [
         "user_name",
         "email",
         rules.NestedRule([
             rules.HTML("<h4>" + lazy_gettext("Change Password") + "</h4>"),
             "old_password",
             "new_password",
             "new_password_confirm",
         ]),
         rules.HTML("<h4>" + lazy_gettext("Profile Details") + "</h4>"),
     ]
     for fn, _, __ in self.get_profile_fields():
         rv.append(_wrap_field(fn))
     if current_user.has_role("admin"):
         rv.extend(["active", "roles"])
     return rv
Example #7
0
	def __init__(self, model, session, **kwargs):
		# new_label = '<img src="/static/img/new_yellow.ico"> Add a New Percentage' 
		new_label = '<img src="/static/img/New-16.png"> Add Percentage' 
		new_button = make_button(model, 'create', 'module', new_label)
		del_button = make_button(model, 'delete', 'module', 'Delete Module', btn='btn-danger')
		self.form_edit_rules = (
		    "code", 
		    "name", 
		    "display_name", 
		    "coefficient", 
		    "credit", 
		    "time", 
		    "order", 
		    # "percentages",
		    rules.HTML( new_button  ),
		    rules.HTML( del_button ),
		)
		super(M, self).__init__(model, session, **kwargs)
Example #8
0
	def __init__(self, model, session, **kwargs):
		# new_label = '<img src="/static/img/new_yellow.ico"> Add a New Unit'
		new_label = '<img src="/static/img/New-16.png"> Add Unit' 
		new_button = make_button(model, 'create', 'semester', new_label)
		self.form_edit_rules = (
		    "name", 
		    "display_name", 
		    "semester", 
		    rules.HTML( new_button  ),
		)
		super(S, self).__init__(model, session, **kwargs)
Example #9
0
class CategoriesView(ModelView):
    column_filters = ['title']
    column_searchable_list = (
        'title',
        'description',
    )
    form_subdocuments = {
        'products': {
            'form_rules': ('title', rules.HTML('<hr>'), 'code')
        }
    }
Example #10
0
	def __init__(self, model, session, **kwargs): 
		del_button = make_button(model, 'delete', 'percentage', 'Delete Percentage', btn='btn-danger')
		self.form_edit_rules = (
		    # "name", 
		    "type", 
		    "percentage", 
		    "time", 
		    "rattrapable", 
		    "order", 
		    rules.HTML( del_button ),
		)
		super(P, self).__init__(model, session, **kwargs)
Example #11
0
class CartView(ModelView):

    form_subdocuments = {
        'cartItems': {
            'form_subdocuments':{
                None: {
                    'form_rules': ('_id', 'name', rules.HTML('<hr>')),
                    'form_widget_args': {
                        'name': {
                            'style': 'color: red'
                        }
                    }
                }
            }
        }
    }
Example #12
0
class PostView(ModelView):
    form_subdocuments = {
        'inner': {
            'form_subdocuments': {
                None: {
                    # Add <hr> at the end of the form
                    'form_rules': ('name', 'tag', 'value', rules.HTML('<hr>')),
                    'form_widget_args': {
                        'name': {
                            'style': 'color: red'
                        }
                    }
                }
            }
        }
    }
Example #13
0
class PostView(ModelView):
    column_filters = ['name']

    form_ajax_refs = {'user': {'fields': ['name']}}

    form_subdocuments = {
        'inner': {
            'form_subdocuments': {
                None: {
                    # Add <hr> at the of the form
                    'form_rules': ('name', 'tag', 'value', rules.HTML('<hr>')),
                    'form_widget_args': {
                        'name': {
                            'style': 'color: red'
                        }
                    }
                }
            }
        }
    }
Example #14
0
class RequirementView(ModelView):
    can_create = True
    can_edit = True
    column_filters = ['name']

    column_searchable_list = ['name']

    form_subdocuments = {
        'sub_reqs': {
            'form_subdocuments': {
                None: {
                    # Add <hr> at the end of the form
                    'form_rules': ('req_list', 'req_num', rules.HTML('<hr>'))
                }
            }
        }
    }

    def is_accessible(self):
        if not current_user.is_active or not current_user.is_authenticated:
            return False

        if current_user.has_role('superuser'):
            return True

        return False

    def _handle_view(self, name, **kwargs):
        """
        Override builtin _handle_view in order to redirect users when a view is not accessible.
        """
        if not self.is_accessible():
            if current_user.is_authenticated:
                # permission denied
                abort(403)
            else:
                # login
                return redirect(url_for('security.login', next=request.url))
Example #15
0
class CarAdmin(ModelView):
    form_rules = [
        rules.FieldSet(('desc', 'cartype', rules.HTML('<br><br>'), 'comment'),
                       'Details')
    ]
    form_widget_args = {
        'cartype': {
            'style': 'color: black'
        },
        'desc': {
            'style': 'color: black',
            #'readonly': True
        },
        'comment': {
            'rows': 4,
            'style': 'color: red',
        }
    }
    form_overrides = dict(cartype=RadioField)
    form_args = dict(cartype=dict(
        choices=[('Compact',
                  'Compact'), ('Mid-size',
                               'Mid-size'), ('Pickup-Truck', 'Pickup Truck')]))
Example #16
0
class SoftwareView(ModelView):

    list_template = 'admin/custom_list.html'

    column_type_formatters = MY_DEFAULT_FORMATTERS  # format dateTime without time

    # Columns (in list view):
    # -----------------------
    column_list = [
        'added_by_name', 'software_name', 'last_updated', 'domain',
        'is_pending'
    ]
    # column_exclude_list = ['description', 'long_description', 'date']

    column_labels = {
        'added_by_name': 'Added By',
        'is_pending': 'Pending',
    }

    column_filters = ['added_by_name', 'software_name', 'domain', 'is_pending']

    column_searchable_list = ('software_name', 'description')
    # column_editable_list = ['name', ]  # inline editing, has BUG, first ele

    # Others:
    # -------
    # can_create = True
    # can_edit = True
    # can_delete = False
    # page_size = 20  # the number of entries to display on the list view
    can_view_details = True
    can_export = True
    extra = None

    # list_template = 'admin/list.html'
    # create_template = 'create.html'
    edit_template = 'admin/custom_edit.html'

    # create_modal = True
    # edit_modal = True

    # Form options:
    # -------------
    form_excluded_columns = ['languages_lower']

    # form_choices = {        # is select
    #     'ui': [('Yes', 'Yes'), ('No', 'No')]
    # }

    # *** Rename tags here
    form_args = dict(
        added_by_name={'label': 'Name'},
        added_by_email={'label': 'Email'},
        is_SW_owner={'label': 'Are you the Software Owner'},
        mm_features={'label': ''},  # remove label
        # mm_features.qm_mm={'label': 'QM/MM'},  # not here, in form_subdocument
        qm_features={'label': ''},
        is_pending={'label': 'Pending'},
        required_citation={'label': 'Requested Citations(s)'},
        # changes how the input is parsed by strptime (12 hour time)
        # date_of_latest_version={'format': '%Y-%m-%d %I:%M %p'}
    )

    form_widget_args = dict(
        description={
            'rows': 4,
            'style': 'color: black'
        },
        long_description={
            'rows': 10,
            'style': 'color: black'
        },
        comments={
            'rows': 4,
            'style': 'color: black'
        },
        date_of_latest_version={  # http://www.daterangepicker.com/#options
            'data-max-date': datetime.now()
            # 'widget': DatePickerWidget(),  # not working
            # 'data-role': 'datepicker',
            # 'data-date-format': '%Y-%m-%d %I:%M %p',  # has to be in both here and in form_args
            # 'data-show-meridian': 'True'
        })

    form_subdocuments = dict(
        mm_features=dict(
            form_args={
                # 'qm_mm': {'label': 'QM/MM'}  # working
            },  # form_args
            form_rules=[
                'ensembles', 'free_energy_methods',
                'advanced_sampling_methods', 'forcefields', 'file_formats',
                'qm_mm', 'tags'
            ],
            # form_widget_args={
            #     'tags': {'class': 'selectpicker form-control', 'data-live-search': "true",
            #     'data-actions-box': "true", 'data-size': 7},
            # },
        ),
        qm_features=dict(
            form_args={},  # form_args
            form_rules=[
                # 'basis', 'element_coverage', 'other', 'tags'
            ],
        ))

    form_overrides = dict(
        # date_of_latest_version=DateTimeField?
        long_description=CKEditorField,
        description=CKEditorField,
        required_citation=CKEditorField)

    # Form display organization rules
    form_create_rules = [
        rules.HTML(
            '<h4>Please fill this form as complete as you can to be accessible through search.</h4>'
        ),
        rules.HTML(
            '<h5>(For any issues submitting this form contact us at [email protected])</h5>'
        ),
        rules.HTML('<hr>'),
        rules.Header('Your Information'),
        rules.HTML(
            '<h6>Your information will not be public. '
            'We will use it to contact you if we have questions about your submission, '
            'or want to clarify something.</h6>'),
        rules.FieldSet(('added_by_name', 'added_by_email', 'is_SW_owner')),
        rules.HTML('<hr>'),
        rules.Header('Availability'),
        'software_name',
        'official_website',
        'license',
        'price',
        'latest_version',
        'date_of_latest_version',
        'principal_contact_name',
        'principal_contact_email',
        rules.HTML('<hr>'),
        rules.Header('More Details'),
        'description',
        'long_description',
        'required_citation',
        'languages',
        'compilers',
        'gui',
        rules.HTML('<hr>'),
        rules.Header('Software Engineering'),
        'source_code_link',
        'executables',
        'code_management',
        'continuous_integration',
        'number_of_tests',
        'test_coverage',
        rules.HTML('<hr>'),
        rules.Header('Performance'),
        'parallel',
        'gpu',
        'knl_optimized',
        rules.HTML('<hr>'),
        rules.Header('Support Links'),
        'support_line',
        'documentation',
        'number_of_tutorials',
        'wiki',
        'forum',
        'mail_list',
        rules.HTML('<hr>'),
        'domain',
        rules.Header('MM Features'),
        'mm_features',
        rules.Header('QM Features'),
        'qm_features',
        rules.HTML('<hr>'),
        rules.HTML(
            '<h3>Do you have any comments or any other information?</h3>'),
        'comments',
        rules.HTML('<hr>'),
        'is_pending',
    ]

    # Use same rule set for edit page
    form_edit_rules = form_create_rules

    def scaffold_form(self):
        form_class = super(SoftwareView, self).scaffold_form()
        form_class.last_updated_by = ''  # mongoengine requires value for Strings, no None
        # form_class.extra = wf.SelectField('Extra', choices=[('c', 'c'),
        #                       ('cpp', 'CPP'), ('py', 'Python')])
        # form_class.tests = wf.DecimalField('Number of Tests')
        return form_class

    def is_accessible(self):
        return login.current_user.is_authenticated and login.current_user.can(
            Permission.MODERATE)

    # @action('get_edit_url', 'Edit URL', 'Get a private edit link')
    # def get_edit_url(self, ids):
    #     try:
    #         print('Id is: ', ids)
    #         url = 'admin/software/' + self.generate_software_id_token(ids)
    #         flash('Private URL to edit this software: ' + url)
    #
    #     except Exception as ex:
    #         if not self.handle_view_exception(ex):
    #             raise
    #
    #         flash(gettext('Failed to generate URL. %(error)s', error=str(ex)), 'error')

    def generate_software_id_token(self, id, expiration=3600 * 24 * 30):
        """Generate a token safe for URL
            Id: the id of the software in the DB
            expiration: in number of seconds (default to a month)
        """

        s = Serializer(current_app.config['SECRET_KEY'], expiration)
        return s.dumps(
            str(id),
            salt=current_app.config['EDIT_SOFTWARE_SALT'])  # .decode('utf-8')

    def confirm_software_id_token(self, token):
        s = Serializer(current_app.config['SECRET_KEY'])
        try:
            id = s.loads(
                token,  # .encode('utf-8'),
                salt=current_app.config['EDIT_SOFTWARE_SALT'],
                max_age=3600 * 24 * 30)
        except:
            return False

        return id
Example #17
0
class PostView(ModelView):
    def get_content(view, context, model, name):
        if not model.content:
            return ''

        return str(model.content)[:300]

    column_formatters = {'content': get_content}

    column_display_pk = True
    #edit_modal = True
    #create_modal = True

    form_overrides = dict(content=CKEditorField)
    create_template = 'admin/create_post.html'
    edit_template = 'admin/edit_post.html'
    #column_formatters = dict(content = lambda v, c, m, p: m)

    column_list = ('title', 'content', 'tags', 'status', 'create_time',
                   'modify_time', 'image')
    # column_labels = dict(id='ID',
    #                      title=u'标题',
    #                      content=u'内容',
    #                      author=u'作者',
    #                      tags=u'标签',
    #                      status=u'状态',
    #                      create_time=u'创建时间',
    #                      modify_time=u'修改时间')

    column_choices = {'status': [(0, 'draft'), (1, 'published')]}

    column_filters = ('title', 'content', 'create_time')

    column_searchable_list = (
        'content',
        'title',
    )

    column_sortable_list = ('create_time', 'modify_time')

    form_ajax_refs = {'tags': {'fields': ('name', )}}

    form_subdocuments = {
        'inner': {
            'form_subdocuments': {
                None: {
                    # Add <hr> at the end of the form
                    'form_rules':
                    ('created_at', 'body', 'author', rules.HTML('<hr>')),
                    'form_widget_args': {
                        'name': {
                            'style': 'color: red'
                        }
                    }
                }
            }
        }
    }

    def is_accessible(self):
        return current_user.is_authenticated