Merge branch 'master' of https://github.com/janeczku/calibre-web
This commit is contained in:
commit
e15ebd5aac
26
cps/admin.py
26
cps/admin.py
|
@ -246,14 +246,15 @@ def list_users():
|
|||
limit = int(request.args.get("limit") or 10)
|
||||
search = request.args.get("search")
|
||||
sort = request.args.get("sort", "state")
|
||||
order = request.args.get("order")
|
||||
order = request.args.get("order", "").lower()
|
||||
state = None
|
||||
if sort == "state":
|
||||
state = json.loads(request.args.get("state", "[]"))
|
||||
|
||||
if sort != "state" and order:
|
||||
order = text(sort + " " + order)
|
||||
else:
|
||||
elif not state:
|
||||
order = ub.User.name.desc()
|
||||
if sort == "state":
|
||||
state = json.loads(request.args.get("state"))
|
||||
|
||||
all_user = ub.session.query(ub.User)
|
||||
if not config.config_anonbrowse:
|
||||
|
@ -266,16 +267,7 @@ def list_users():
|
|||
func.lower(ub.User.kindle_mail).ilike("%" + search + "%"),
|
||||
func.lower(ub.User.email).ilike("%" + search + "%")))
|
||||
if state:
|
||||
outcome = list()
|
||||
userlist = {user.id:user for user in all_user.all()}
|
||||
for entry in state:
|
||||
outcome.append(userlist[entry])
|
||||
del userlist[entry]
|
||||
for entry in userlist:
|
||||
outcome.append(userlist[entry])
|
||||
if request.args.get("order", "").lower() == "asc":
|
||||
outcome.reverse()
|
||||
users = outcome[off:off + limit]
|
||||
users = calibre_db.get_checkbox_sorted(all_user.all(), state, off, limit, request.args.get("order", "").lower())
|
||||
else:
|
||||
users = all_user.order_by(order).offset(off).limit(limit).all()
|
||||
if search:
|
||||
|
@ -364,7 +356,7 @@ def edit_list_user(param):
|
|||
user.email = check_email(vals['value'])
|
||||
elif param == 'kindle_mail':
|
||||
user.kindle_mail = valid_email(vals['value']) if vals['value'] else ""
|
||||
elif param == 'role':
|
||||
elif param.endswith('role'):
|
||||
if user.name == "Guest" and int(vals['field_index']) in \
|
||||
[constants.ROLE_ADMIN, constants.ROLE_PASSWD, constants.ROLE_EDIT_SHELFS]:
|
||||
raise Exception(_("Guest can't have this role"))
|
||||
|
@ -375,7 +367,9 @@ def edit_list_user(param):
|
|||
if not ub.session.query(ub.User).\
|
||||
filter(ub.User.role.op('&')(constants.ROLE_ADMIN) == constants.ROLE_ADMIN,
|
||||
ub.User.id != user.id).count():
|
||||
return _(u"No admin user remaining, can't remove admin role", nick=user.name), 400
|
||||
return Response(json.dumps({'type': "danger",
|
||||
'message':_(u"No admin user remaining, can't remove admin role",
|
||||
nick=user.name)}), mimetype='application/json')
|
||||
user.role &= ~int(vals['field_index'])
|
||||
elif param == 'sidebar_view':
|
||||
if user.name == "Guest" and int(vals['field_index']) == constants.SIDEBAR_READ_AND_UNREAD:
|
||||
|
|
13
cps/db.py
13
cps/db.py
|
@ -616,6 +616,19 @@ class CalibreDB():
|
|||
return and_(lang_filter, pos_content_tags_filter, ~neg_content_tags_filter,
|
||||
pos_content_cc_filter, ~neg_content_cc_filter, archived_filter)
|
||||
|
||||
@staticmethod
|
||||
def get_checkbox_sorted(inputlist, state, offset, limit, order):
|
||||
outcome = list()
|
||||
elementlist = {ele.id: ele for ele in inputlist}
|
||||
for entry in state:
|
||||
outcome.append(elementlist[entry])
|
||||
del elementlist[entry]
|
||||
for entry in elementlist:
|
||||
outcome.append(elementlist[entry])
|
||||
if order == "asc":
|
||||
outcome.reverse()
|
||||
return outcome[offset:offset + limit]
|
||||
|
||||
# Fill indexpage with all requested data from database
|
||||
def fill_indexpage(self, page, pagesize, database, db_filter, order, *join):
|
||||
return self.fill_indexpage_with_archived_books(page, pagesize, database, db_filter, order, False, *join)
|
||||
|
|
|
@ -117,6 +117,7 @@ $(function() {
|
|||
|
||||
$("#books-table").bootstrapTable({
|
||||
sidePagination: "server",
|
||||
queryParams: queryParams,
|
||||
pagination: true,
|
||||
paginationLoop: false,
|
||||
paginationDetailHAlign: " hidden",
|
||||
|
@ -461,7 +462,7 @@ $(function() {
|
|||
$("input[data-name='passwd_role'][data-pk='"+guest.data("pk")+"']").prop("disabled", true);
|
||||
$("input[data-name='edit_shelf_role'][data-pk='"+guest.data("pk")+"']").prop("disabled", true);
|
||||
$("input[data-name='sidebar_read_and_unread'][data-pk='"+guest.data("pk")+"']").prop("disabled", true);
|
||||
$(".user-remove[data-pk='"+guest.data("pk")+"']").prop("disabled", true);
|
||||
$(".user-remove[data-pk='"+guest.data("pk")+"']").hide();
|
||||
},
|
||||
onSort: function(a, b) {
|
||||
console.log("huh");
|
||||
|
@ -611,25 +612,30 @@ function checkboxFormatter(value, row, index){
|
|||
|
||||
function checkboxChange(checkbox, userId, field, field_index) {
|
||||
$.ajax({
|
||||
method:"post",
|
||||
method: "post",
|
||||
url: window.location.pathname + "/../../ajax/editlistusers/" + field,
|
||||
data: {"pk":userId, "field_index":field_index, "value": checkbox.checked}
|
||||
/*<div className="editable-buttons">
|
||||
<button type="button" className="btn btn-default btn-sm editable-cancel"><i
|
||||
className="glyphicon glyphicon-remove"></i></button>
|
||||
</div>*/
|
||||
/*<div className="editable-error-block help-block" style="">Text to show</div>*/
|
||||
});
|
||||
$.ajax({
|
||||
method:"get",
|
||||
url: window.location.pathname + "/../../ajax/listusers",
|
||||
async: true,
|
||||
timeout: 900,
|
||||
success:function(data) {
|
||||
$("#user-table").bootstrapTable("load", data);
|
||||
data: {"pk": userId, "field_index": field_index, "value": checkbox.checked},
|
||||
success: function (data) {
|
||||
if (!jQuery.isEmptyObject(data)) {
|
||||
$("#flash_success").remove();
|
||||
$("#flash_danger").remove();
|
||||
$( ".navbar" ).after( '<div class="row-fluid text-center" style="margin-top: -20px;">' +
|
||||
'<div id="flash_'+data.type+'" class="alert alert-'+data.type+'">'+data.message+'</div>' +
|
||||
'</div>');
|
||||
}
|
||||
$.ajax({
|
||||
method: "get",
|
||||
url: window.location.pathname + "/../../ajax/listusers",
|
||||
async: true,
|
||||
timeout: 900,
|
||||
success: function (data) {
|
||||
$("#user-table").bootstrapTable("load", data);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function deactivateHeaderButtons(e) {
|
||||
$("#user_delete_selection").addClass("disabled");
|
||||
$("#user_delete_selection").attr("aria-disabled", true);
|
||||
|
@ -734,8 +740,6 @@ function queryParams(params)
|
|||
params.state = JSON.stringify(selections);
|
||||
return params;
|
||||
}
|
||||
function user_handle (userId) {
|
||||
}
|
||||
|
||||
function test(){
|
||||
console.log("hello");
|
||||
|
|
21
cps/web.py
21
cps/web.py
|
@ -757,33 +757,26 @@ def list_books():
|
|||
limit = int(request.args.get("limit") or config.config_books_per_page)
|
||||
search = request.args.get("search")
|
||||
sort = request.args.get("sort", "state")
|
||||
order = request.args.get("order")
|
||||
order = request.args.get("order", "").lower()
|
||||
state = None
|
||||
|
||||
if sort == "state":
|
||||
state = json.loads(request.args.get("state", "[]"))
|
||||
|
||||
if sort != "state" and order:
|
||||
order = [text(sort + " " + order)]
|
||||
else:
|
||||
elif not state:
|
||||
order = [db.Books.timestamp.desc()]
|
||||
if sort == "state":
|
||||
state = json.loads(request.args.get("state"))
|
||||
|
||||
total_count = filtered_count = calibre_db.session.query(db.Books).count()
|
||||
|
||||
if state:
|
||||
outcome = list()
|
||||
if search:
|
||||
books = calibre_db.search_query(search)
|
||||
filtered_count = len(books)
|
||||
else:
|
||||
books = calibre_db.session.query(db.Books).filter(calibre_db.common_filters()).all()
|
||||
booklist = {book.id: book for book in books}
|
||||
for entry in state:
|
||||
outcome.append(booklist[entry])
|
||||
del booklist[entry]
|
||||
for entry in booklist:
|
||||
outcome.append(booklist[entry])
|
||||
if request.args.get("order", "").lower() == "asc":
|
||||
outcome.reverse()
|
||||
entries = outcome[off:off + limit]
|
||||
entries = calibre_db.get_checkbox_sorted(books, state, off, limit,order)
|
||||
elif search:
|
||||
entries, filtered_count, __ = calibre_db.get_search_results(search, off, order, limit)
|
||||
else:
|
||||
|
|
|
@ -27,7 +27,7 @@ Flask-SimpleLDAP>=1.4.0,<1.5.0
|
|||
|
||||
#oauth
|
||||
Flask-Dance>=1.4.0,<3.1.0
|
||||
SQLAlchemy-Utils>=0.33.5,<0.37.0
|
||||
SQLAlchemy-Utils>=0.33.5,<0.38.0
|
||||
|
||||
# extracting metadata
|
||||
lxml>=3.8.0,<4.7.0
|
||||
|
|
Loading…
Reference in New Issue
Block a user