Skip to content

Instantly share code, notes, and snippets.

@jgram925
jgram925 / Django Dynamically Add Formset Forms.html
Last active July 18, 2019 18:40
Django Dynamically Add Formset Forms.html
<form method='POST'>
{% csrf_token %}
{{ ssformset.management_form }}
{{ ssformset.non_form_errors }}
<div id="form-list">
{% for form in ssformset %}
<div id="form-set">
{% for field in form %}
<div class="form-group">
<div class="row">
@jgram925
jgram925 / Ajax Post.js
Last active July 17, 2019 15:11
Ajax Post.js
var pk_list = [];
$('#forecast_table').on('click', '#add_to_list', function(){
var this_val = parseInt($(this).val());
if($(this).html() == 'Add to List'){
$(this).removeClass('btn-primary').addClass('btn-danger').html('Remove from List')
pk_list.push(this_val);
}else{
$(this).addClass('btn-primary').removeClass('btn-danger').html('Add to List')
pk_list.splice($.inArray(this_val, pk_list), 1);
}
@jgram925
jgram925 / Docker & Docker-Compose Notes.md
Last active July 18, 2019 18:42
Docker & Docker-Compose Notes.md
@jgram925
jgram925 / Bootstrap Equal Columns.js
Last active May 21, 2019 17:17
Bootstrap Equal Columns.js
# Instantiated
function panelHeight(indexStart, greaterIndex){
if($(window).width() > 975){
var tallestHeight = 0;
for(i=indexStart; i<greaterIndex; i++){
var testHeight = $(".panel-body:eq(" + i + ")").outerHeight();
if(testHeight > tallestHeight){
tallestHeight = testHeight;
};
};
@jgram925
jgram925 / supervisor.conf
Last active June 15, 2019 17:49
supervisor.conf
[program:calib]
directory=/home/joswar/projects/calibration/
environment=DJANGO_SETTINGS_MODULE=calib_site.settings.testdev
command=/home/joswar/envs/calibration/bin/gunicorn -c conf/gunicorn_conf_prod.py calib_site.wsgi:application
redirect_stderr=true
autostart=true
autorestart=true
user=joswar
priority=990
stopsignal=KILL
@jgram925
jgram925 / nginx.conf
Last active June 15, 2019 17:50
nginx.conf
server {
server_name 10.6.0.85;
listen 112;
keepalive_timeout 5;
location /static {
alias /home/joswar/projects/calibration/static/;
autoindex on;
}
location /media {
alias /home/joswar/projects/calibration/media/;
@jgram925
jgram925 / gunicorn.py
Last active June 15, 2019 17:50
gunicorn.py
workers = 1
bind = '127.0.0.1:8085'
proc_name = 'calibration'
@jgram925
jgram925 / Dynamically Display Form Fields.md
Last active June 15, 2019 17:51
Dynamically Display Form Fields.md

Using jQuery to hide and show fields. Making sure to clear fields if they are not longer appropriate. Using Select2 with json and ajax is better than hard coding options.

Dynamically Display with Picklist

$(document).ready(function(){    

    // Hide SNMP fields if not already selected,  also Hides/Shows closest div with no Id or Class
    if($('#id_check_cmd').val() != 3) {
        $("#id_snmp_type").closest(".mws-form-col-5-8").hide()

$("#id_snmp_oid").closest(".mws-form-col-5-8").hide()