The founder of ctrleff demonstrates his methodology of web development that has evolved through the years to find the perfect balance between speed and scalability.
8. 2. scalable
collaborators will not be cursing (that much) at your shitty code base
9. 2. scalable
collaborators will not be cursing (that much) at your shitty code base
proven technology that is actually used by huge infrastructures. (no rewriting needed)
18. <body>
<div id="wrap">
<div class="bodycontainer" id="main">
<div class="left">
<img src="/static/images/menu_less_shadow.png"
class="appimg" />
</div>
<div class="right">
<div class="intro">
Hello You,
</div>
<div class="content">
<div class="graybox">
<span class="first">
Remember that dingy burger place around the
remote corner that was surprisingly cheap and good ?
</span>
<span class="meneither">
Me Neither.
</span>
<span class="bestfriend">
Nor your best friend.
</span>
<span class="last">
Soon you can. We are <text>launching
soon</text>.
</span>
</div>
</div>
19. Disgusting eh?
i wish...
i have a pythonic html. indentation for nesting.
something that's nice to work with css.
21. body
div#wrap
div.bodycontainer#main
div.left
> img.appimg src="/static/images/menu_less_shadow.png"
div.right
div.intro
Hello You,
div.content
div.graybox
span.first
Remember that dingy burger place around the
remote corner that was surprisingly cheap and good ?
span.meneither
Me Neither.
span.bestfriend
Nor your best friend.
span.last
Soon you can. We are <text>launching
soon</text>.
37. make it ReSTFUL
@app.route('/ad/get', methods=['POST'])
def get_ad():
"""
Retrieves all the information about an ad.
"""
from db import Ad
ad = Ad.query.get(request.form.get("id"))
if ad:
return jsonify({"res": ad.serialize })
else:
return jsonify({
"res": False,
"error": "We are unable to find any classifieds near
you!",
})
39. write the unit-tests
def test_ad_creation(self):
"""
Tests the API to create ads. Conveniently, also tests get ad api call.
"""
data = {
"long": randint(-360000000,360000000),
"lat": randint(-360000000,360000000),
"category": 5,
"email": "test@test.com",
"title": "Test Item " + random_string(),
"price": str(randint(0,1000)),
"image": open_file("sample_upload_pic.jpg"),
"description": " ".join([random_string() for i in range(10)]),
}
#create it
create_response = self.app.post("/ad/create", data=data)
response_dict = json.loads(create_response.data)
ad_id = response_dict["res"]
#retrieve it
res = self.app.post("/ad/get", data={"id": ad_id})
assert "id" in res.data