##// END OF EJS Templates
Added basic SVG support
Added basic SVG support

File last commit:

r1240:92ddbd4a default
r1284:aa3c5b96 default
Show More
utils.py
83 lines | 2.3 KiB | text/x-python | PythonLexer
Ilyas
Added django-simple-capthca support...
r78 """
This module contains helper functions and helper classes.
"""
neko259
Moved imageboard settings to the boards settings module. Added setting to disable archive
r716 import time
neko259
Added centrifuge (websocket) support for thread autoupdate. Only websocket version is supported for now
r853 import hmac
neko259
Added ability to cache method result with additional arguments. Cache thread...
r1106
neko259
Started work on the method caching decorator (BB-57)
r957 from django.core.cache import cache
from django.db.models import Model
neko259
Moved imageboard settings to the boards settings module. Added setting to disable archive
r716
neko259
Rewriting views to class-based
r542 from django.utils import timezone
wnc_21
Added captcha support
r95
neko259
Fixed captcha design. Added setting to enable or disable captcha. This refs #39
r81 from neboard import settings
Ilyas
Added django-simple-capthca support...
r78
neko259
Added ability to cache method result with additional arguments. Cache thread...
r1106 CACHE_KEY_DELIMITER = '_'
neko259
Show moderator controls when downloading a single post over API. Removed duplicate code from get_post_data
r1109 PERMISSION_MODERATE = 'moderation'
wnc_21
Added captcha support
r95
neko259
Added ban middleware. Now banned user's won't cause load to the server.
r210 def get_client_ip(request):
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
if x_forwarded_for:
ip = x_forwarded_for.split(',')[-1].strip()
else:
ip = request.META.get('REMOTE_ADDR')
neko259
Rewriting views to class-based
r542 return ip
neko259
User notifications (BB-59)
r990 # TODO The output format is not epoch because it includes microseconds
neko259
Rewriting views to class-based
r542 def datetime_to_epoch(datetime):
return int(time.mktime(timezone.localtime(
datetime,timezone.get_current_timezone()).timetuple())
neko259
Moving neboard to python3 support (no python2 for now until we figure out how...
r765 * 1000000 + datetime.microsecond)
neko259
Added centrifuge (websocket) support for thread autoupdate. Only websocket version is supported for now
r853
def get_websocket_token(user_id='', timestamp=''):
"""
Create token to validate information provided by new connection.
"""
sign = hmac.new(settings.CENTRIFUGE_PROJECT_SECRET.encode())
sign.update(settings.CENTRIFUGE_PROJECT_ID.encode())
sign.update(user_id.encode())
sign.update(timestamp.encode())
token = sign.hexdigest()
neko259
Started work on the method caching decorator (BB-57)
r957 return token
neko259
Added ability to cache method result with additional arguments. Cache thread...
r1106 def cached_result(key_method=None):
neko259
Started work on the method caching decorator (BB-57)
r957 """
Caches method result in the Django's cache system, persisted by object name,
object name and model id if object is a Django model.
"""
neko259
Added ability to cache method result with additional arguments. Cache thread...
r1106 def _cached_result(function):
def inner_func(obj, *args, **kwargs):
# TODO Include method arguments to the cache key
cache_key_params = [obj.__class__.__name__, function.__name__]
if isinstance(obj, Model):
cache_key_params.append(str(obj.id))
if key_method is not None:
cache_key_params += [str(arg) for arg in key_method(obj)]
cache_key = CACHE_KEY_DELIMITER.join(cache_key_params)
neko259
Started work on the method caching decorator (BB-57)
r957
neko259
Added ability to cache method result with additional arguments. Cache thread...
r1106 persisted_result = cache.get(cache_key)
if persisted_result is not None:
result = persisted_result
else:
result = function(obj, *args, **kwargs)
cache.set(cache_key, result)
neko259
Started work on the method caching decorator (BB-57)
r957
neko259
Added ability to cache method result with additional arguments. Cache thread...
r1106 return result
neko259
Started work on the method caching decorator (BB-57)
r957
neko259
Added ability to cache method result with additional arguments. Cache thread...
r1106 return inner_func
return _cached_result
neko259
Show moderator controls when downloading a single post over API. Removed duplicate code from get_post_data
r1109
def is_moderator(request):
try:
moderate = request.user.has_perm(PERMISSION_MODERATE)
except AttributeError:
moderate = False
return moderate