Improvements for limit tags

pull/1137/head
Ozzieisaacs 4 years ago
parent 1da4efec86
commit d9adb4fc94

@ -207,7 +207,6 @@ def edit_domain(allow):
# value: 'superuser!' //new value
vals = request.form.to_dict()
answer = ub.session.query(ub.Registration).filter(ub.Registration.id == vals['pk']).first()
# domain_name = request.args.get('domain')
answer.domain = vals['value'].replace('*', '%').replace('?', '_').lower()
ub.session.commit()
return ""
@ -252,6 +251,118 @@ def list_domain(allow):
response.headers["Content-Type"] = "application/json; charset=utf-8"
return response
@admi.route("/ajax/editrestriction/<int:type>", methods=['POST'])
@login_required
@admin_required
def edit_restriction(type):
element = request.form.to_dict()
if element['id'].startswith('a'):
if type == 0: # Tags as template
elementlist = config.list_restricted_tags()
elementlist[id[1:]]=element['Element']
config.config_restricted_tags = ','.join(elementlist)
if type == 1: # CustomC
pass
if type == 2: # Tags per user
pass
if element['type'].startswith('d'):
if type == 0: # Tags as template
elementlist = config.list_allowed_tags()
elementlist[id[1:]]=element['Element']
config.config_restricted_tags = ','.join(elementlist)
if type == 1: # CustomC
pass
if type == 2: # Tags per user
pass
config.save()
return ""
@admi.route("/ajax/addrestriction/<int:type>", methods=['POST'])
@login_required
@admin_required
def add_restriction(type):
log.info("Hit: " + str(type))
element = request.form.to_dict()
if type == 0: # Tags as template
if 'submit_allow' in element:
elementlist = config.list_allowed_tags()
if elementlist == ['']:
elementlist= []
if not element['add_element'] in elementlist:
elementlist += [element['add_element']]
config.config_allowed_tags = ','.join(elementlist)
elif 'submit_deny' in element:
elementlist = config.list_restricted_tags()
if elementlist == ['']:
elementlist= []
if not element['add_element'] in elementlist:
elementlist+=[element['add_element']]
config.config_restricted_tags = ','.join(elementlist)
config.save()
if type == 1: # CustomC
pass
if type == 2: # Tags per user
pass
return ""
@admi.route("/ajax/deleterestriction/<int:type>", methods=['POST'])
@login_required
@admin_required
def delete_restriction(type):
element = request.form.to_dict()
if int(element['type']) == 1:
if type == 0: # Tags as template
if element['id'].startswith('a'):
elementlist = config.list_allowed_tags()
if element['Element'] in elementlist:
elementlist.remove(element['Element'])
config.config_allowed_tags = ','.join(elementlist)
elif element['id'].startswith('d'):
elementlist = config.list_restricted_tags()
if element['Element'] in elementlist:
elementlist.remove(element['Element'])
config.config_restricted_tags = ','.join(elementlist)
config.save()
if type == 1: # CustomC
pass
if type == 2: # Tags per user
pass
if int(element['type'])== 2:
if type == 0: # Tags as template
elementlist = config.list_allowed_tags()
if not element['Element'] in elementlist:
elementlist+=element['Element']
config.config_restricted_tags = ','.join(elementlist)
if type == 1: # CustomC
pass
if type == 2: # Tags per user
pass
return ""
@admi.route("/ajax/listrestriction/<int:type>")
@login_required
@admin_required
def list_restriction(type):
if type == 0: # Tags as template
#for x, i in enumerate(config.list_restricted_tags()):
# if x != '':
# {'Element': x, 'type': '1', 'id': 'a' + str(i)}
restrict = [{'Element': x, 'type':'1', 'id': 'd'+str(i) } for i,x in enumerate(config.list_restricted_tags()) if x != '' ]
allow = [{'Element': x, 'type':'1', 'id': 'a'+str(i) } for i,x in enumerate(config.list_allowed_tags()) if x != '']
json_dumps = restrict + allow
elif type == 1: # CustomC
json_dumps = ""
elif type == 2: # Tags per user
json_dumps = ""
else:
json_dumps = ""
js = json.dumps(json_dumps)
response = make_response(js.replace("'", '"'))
response.headers["Content-Type"] = "application/json; charset=utf-8"
return response
@admi.route("/config", methods=["GET", "POST"])
@unconfigured
@ -306,7 +417,7 @@ def _configuration_update_helper():
reboot_required |= _config_string("config_certfile")
if config.config_certfile and not os.path.isfile(config.config_certfile):
return _configuration_result('Certfile location is not valid, please enter correct path', gdriveError)
_config_string("config_server_url")
_config_checkbox_int("config_uploading")

