def spam(domain, color=None): device = get_current_device() request = get_current_request() return { 'color' : color or 'red', 'device': device, 'domain': domain, }
def get_or_cache_thumbnail_list(self): """ cacheがなければAPIgetする """ url_list = {} path = self.thumbnail_path_key() try: data = cache.get(path, None) if data: Log.debug("data %s" % data) url_list = msgpack.unpackb(data) Log.debug("data url_list %s" % url_list) else: request = get_current_request() request_params = [value for key,value in self.THUMBNAIL_MAPS.items()] request_params = (',').join(request_params) profile = People(request).get_myself(self.id, request_params, caching=False) for key, value in self.THUMBNAIL_MAPS.items(): url_list[value] = profile[value] Log.debug("new data url_list %s" % url_list) pack_data = msgpack.packb(url_list) Log.debug("pack_data url_list %s" % pack_data) cache.set(path, pack_data, timeout=self.CACHE_TIME) except: url_list = {} Log.debug("return url_list %s" % url_list) return url_list
def get_or_cache_thumbnail_list(self): """ cacheがなければAPIgetする """ url_list = {} path = self.thumbnail_path_key() try: data = cache.get(path, None) if data: Log.debug("data %s" % data) url_list = msgpack.unpackb(data) Log.debug("data url_list %s" % url_list) else: request = get_current_request() request_params = [ value for key, value in self.THUMBNAIL_MAPS.items() ] request_params = (',').join(request_params) profile = People(request).get_myself(self.id, request_params, caching=False) for key, value in self.THUMBNAIL_MAPS.items(): url_list[value] = profile[value] Log.debug("new data url_list %s" % url_list) pack_data = msgpack.packb(url_list) Log.debug("pack_data url_list %s" % pack_data) cache.set(path, pack_data, timeout=self.CACHE_TIME) except: url_list = {} Log.debug("return url_list %s" % url_list) return url_list
def spam(domain, color=None): device = get_current_device() request = get_current_request() return { 'color': color or 'red', 'device': device, 'domain': domain, }
def render(self, context): pager = self.pager.resolve(context) url_name = self.url_name.resolve(context) url_args = [url_arg.resolve(context) for url_arg in self.url_args] next_index = pager['current'].next_page_number() \ if pager['current'].has_next() else None prev_index = pager['current'].previous_page_number() \ if pager['current'].has_previous() else None try: replace_index = url_args.index('#PAGE#') except ValueError: replace_index = len(url_args) url_args.append('#PAGE#') pages = [] next_url = None prev_url = None for index in pager['navigator']: url_args[replace_index] = index # URL生成 device = get_current_device() request = get_current_request() reversed_url = reverse(url_name, args=url_args) if request and not device.is_featurephone: url = opensocial_session_url_convert(reversed_url, request) else: url = opensocial_url_convert(reversed_url) pages.append({ 'index': index, 'url': url, }) if next_index == index: next_url = url elif prev_index == index: prev_url = url pager_context = template.Context({ 'pager': pager, 'pages': pages, 'current_index': pager['current'].number, 'next_url': next_url, 'next_index': next_index, 'prev_url': prev_url, 'prev_index': prev_index, }) pager_template = template.loader.get_template(self.template_name) rendered_html = pager_template.render(pager_context) return rendered_html
def opensocial_url_with_domain(reversed_url): u""" SPの場合、リクエストからセッションIDを取得してURLを出す。 FPの場合は opensocial_url のように動作する。 だだし、引数は reverse された URLを取る。 例:: {% opensocial_url_with_domain <reverseされたURL> %} """ from mobilejp.middleware.mobile import get_current_request, get_current_device request = get_current_request() device = get_current_device() if request and not device.is_featurephone: url = opensocial_session_url_convert(reversed_url, request) else: url = opensocial_url_convert(reversed_url) return url
class URLNode(Node): """ URLNode """ def __init__(self, view_name, args, kwargs, asvar, converter, query=None): """ argument view_name: Letters args: list kwargs: dictionary asvar: converter: query:dictionary 引数 view_name : 文字列 args : リスト kwargs : 辞書 asvar : converter : query : 辞書 """ self.view_name = view_name self.args = args self.kwargs = kwargs self.asvar = asvar self.converter = converter self.query = query def render(self, context): """ Create URL and return it. argument: context return value: url or '' URLを生成し、返す 引数 context 返り値 url or '' """ #Log.debug("UrlNode 1") from django.core.urlresolvers import reverse, NoReverseMatch args = [arg.resolve(context) for arg in self.args] kwargs = dict([(smart_str(k,'ascii'), v.resolve(context)) for k, v in self.kwargs.items()]) try: #if view_name is included in context,use it. # view_nameがコンテキストに含まれる変数名ならば展開して使う view_name = resolve_variable(self.view_name, context) except template.VariableDoesNotExist: view_name = self.view_name if 'request' in context: request = context['request'] else: request = None url = '' try: url = reverse(view_name, args=args, kwargs=kwargs, current_app=context.current_app) except NoReverseMatch, e: if getattr(settings, 'ERROR_PAGE_MAIL', False): try: try: request_repr = repr(request) except: request_repr = "Request repr() unavailable" subject = 'opensocial_url_error' message = str(e) + '\r\n\r\n' + request_repr mail_admins(subject, message) except: pass if settings.SETTINGS_MODULE: project_name = settings.SETTINGS_MODULE.split('.')[0] try: url = reverse(project_name + '.' + view_name, args=args, kwargs=kwargs, current_app=context.current_app) except NoReverseMatch: if self.asvar is None: raise e else: if self.asvar is None: raise e from mobilejp.middleware.mobile import get_current_request, get_current_device request= get_current_request() device = get_current_device() if request and not device.is_featurephone: if self.query: url = opensocial_session_url_convert(url, request, resolve_variable(self.query, context)) else: url = opensocial_session_url_convert(url, request) # from mobilejp.middleware.mobile import get_is_webview # if get_is_webview(): # url += '&is_webview=True' else: if self.query: url = self.converter(url, resolve_variable(self.query, context)) else: url = self.converter(url) if self.asvar: context[self.asvar] = url return '' else: return url