Commit 1af40b6c authored by ibuler's avatar ibuler

[Update] 支持etag

parent 8ed3bb85
......@@ -35,12 +35,12 @@ class CommandFilterRuleSerializer(BulkOrgResourceModelSerializer):
fields = '__all__'
list_serializer_class = AdaptedBulkListSerializer
def validate_content(self, content):
tp = self.initial_data.get("type")
if tp == CommandFilterRule.TYPE_REGEX:
return content
if self.invalid_pattern.search(content):
invalid_char = self.invalid_pattern.pattern.replace('\\', '')
msg = _("Content should not be contain: {}").format(invalid_char)
raise serializers.ValidationError(msg)
return content
# def validate_content(self, content):
# tp = self.initial_data.get("type")
# if tp == CommandFilterRule.TYPE_REGEX:
# return content
# if self.invalid_pattern.search(content):
# invalid_char = self.invalid_pattern.pattern.replace('\\', '')
# msg = _("Content should not be contain: {}").format(invalid_char)
# raise serializers.ValidationError(msg)
# return content
......@@ -6,6 +6,8 @@ from django.core.cache import cache
from django.db.models import Q
from django.conf import settings
from rest_framework.views import Response
from django.utils.decorators import method_decorator
from django.views.decorators.http import condition
from django.utils.translation import ugettext as _
from common.utils import get_logger
......@@ -14,7 +16,7 @@ from ..utils import (
AssetPermissionUtil
)
from .. import const
from ..hands import Asset, Node, SystemUser, Label
from ..hands import Asset, Node, SystemUser
from .. import serializers
logger = get_logger(__name__)
......@@ -22,6 +24,17 @@ logger = get_logger(__name__)
__all__ = ['UserPermissionCacheMixin', 'GrantAssetsMixin', 'NodesWithUngroupMixin']
def get_etag(request, *args, **kwargs):
cache_policy = request.GET.get("cache_policy")
if cache_policy != '1':
return None
view = request.parser_context.get("view")
if not view:
return None
etag = view.get_meta_cache_id()
return etag
class UserPermissionCacheMixin:
cache_policy = '0'
RESP_CACHE_KEY = '_PERMISSION_RESPONSE_CACHE_V2_{}'
......@@ -96,6 +109,7 @@ class UserPermissionCacheMixin:
cache.set(key, response.data, self.CACHE_TIME)
logger.debug("Set response to cache: {}".format(key))
@method_decorator(condition(etag_func=get_etag))
def get(self, request, *args, **kwargs):
self.cache_policy = request.GET.get('cache_policy', '0')
......
......@@ -3,6 +3,7 @@
import uuid
from django.shortcuts import get_object_or_404
from rest_framework.views import APIView, Response
from rest_framework.generics import (
ListAPIView, get_object_or_404, RetrieveAPIView
)
......
......@@ -223,7 +223,7 @@ function formSubmit(props) {
return
}
$.each(errors, function (k, v) {
var fieldRef = props.form.find('input[name="' + k + '"]');
var fieldRef = props.form.find('[name="' + k + '"]');
var formGroupRef = fieldRef.parents('.form-group');
var parentRef = fieldRef.parent();
var helpBlockRef = parentRef.children('.help-block.error');
......@@ -237,7 +237,7 @@ function formSubmit(props) {
helpBlockRef.html(help_msg);
} else {
$.each(v, function (kk, vv) {
if (typeof errors === "object") {
if (typeof vv === "object") {
$.each(vv, function (kkk, vvv) {
noneFieldErrorMsg += " " + vvv + '<br/>';
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment