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
| from .models import Post, Category | |
| from .decorators import action_form | |
| class PostCategoryForm(forms.Form): | |
| title = 'Update category for the selected posts' | |
| category = forms.ModelChoiceField(queryset=Category.objects.all()) | |
| @admin.register(Post) |
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
| # encoding: utf-8 | |
| import os | |
| import shelve | |
| import boto.glacier | |
| import boto | |
| from boto.glacier.exceptions import UnexpectedHTTPResponseError | |
| ACCESS_KEY_ID = "XXXXXXXXXXXXX" | |
| SECRET_ACCESS_KEY = "XXXXXXXXXXX" | |
| SHELVE_FILE = os.path.expanduser("~/.glaciervault.db") |
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
| # encoding: utf-8 | |
| from __future__ import unicode_literals | |
| import os | |
| import requests | |
| import sys | |
| def get_google_auth_session(username, password): | |
| session = requests.Session() |
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
| def set_filter_operation_on_model(model_query_set_object, field, value, operator ): | |
| if operator == FilterOperators.EQ: | |
| kwargs = {'{0}__{1}'.format(field, 'exact'): value ,} | |
| elif operator == FilterOperators.CONTAINS: | |
| kwargs = {'{0}__{1}'.format(field, 'contains'): value ,} | |
| elif operator == FilterOperators.IS_NOT: | |
| kwargs = {'{0}__{1}'.format(field, 'exact') : value, } | |
| return model_quesry_set_object.filter(~Q(**kwargs)) | |
| return model_quesry_set_object.filter(**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
| def get_ip_address_from_request(request): | |
| """ Makes the best attempt to get the client's real IP or return the loopback """ | |
| PRIVATE_IPS_PREFIX = ('10.', '172.', '192.', '127.') | |
| ip_address = '' | |
| x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR', '') | |
| if x_forwarded_for and ',' not in x_forwarded_for: | |
| if not x_forwarded_for.startswith(PRIVATE_IPS_PREFIX) and is_valid_ip(x_forwarded_for): | |
| ip_address = x_forwarded_for.strip() | |
| else: | |
| ips = [ip.strip() for ip in x_forwarded_for.split(',')] |
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 type="text/javascript"> | |
| jQuery(document).ready(function($){ | |
| $('<div id="show-filters" style="float: right;"><a href="#">Show Filters</a></p>').prependTo('div.actions'); | |
| $('#show-filters').hide(); | |
| $('#changelist-filter h2').html('<a style="color: white;" id="hide-filters" href="#">Filter →</a>'); | |
| $('#show-filters').click(function() { | |
| $('#changelist-filter').show('fast'); | |
| $('#changelist').addClass('filtered'); | |
| $('#show-filters').hide(); |