This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''Using the if else construct ''' | |
def function_if_else(condtion_variable): | |
if condtion_variable = -1: | |
print "Variable is equal to minus 1" | |
elif condtion_variable == 0: | |
print "Variable is equal to 0" | |
else condtion_variable =1: | |
print "Variable is equal to 1" | |
'''We can use dictionary ''' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
// Lets think template_variable is a django template variable | |
var is_condtion = {% if template_variable %}true{% else %}false{% endif %}; | |
if (is_condtion == false) | |
{ | |
alert("Execute this code if is_condition is true"); | |
// For example | |
<div> Hello How are you </div> | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Employee(models.Model): | |
name=models.CharField(max_length="50") | |
created_datetime = models.DateTimeField() | |
@staticmethod | |
def get_n_latest(n): | |
employeeList = Employee.objects.all().order_by('-created_datetime') | |
return employeeList[:n] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json, urllib | |
def get_latitude_longitude(address): | |
# assuming address object contains all the reuqried address fields | |
location = str(address.addressLine) +"+" +str(address.locality)+"+"+str(address.city)+ | |
"+"+ str(address.state)+"+"+str(address.country)+"+"+str(address.zipCode) | |
GEOLOC_URL = 'http://maps.googleapis.com/maps/api/geocode/json' | |
GEO_ARGS = {} | |
GEO_ARGS.update({'address': loc }) | |
url = GEOLOC_URL + '?' + urllib.urlencode(GEO_ARGS) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Data.OleDb; | |
using System.Data; | |
protected void Button1_Click(object sender, EventArgs e) | |
{ | |
string fileName = "C:\\Enter\\Location\\filename.xls"; // Need to enter the file location - note xls file extension | |
var conString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + | |
fileName + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\""; | |
/*In case you have .xlsx file try | |
conString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' model.py : showing the model created by python manage.py inspectdb > models.py ''' | |
class Test(models.Model): | |
datetime = models.DateTimeField(primary_key=True) # Time stamp value used as a dummy Primary Key for the model | |
value_1 = models.CharField(max_length=25) # Composite key of value_1 & value_2 | |
value_2 = models.CharField(max_length=15) # Composite key of value_1 & value_2 | |
class Meta: | |
managed = False | |
db_table = 'tbl_test' | |
verbose_name = 'Test Record' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DepartmentAdmin(admin.ModelAdmin): | |
def formfield_for_foreignkey(self, db_field, request, **kwargs): | |
if db_field.name == "employee": | |
''' The idea here is to read the string in request path as when django edits a field it has its key at the end of the string after add''' | |
request_path_array = filter(None,request.path.split('/')) | |
if request_path_array[len(request_path_array)-1] !="add": | |
'''Now get all the employee with particular department id''' | |
kwargs["queryset"] = Employee.objects.filter(departmentid=request_path_array[len(request_path_array)-1]) | |
return db_field.formfield(**kwargs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' changes to url.py ''' | |
urlpatterns = patterns('', | |
url(r'^employees/$',get_all_employees), | |
url(r'^employees/empdetail$',get_employee_by_id), | |
url(r'^employees/empsearch$',get_employee_search), | |
) | |
'''changes to views.py ###### ''' | |
def get_employee_by_id(request): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function onEmployeeClick(vEmpId) { | |
$.ajax({ | |
type: "GET", | |
url: "empdetail", | |
data: { | |
// Here we are passing the employee Id as input to the view in GET | |
'EMP_ID': vEmpId, | |
}, | |
success: function (data) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' In URLS.py ''' | |
from demoapp.views import get_employee | |
urlpatterns = patterns('', | |
('^get_employee/$',get_employee), | |
''' in views .py ''' | |
from demoapp.models import employee | |
def get_employee(request): | |
employee_id = request.GET['EMPID'] |
NewerOlder