<commit_before># -*- coding: UTF-8 -*-
# Copyright 2009-2015 <NAME>
# License: BSD (see file COPYING for details)
"""
See introduction in :doc:`/dev/ar`.

.. autosummary::

"""

import logging
logger = logging.getLogger(__name__)

import datetime
from copy import copy

from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import get_language
from django.utils import translation
from django import http
from django.core import exceptions

from lino.core.utils import obj2unicode

from lino.utils import AttrDict
from lino.utils import isiterable

from lino.core import constants

from lino.core.utils import navinfo
from lino.core.boundaction import BoundAction

from lino.utils.xmlgen.html import E

from lino.core.signals import on_ui_created, pre_ui_save
from lino.core.utils import ChangeWatcher


CATCHED_AJAX_EXCEPTIONS = (Warning, exceptions.ValidationError)


class ValidActionResponses:
    """These are the allowed keyword arguments for :meth:`ar.set_response
    <BaseRequest.set_response>`, and the action responses supported by
    :js:func:`Lino.handle_action_result` (defined in :xfile:`linolib.js`).

    This class is never instantiated, but used as a placeholder for
    these names and their documentation.

    """

    message = None
    """a string with a message to be shown to the user.
    """

    alert = None
    """ True to specify that the message is rather important
    and should alert and should be presented in a dialog box to be
    confirmed by the user.
    """

    success = None

    errors = None
    html = None
    rows = None
    data_record = None

    record_id = None
    refresh = None
    refresh_all = None
    close_window = None
    record_deleted = None
    xcallback = None
    open_url = None
    open_davlink_url = None
    info_message = None
    warning_message = None
    "deprecated"

    eval_js = None
    active_tab = None

    detail_handler_name = None
    """The name of the detail handler to be used.  Application code should
    not need to use this.  It is automatically set by
    :meth:`ActorRequest.goto_instance`.

    """


# ACTION_RESPONSES = frozenset((
#     'message', 'success', 'alert',
#     'errors',
#     'html',
#     'rows',
#     'data_record',
#     'detail_handler_name',
#     'record_id',
#     'refresh', 'refresh_all',
#     'close_window',
#     'record_deleted',
#     'xcallback',
#     'open_url',
#     'open_davlink_url',
#     'info_message',
#     'warning_message',  # deprecated
#     'eval_js',
#     'active_tab'))


class VirtualRow(object):

    def __init__(self, **kw):
        self.update(**kw)

    def update(self, **kw):
        for k, v in kw.items():
            setattr(self, k, v)

    def get_row_permission(self, ar, state, ba):
        if ba.action.readonly:
            return True
        return False


class PhantomRow(VirtualRow):

    def __init__(self, request, **kw):
        self._ar = request
        VirtualRow.__init__(self, **kw)

    def __unicode__(self):
        return unicode(self._ar.get_action_title())


inheritable_attrs = frozenset(
    'user subst_user renderer requesting_panel master_instance'.split())


class BaseRequest(object):
    """Base class of all action requests.

    """
    user = None
    subst_user = None

    renderer = None
    """The renderer to use when processing this request."""

    actor = None
    action_param_values = None
    param_values = None
    bound_action = None
    known_values = {}
    master_instance = None

    tableattrs = dict(cellspacing="3px", bgcolor="#ffffff", width="100%")
    # ~ cellattrs = dict(align="center",valign="middle",bgcolor="#eeeeee")
    cellattrs = dict(align="left", valign="top", bgcolor="#eeeeee")
    # ~ cellattrs = dict(align="left",valign="top",bgcolor="#d0def0")

    request = None
    """The incoming Django HttpRequest object which caused this action
    request.

    """

    selected_rows = []
    content_type = 'application/json'
    requesting_panel = None

    def __init__(self, request=None, parent=None, **kw):
        self.request = request
        self.response = dict()
        if request is not None:
            if request.method in ('PUT', 'DELETE'):
                rqdata = http.QueryDict(request.body)
                # note that `body` was named `raw_post_data` before Django 1.4
                #~ print 20130222, rqdata
            else:
                rqdata = request.REQUEST
            kw = self.parse_req(request, rqdata, **kw)
        if parent is not None:
            for k in inheritable_attrs:
                if k in kw:
                    if kw[k] is None:
                        raise Exception("%s : %s=None" % (kw, k))
                else:
                    kw[k] = getattr(parent, k)
            kv = kw.setdefault('known_values', {})<commit_msg>The warning "RemovedInDjango19Warning: `request.REQUEST` is deprecated"  fixed #38<commit_after># -*- coding: UTF-8 -*-