@ -74,6 +74,7 @@ class _Settings(_Base):
config_default_show = Column(SmallInteger, default=6143)
config_columns_to_ignore = Column(String)
config_restricted_tags = Column(String)
config_allowed_tags = Column(String)
config_restricted_column = Column(SmallInteger, default=0)
config_restricted_column_value = Column(String)
config_allowed_column_value = Column(String)
@ -180,12 +181,21 @@ class _ConfigSQL(object):
def show_detail_random(self):
return self.show_element_new_user(constants.DETAIL_RANDOM)
'''def show_mature_content(self):
return self.show_element_new_user(constants.MATURE_CONTENT)'''
def list_restricted_tags(self):
mct = self.config_restricted_tags.split(",")
return [t.strip() for t in mct]
'''def mature_content_tags(self):
mct = self.config_mature_content_tags.split(",")
return [t.strip() for t in mct]'''
def list_allowed_tags(self):
mct = self.config_allowed_tags.split(",")
return [t.strip() for t in mct]
def list_restricted_column_values(self):
mct = self.config_restricted_column_values().split(",")
return [t.strip() for t in mct]
def list_allowed_column_values(self):
mct = self.config_allowed_column_values().split(",")
return [t.strip() for t in mct]
def get_log_level(self):
return logger.get_level_name(self.config_log_level)

@ -24,7 +24,7 @@ import signal
import socket
try:
from gevent.pyswsgi import WSGIServer
from gevent.pywsgi import WSGIServer
from gevent.pool import Pool
from gevent import __version__ as _version
VERSION = 'Gevent ' + _version

@ -93,6 +93,73 @@ $(function() {
var domainId = $(e.relatedTarget).data("domain-id");
$(e.currentTarget).find("#btndeletedomain").data("domainId", domainId);
});
$('#restrictModal').on('hidden.bs.modal', function () {
$('#restrict-elements-table').bootstrapTable('destroy');
});
// $('#table').bootstrapTable('destroy');
function startTable(type){
$("#restrict-elements-table").bootstrapTable({
formatNoMatches: function () {
return "";
},
url:window.location.pathname + "/../../ajax/listrestriction/" + type,
onClickCell: function (field, value, row, $element) {
// ...
if(field == 3){
$.ajax ({
type: 'Post',
data: 'id=' + row.id + '&type=' + row.type + "&Element=" + row.Element,
url: window.location.pathname + "/../../ajax/deleterestriction/" + type,
async: true,
timeout: 900,
success:function(data) {
$.ajax({
method:"get",
url: window.location.pathname + "/../../ajax/listrestriction/"+type,
async: true,
timeout: 900,
success:function(data) {
$("#restrict-elements-table").bootstrapTable("load", data);
}
});
}
});
}
},
striped: false
});
$("[id^=submit_]").click(function(event) {
event.preventDefault();
console.log($(this)[0].name)
$.ajax({
url: window.location.pathname + "/../../ajax/addrestriction/"+type,
type: 'Post',
data: $(this).closest("form").serialize() + "&" + $(this)[0].name + "=",
success: function () {
$.ajax ({
method:"get",
url: window.location.pathname + "/../../ajax/listrestriction/"+type,
async: true,
timeout: 900,
success:function(data) {
$("#restrict-elements-table").bootstrapTable("load", data);
}
});
}
});
return;
});
}
$('#get_column_values').on('click',function()
{
startTable(1);
});
$('#get_tags').on('click',function()
{
startTable(0);
});
});
/* Function for deleting domain restrictions */
@ -104,3 +171,12 @@ function TableActions (value, row, index) {
"</a>"
].join("");
}
/* Function for deleting domain restrictions */
function RestrictionActions (value, row, index) {
return [
"<div class=\"danger remove\" data-restriction-id=\"" + row.id + "\" title=\"Remove\">",
"<i class=\"glyphicon glyphicon-trash\"></i>",
"</div>"
].join("");
}

@ -1,8 +1,6 @@
{% extends "layout.html" %}
{% block body %}
{% if book %}
<div class="col-sm-3 col-lg-3 col-xs-12">
<div class="cover">
<img src="{{ url_for('web.get_cover', book_id=book.id) }}" alt="{{ book.title }}"/>

