Skip to content

Instantly share code, notes, and snippets.

View volgoweb's full-sized avatar

Dima Koldunov Python Developer volgoweb

  • Российская Федерация
View GitHub Profile
@volgoweb
volgoweb / some_view.py
Created August 18, 2017 19:55
Example of view in Django
class LotListView(ListView):
model = Article
context_object_name = 'articles'
def get_context_data(self, **kwargs):
context = super(LotListView, self).get_context_data(**kwargs)
context['articles_data'] = [self._get_article_view_model(a) for a in context['articles']]
return context
@staticmethod
@volgoweb
volgoweb / yesOrNo.py
Created May 12, 2017 10:01 — forked from garrettdreyfus/yesOrNo.py
Dead simple python function for getting a yes or no answer.
def yes_or_no(question):
reply = str(raw_input(question+' (y/n): ')).lower().strip()
if reply[0] == 'y':
return True
if reply[0] == 'n':
return False
else:
return yes_or_no("Uhhhh... please enter ")
def multipliers():
return (lambda x: i*x for i in range(4)]
print [m(2) for m in multipliers()]
@volgoweb
volgoweb / django_tornado_handler.py
Created February 17, 2016 19:44 — forked from bdarnell/django_tornado_handler.py
django_tornado_handler.py
# NOTE: This code was extracted from a larger class and has not been
# tested in this form. Caveat emptor.
import django.conf
import django.contrib.auth
import django.core.handlers.wsgi
import django.db
import django.utils.importlib
import httplib
import json
import logging
@volgoweb
volgoweb / db_insert multiple rows
Created September 25, 2013 09:33
Insert multiple rows into db, using drupal 7 pdo
$values = array(
array(
'title' => 'Example',
'uid' => 1,
'created' => REQUEST_TIME,
),
array(
'title' => 'Example 2',
'uid' => 1,
'created' => REQUEST_TIME,