# Copyright 2009-2015 <NAME>
# License: BSD (see file COPYING for details)
"""
See introduction in :doc:`/dev/ar`.

.. autosummary::

"""

import logging
logger = logging.getLogger(__name__)

import datetime
from copy import copy

from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import get_language
from django.utils import translation
from django import http
from django.core import exceptions

from lino.core.utils import obj2unicode

from lino.utils import AttrDict
from lino.utils import isiterable

from lino.core import constants

from lino.core.utils import navinfo
from lino.core.boundaction import BoundAction

from lino.utils.xmlgen.html import E

from lino.core.signals import on_ui_created, pre_ui_save
from lino.core.utils import ChangeWatcher


CATCHED_AJAX_EXCEPTIONS = (Warning, exceptions.ValidationError)


class ValidActionResponses:
    """These are the allowed keyword arguments for :meth:`ar.set_response
    <BaseRequest.set_response>`, and the action responses supported by
    :js:func:`Lino.handle_action_result` (defined in :xfile:`linolib.js`).

    This class is never instantiated, but used as a placeholder for
    these names and their documentation.

    """

    message = None
    """a string with a message to be shown to the user.
    """

    alert = None
    """ True to specify that the message is rather important
    and should alert and should be presented in a dialog box to be
    confirmed by the user.
    """

    success = None

    errors = None
    html = None
    rows = None
    data_record = None

    record_id = None
    refresh = None
    refresh_all = None
    close_window = None
    record_deleted = None
    xcallback = None
    open_url = None
    open_davlink_url = None
    info_message = None
    warning_message = None
    "deprecated"

    eval_js = None
    active_tab = None

    detail_handler_name = None
    """The name of the detail handler to be used.  Application code should
    not need to use this.  It is automatically set by
    :meth:`ActorRequest.goto_instance`.

    """


# ACTION_RESPONSES = frozenset((
#     'message', 'success', 'alert',
#     'errors',
#     'html',
#     'rows',
#     'data_record',
#     'detail_handler_name',
#     'record_id',
#     'refresh', 'refresh_all',
#     'close_window',
#     'record_deleted',
#     'xcallback',
#     'open_url',
#     'open_davlink_url',
#     'info_message',
#     'warning_message',  # deprecated
#     'eval_js',
#     'active_tab'))


class VirtualRow(object):

    def __init__(self, **kw):
        self.update(**kw)

    def update(self, **kw):
        for k, v in kw.items():
            setattr(self, k, v)

    def get_row_permission(self, ar, state, ba):
        if ba.action.readonly:
            return True
        return False


class PhantomRow(VirtualRow):

    def __init__(self, request, **kw):
        self._ar = request
        VirtualRow.__init__(self, **kw)

    def __unicode__(self):
        return unicode(self._ar.get_action_title())


inheritable_attrs = frozenset(
    'user subst_user renderer requesting_panel master_instance'.split())


class BaseRequest(object):
    """Base class of all action requests.

    """
    user = None
    subst_user = None

    renderer = None
    """The renderer to use when processing this request."""

    actor = None
    action_param_values = None
    param_values = None
    bound_action = None
    known_values = {}
    master_instance = None

    tableattrs = dict(cellspacing="3px", bgcolor="#ffffff", width="100%")
    # ~ cellattrs = dict(align="center",valign="middle",bgcolor="#eeeeee")
    cellattrs = dict(align="left", valign="top", bgcolor="#eeeeee")
    # ~ cellattrs = dict(align="left",valign="top",bgcolor="#d0def0")

    request = None
    """The incoming Django HttpRequest object which caused this action
    request.

    """

    selected_rows = []
    content_type = 'application/json'
    requesting_panel = None

    def __init__(self, request=None, parent=None, **kw):
        self.request = request
        self.response = dict()
        if request is not None:
            if request.method in ('PUT', 'DELETE'):
                rqdata = http.QueryDict(request.body)
                # note that `body` was named `raw_post_data` before Django 1.4
                #~ print 20130222, rqdata
            else:
                # rqdata = request.REQUEST
                rqdata = getattr(request,request.method)
            kw = self.parse_req(request, rqdata, **kw)
        if parent is not None:
            for k in inheritable_attrs:
                if k in kw:
                    if kw[k] is None:
                        raise Exception("%s : %s=None" % (kw, k))
                else:
                    kw[k] = getattr(parent, k)
            kv = kw.setdefault('known_values', {})
{'fraction_non_alphanumeric': 0.10283114256825075, 'fraction_numerical': 0.005662285136501517, 'mean_word_length': 2.717023675310034, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6235194', 'n_tokens_mistral': 3039, 'n_tokens_neox': 2876, 'n_words': 875}