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 / 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>
@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 / 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 / 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 / views.py
Created August 2, 2016 18:41
send SMS from Django app Plivo
import plivo
def send_sms_plivo(to, message):
"""
Send message via plivo service 0.0037 USD/sms; only outgoing
:return:
"""
auth_id = "....."
auth_token="..........."
@ragowthaman
ragowthaman / app.js
Created November 17, 2016 18:27
Django Webservice Angular Ionic App setup
.state('tab.referral-registration-form', {
url: '/register/referral/form',
views: {
'tab-dash': {
templateUrl: 'templates/dash-referral-registration/dash-referral_form.html',
controller: 'RegisterReferralFormCtrl'
}
}
})
.state('tab.referral-registration-ack', {
@ragowthaman
ragowthaman / models.py
Created November 23, 2016 06:11
Image upload via webservice Django/ionic
def get_resultfile_upload_destination(instance, filename):
return "complaint/00_generic/farmerid_{farmerid}/{file}".format(farmerid=instance.farmer.id, file=filename)
class Complaint(models.Model):
farmer = models.ForeignKey(Farmer)
file = models.FileField(blank=True, default='', upload_to=get_resultfile_upload_destination)
text = models.TextField(blank=True, default='')
timestamp = models.DateTimeField(auto_now=True)
@ragowthaman
ragowthaman / models.py
Created February 1, 2017 06:47
Create a webservice for BULK create
class Gyro(models.Model):
device = models.ForeignKey(Device)
ts = models.DateTimeField()
x = models.DecimalField(max_digits=18, decimal_places=18)
y = models.DecimalField(max_digits=18, decimal_places=18)
z = models.DecimalField(max_digits=18, decimal_places=18)
@ragowthaman
ragowthaman / list_consultants.html
Last active October 13, 2017 07:05
Display model data onto a template : URL -> Views(model) -> Template
{% extends "base_instance.html" %}
{% load i18n staticfiles %}
{% load templatetag_generic %}
{% block meta_title %}{% trans "Consultants" %}{% endblock %}
{% block title %}
{{ affiliation }} :
Consultant(s) List
{% endblock %}
@ragowthaman
ragowthaman / file.css
Created October 13, 2017 07:04
Setup Side nav side tabs
/* START setup tabs in side nav*/
.nav-tabs li.active > a,
.nav-tabs li.active > a:hover,
.nav-tabs li.active > a:focus {
color: #555555;
cursor: default;
background-color: #ffffff;
border: 1px solid #ffffff;
border-bottom-color: transparent;