This file contains 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
# common logic for *session_request. | |
sub _session_request { | |
my ($res, $path) = @_; | |
my $req = Catalyst::Utils::request($path); | |
$req->header('Cookie'=>$res->headers->{'set-cookie'}); | |
return $req; | |
} | |
# build request with session, using given response. | |
sub session_request { |
This file contains 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
# coding: utf-8 | |
import re | |
# いろいろなパターンを作るためのフォーマット | |
text_fmt = u""" | |
... | |
お客様の%(id_label)s/%(pw_label)sをご入力ください。 | |
... | |
%(id_label_prefix)s%(id_label)s%(label_suffix)s%(sep)s%(value_prefix)s%(id)s | |
%(pw_label_prefix)s%(pw_label)s%(label_suffix)s%(sep)s%(value_prefix)s%(pw)s |
This file contains 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
from json import dumps, loads | |
from UserDict import DictMixin | |
class JsonSerializedDict(DictMixin): | |
""" | |
>>> JSD = JsonSerializedDict | |
>>> d = JSD() | |
>>> print d | |
{} |
This file contains 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 os, binascii | |
def get_secret_key(key_filename): | |
key_path = os.path.join(BASE_DIR, 'conf', key_filename) | |
if not os.path.exists(key_path): | |
try: | |
umask_saved = os.umask(0277) | |
with open(key_path, 'wb') as key_file: | |
key_file.write(binascii.b2a_base64(os.urandom(64)).rstrip('=')) | |
finally: | |
os.umask(umask_saved) |
This file contains 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
<form id="delete_form" | |
method="POST" action="{% url 'delete_something' %}"> | |
{% csrf_token %} | |
<div> | |
<input type="hidden" name="delete" value=""> | |
<button id="delete_button" type="button">Delete</button> | |
<script> | |
$('#delete_button').on('click', | |
form_confirmation_factory('delete_form', | |
'Delete', 'Existing something will be removed.', 'OK', 'Cancel')) |
This file contains 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
<table> | |
{% for obj in page %} | |
<tr><td>{{ obj.blah }}</td></tr> | |
{% endfor %} | |
{% ifequal page.number page.paginator.num_pages %} | |
{% for padding in page.paginator.paddngs %} | |
<tr><td> </td></tr> | |
{% endfor %} | |
{% endifequal %} | |
</table> |
This file contains 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
<div class="container padding10"> | |
<h1>Add user</h1> | |
<div class="padding10"> | |
<form method="POST" action="{% url 'user_add' %}"> | |
{% csrf_token %} | |
<fieldset> | |
{% with field=form.is_superuser type='switch' %}{% include "share/form_field.html" %}{% endwith %} | |
{% with field=form.is_active type='switch' %}{% include "share/form_field.html" %}{% endwith %} | |
{% with field=form.username type='text' %}{% include "share/form_field.html" %}{% endwith %} | |
{% with field=form.password type='password' %}{% include "share/form_field.html" %}{% endwith %} |
This file contains 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
# coding: utf-8 | |
"""外部DBMS | |
""" | |
import os | |
from functools import wraps | |
from json import loads | |
from logging import getLogger | |
from threading import local |
This file contains 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
# coding: utf-8 | |
"""dataTables.js 用のクエリパーザ | |
""" | |
import re | |
class DataTablesQueryParser(object): | |
"""dataTables.js 用のクエリパーザ | |
""" | |
def __init__(self, request, column_map=dict(), method='POST'): |
This file contains 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
# coding: utf-8 | |
class MatchContext(object): | |
""" | |
>>> import re | |
>>> with MatchContext(re.match(r'(.)', 'a')) as context: | |
... print context.groups() | |
('a',) | |
>>> import re | |
>>> with MatchContext(re.match(r'(.)', '')) as context: |