Skip to content

Instantly share code, notes, and snippets.

View thclark's full-sized avatar

Tom Clark thclark

View GitHub Profile
@thclark
thclark / LoadingPage.js
Last active February 21, 2019 22:29
Loading spinner, centred on a page, in React. Designed for use with creative-tim material kit pro, but could be adapted.
import classNames from 'classnames'
import PropTypes from 'prop-types'
import React, { Component } from 'react'
import withStyles from '@material-ui/core/styles/withStyles'
import CircularProgress from '@material-ui/core/CircularProgress'
import FullArea from 'components/FullArea'
import GridContainer from 'components/Grid/GridContainer'
import GridItem from 'components/Grid/GridItem'
@thclark
thclark / views
Created January 11, 2019 08:39
Django view for providing DataTables
from app.models import Manifest, ManifestFileRecord
from django_datatables_view.base_datatable_view import BaseDatatableView
logger = logging.getLogger(__name__)
class ManifestDatatableView(BaseDatatableView):
model = Manifest
columns = ['id', 'name', 'created', 'updated', 'tags', 'automan_params']
@thclark
thclark / gist:13794cf4ba5cea3c472dcad9f4039262
Created January 11, 2019 08:33
Jijnja2 Block for rendering a table with django-datatables-view
{% block view_scripts %}
<script type="text/javascript">
var MANIFEST_TABLE_URL = '{{ reverse('manifests:manifest-files-table', kwargs={'manifest_id': object.manifest.id if object.manifest else 'none'}) }}';
</script>
<script>
var table2 = $('#manifestfilestable').DataTable({
language: dt_language, // global variable defined in html
@thclark
thclark / n_plus_one_in_django.py
Last active February 15, 2018 11:20
An example of the N+1 database insertion problem in django
from django.db.models import CharField, Model, OneToOneField, AutoField, EmailField
class User(Model):
id = AutoField(primary_key=True) # The default Id field from django
username = CharField(max_length=30)
profile = OneToOneField(Profile, primary_key=True, related_name='user')
class Profile(Model):