Skip to content

Instantly share code, notes, and snippets.

View ragowthaman's full-sized avatar
🎯
Focusing

Gowthaman Ramasamy ragowthaman

🎯
Focusing
  • Seattle BioMed
  • Seattle WA USA
View GitHub Profile
@ragowthaman
ragowthaman / settings.py
Created August 2, 2016 08:16
Enable Django app with emailing (send_mail + gmail)
# Email/gmail configuration
# console.EmailBackend is to test the email on console in dev mode
# comment next line to spit emails on console for testing (of course comment the line next to it)
# EMAIL_BACKEND='django.core.mail.backends.console.EmailBackend'
# smtp.EmailBackend is for the production server
EMAIL_BACKEND='django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST='smtp.gmail.com'
EMAIL_PORT=587
EMAIL_HOST_USER='[email protected]'
@ragowthaman
ragowthaman / ajax.py
Created July 7, 2016 09:38
How to delete a list element via ajax
def delete_practice(request):
if request.is_ajax and request.POST:
kb_practice_id = request.POST.get('kb_practice_id')
Practice.objects.get(id=kb_practice_id).delete()
return HttpResponse(json.dumps({}), content_type="application/json")
else:
raise Http404
@ragowthaman
ragowthaman / ajax.py
Created July 7, 2016 09:00
A gist to add an list item to existing list via ajax
def add_new_practice(request):
if request.is_ajax and request.POST:
protocol_id = request.POST.get('protocol_id')
form = PracticeModelForm(request.POST)
if form.is_valid():
practice_object = Practice(protocol=Protocol.objects.get(id=protocol_id))
form = PracticeModelForm(request.POST, instance=practice_object)
form.save()
return HttpResponse(json.dumps({}))
@ragowthaman
ragowthaman / list_kb_ practices.html
Created July 7, 2016 05:51
Button to invoke action when clicked
<TH><span class="add-new-practice">Add New Practice</span></TH>