Skip to content

Instantly share code, notes, and snippets.

View rdegges's full-sized avatar

Randall Degges rdegges

View GitHub Profile
from django.db import models
class Server(models.Model):
"""
This class represents a physical server.
"""
hostname = models.CharField('Server Name',
help_text = 'Hostname of the server.',
max_length = 50
)
from django import forms
class CreateServerForm(forms.Form):
"""
Create a new Server model.
"""
hostname = forms.CharField(
label = 'Server Name',
max_length = 50,
required = False
from django.db import models
from django.forms import ModelForm
class Server(models.Model):
"""
This class represents a physical server.
"""
hostname = models.CharField('Server Name',
help_text = 'Hostname of the server.',
max_length = 50
from myapp.models import Server
from myapp.models import ServerForm
from django.template import RequestContext
from django.shortcuts import render_to_response
def create_server(request):
"""
Create a new Server model.
"""
<?xml version="1.0" encoding="utf-8"?>
<response version="1.0">
<code>200</code>
<id>50</id>
</response>
<?xml version="1.0" encoding="utf-8"?>
<response version="1.0">
<code>400</code>
<errors>
<error>This API call requires a HTTP POST.</error>
</errors>
</response>
from lxml import etree
response = 'some xml response here'
try:
doc = etree.XML(response.strip())
code = doc.findtext('code')
print code
except etree.XMLSyntaxError:
print 'XML parsing error.'
from sys import exit
from lxml import etree
response = 'some xml response here'
try:
doc = etree.XML(response.strip())
code = doc.findtext('code')
print code
except etree.XMLSyntaxError:
##
# This gist is an update of the tropo python scripting tutorial page. It contains some
# suggested changes that would make the tutorial more familiar to native python
# developers.
#
# The tropo python scripting tutorial can be found at:
# https://www.tropo.com/docs/scripting/t_tutorial-python.htm
#
# NOTE: All changes I've proposed here are very simple (just removing parenthesis
# from if statements, mostly). All examples work well. The python style guide
/*
* test.c
*
* This example program demonstrates a weird way to reference array elements in
* C. All credit goes to the Stack Overflow 'Strangest language feature'
* discussion page:
* http://stackoverflow.com/questions/1995113/strangest-language-feature
*/
#include <stdio.h>