@ -1,4 +1,8 @@
{% extends "layout.html" %}
{% block header %}
<link href="{{ url_for('static', filename='css/libs/bootstrap-table.min.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='css/libs/bootstrap-editable.css') }}" rel="stylesheet">
{% endblock %}
{% block body %}
<div class="discover">
<h2>{{title}}</h2>
@ -111,14 +115,17 @@
<input type="checkbox" name="edit_shelf_role" id="edit_shelf_role" {% if conf.role_edit_shelfs() %}checked{% endif %}>
<label for="edit_shelf_role">{{_('Allow Editing Public Shelfs')}}</label>
</div>
<div class="form-group">
<!--div class="form-group">
<label for="config_restricted_tags">{{_('Restrict Tags')}}</label>
<input type="text" class="form-control" name="config_restricted_tags" id="config_restricted_tags" value="{{ conf.config_restricted_tags if conf.config_restricted_tags != None }}" autocomplete="off">
</div>
<div class="form-group">
</div-->
<a href="#" id="get_tags" class="btn btn-default" data-toggle="modal" data-target="#restrictModal">{{_('Add allowed/denied Tags')}}</a>
<a href="#" id="get_column_values" class="btn btn-default" data-toggle="modal" data-target="#restrictModal">{{_('Add allowed/denied custom column values')}}</a>
<!--div class="form-group">
<label for="config_restricted_column_value">{{_('Restricted Column Content')}}</label>
<input type="text" class="form-control" name="config_restricted_column_value" id="config_restricted_column_value" value="{{ conf.config_restricted_column_value if conf.config_restricted_column_value != None }}" autocomplete="off">
</div>
</div-->
</div>
</div>
</div>
@ -155,6 +162,9 @@
</form>
</div>
{% endblock %}
{% block modal %}
{{ restrict_modal() }}
{% endblock %}
{% block js %}
<script type="text/javascript">
$('.collapse').on('shown.bs.collapse', function(){
@ -163,4 +173,8 @@
$(this).parent().find(".glyphicon-minus").removeClass("glyphicon-minus").addClass("glyphicon-plus");
});
</script>
<script src="{{ url_for('static', filename='js/libs/bootstrap-table/bootstrap-table.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/libs/bootstrap-table/bootstrap-table-editable.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/libs/bootstrap-table/bootstrap-editable.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/table.js') }}"></script>
{% endblock %}

@ -1,3 +1,4 @@
{% from 'modal_restriction.html' import restrict_modal %}
<!DOCTYPE html>
<html lang="{{ g.user.locale }}">
<head>
@ -229,7 +230,6 @@
});
});
</script>
{% block js %}{% endblock %}
</body>
</html>

@ -0,0 +1,36 @@
{% macro restrict_modal() %}
<div class="modal fade" id="restrictModal" tabindex="-1" role="dialog" aria-labelledby="restrictModalLabel">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="metaModalLabel">{{_('Select allowed/restricted Tags')}}</h4>
</div>
<div class="modal-body">
<table class="table table-no-bordered" id="restrict-elements-table" data-id-field="id" data-show-header="false" data-editable-mode="inline">
<thead>
<tr>
<th data-field="Element" id="Element" data-editable-type="text" data-editable-url="{{ url_for('admin.edit_restriction', type = 0)}}" data-editable="true" data-editable-title="{{_('Enter Tag')}}"></th>
<th data-field="type" id="type" data-visible="false"></th>
<th data-field="id" id="id" data-visible="false"></th>
<th data-align="right" data-formatter="RestrictionActions"></th>
</tr>
</thead>
</table>
<form id="add_restriction" action="" method="POST">
<div class="form-group required">
<label for="add_element">{{_('Add Tag')}}</label>
<input type="text" class="form-control" name="add_element" id="add_element" >
</div>
<div class="form-group required">
<input type="button" class="btn btn-default" value="{{_('Allow')}}" name="submit_allow" id="submit_allow" data-dismiss="static">
<input type="button" class="btn btn-default" value="{{_('Deny')}}" name="submit_deny" id="submit_restrict" data-dismiss="static">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{{_('Close')}}</button>
</div>
</div>
</div>
</div>
{% endmacro %}

@ -155,3 +155,12 @@
{% endif %}
</div>
{% endblock %}
{% block modal %}
{{ restrict_modal() }}
{% endblock %}
{% block js %}
<script src="{{ url_for('static', filename='js/libs/bootstrap-table/bootstrap-table.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/libs/bootstrap-table/bootstrap-table-editable.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/libs/bootstrap-table/bootstrap-editable.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/table.js') }}"></script>
{% endblock %}

@ -158,25 +158,20 @@ class UserBase:
return self.check_visibility(constants.DETAIL_RANDOM)
def list_restricted_tags(self):
# return [line in (line.strip("," ) for line in self.restricted_tags.split(",") if not line.startswith('~'))]
# return [line in (line.strip(",") for line in self.restricted_tags.split(",") if not line.startswith('~'))]
#return [p.strip(",") for p in self.restricted_tags.split(",") if not(p.startswith(starter))]
'''for line in self.restricted_tags.split(","):
if not line.startswith('~'):
continue'''
mct = self.restricted_tags.split(",")
return [t.strip() for t in mct]
def list_allowed_tags(self):
# return [line in (line.strip("," ) for line in self.restricted_tags.split(",") if not line.startswith('~'))]
# return [line in (line.strip(",") for line in self.restricted_tags.split(",") if not line.startswith('~'))]
#return [p.strip(",") for p in self.restricted_tags.split(",") if not(p.startswith(starter))]
'''for line in self.restricted_tags.split(","):
if not line.startswith('~'):
continue'''
mct = self.allowed_tags.split(",")
return [t.strip() for t in mct]
def list_restricted_column_values(self):
mct = self.restricted_column_values().split(",")
return [t.strip() for t in mct]
def list_allowed_column_values(self):
mct = self.allowed_column_values().split(",")
return [t.strip() for t in mct]
def __repr__(self):
return '<User %r>' % self.nickname

Loading…
Cancel
Save