def search(collection, p, of, ot, so, rm): """Render search page.""" from invenio.legacy.search_engine import perform_request_search if 'action_browse' in request.args \ or request.args.get('action', '') == 'browse': return browse() if 'c' in request.args and len(request.args) == 1 \ and len(request.args.getlist('c')) == 1: return redirect(url_for('.collection', name=request.args.get('c'))) argd = argd_orig = wash_search_urlargd(request.args) argd['of'] = 'id' # fix for queries like `/search?p=+ellis` if 'p' in argd: argd['p'] = argd['p'].strip() # update search arguments with the search user preferences if 'rg' not in request.values and current_user.get('rg'): argd['rg'] = int(current_user.get('rg')) rg = int(argd['rg']) collection_breadcrumbs(collection) qid = get_search_query_id(**argd) recids = perform_request_search(req=request.get_legacy_request(), **argd) # back-to-search related code if request and not isinstance(request.get_legacy_request(), cStringIO.OutputType): # store the last search results page session['websearch-last-query'] = request.get_legacy_request() \ .unparsed_uri hit_limit = current_app.config['CFG_WEBSEARCH_PREV_NEXT_HIT_LIMIT'] if len(recids) > hit_limit: last_query_hits = None else: last_query_hits = recids # store list of results if user wants to display hits # in a single list, or store list of collections of records # if user displays hits split by collections: session["websearch-last-query-hits"] = last_query_hits ctx = dict( facets=facets.get_facets_config(collection, qid), records=len(get_current_user_records_that_can_be_displayed(qid)), qid=qid, rg=rg, create_nearest_terms_box=lambda: _create_neareset_term_box(argd_orig), easy_search_form=EasySearchForm(csrf_enabled=False), ot=ot) return response_formated_records(recids, collection, of, **ctx)
def search(collection, p, of, ot, so, rm): """Render search page.""" from invenio.legacy.search_engine import perform_request_search if 'action_browse' in request.args \ or request.args.get('action', '') == 'browse': return browse() if 'c' in request.args and len(request.args) == 1 \ and len(request.args.getlist('c')) == 1: return redirect(url_for('.collection', name=request.args.get('c'))) argd = argd_orig = wash_search_urlargd(request.args) argd['of'] = 'id' # fix for queries like `/search?p=+ellis` if 'p' in argd: argd['p'] = argd['p'].strip() # update search arguments with the search user preferences if 'rg' not in request.values and current_user.get('rg'): argd['rg'] = int(current_user.get('rg')) rg = int(argd['rg']) collection_breadcrumbs(collection) qid = get_search_query_id(**argd) recids = perform_request_search(req=request.get_legacy_request(), **argd) # back-to-search related code if request and not isinstance(request.get_legacy_request(), cStringIO.OutputType): # store the last search results page session['websearch-last-query'] = request.get_legacy_request() \ .unparsed_uri hit_limit = current_app.config['CFG_WEBSEARCH_PREV_NEXT_HIT_LIMIT'] if len(recids) > hit_limit: last_query_hits = None else: last_query_hits = recids # store list of results if user wants to display hits # in a single list, or store list of collections of records # if user displays hits split by collections: session["websearch-last-query-hits"] = last_query_hits ctx = dict( facets=facets.get_facets_config(collection, qid), records=len(get_current_user_records_that_can_be_displayed(qid)), qid=qid, rg=rg, create_nearest_terms_box=lambda: _create_neareset_term_box(argd_orig), easy_search_form=EasySearchForm(csrf_enabled=False), ot=ot ) return response_formated_records(recids, collection, of, **ctx)
def home(): id = current_user.get().id try: user = current_user.get() form = PostForm(request.form) if form.validate_on_submit(): Post.create(about=form.about.data, user_id=user.id) else: print(form.errors) return render_template('home.html', form=form, user=user, id=id) except: return redirect(url_for('index'), id=id)
def user_index(): user = current_users usermanager = UserManager.read(user) if 'admin' not in current_user.get("roles") : flash("You do not have the permissions to see this page") return render_template('index.html') if current_user.get("roles") != ["admin"]: flash("You do not have the permissions to see this page") return render_template('index.html') return render_template('user.html', usermanager = usermanager)
def index(): list_type = 'rank' if not request.path.startswith('/rank'): list_type = 'index' if list_type == 'index' and datetime.datetime.utcnow() > datetime.datetime( 2017, 3, 16, 16, 0, 0): return redirect('/rank') nickname = current_user.get('nickname') products = FFProduct.query.add_descending('vote').find() vote_result = current_user.get('voteResult') product_list = [] voted = {} for product in products: image_list = [] for image in product.get('images'): image_list.append(image) author_names = product.get('authorName').split(',') author_sites = product.get('authorSite').split(',') authors = [] if len(author_names) == len(author_sites): for i, author_name in enumerate(author_names): authors.append({ 'nickname': author_name, 'site': author_sites[i] }) product_item = { 'id': product.id, 'name': product.get('name'), 'desc': product.get('intro'), 'vote': product.get('vote'), 'authors': authors, 'img': image_list } product_list.append(product_item.copy()) if product.id in vote_result: voted[product.id] = True else: voted[product.id] = False if list_type == 'index': random.shuffle(product_list) return render_template('index.html', data=product_list, voted=voted, nickname=nickname, list_type=list_type)
def index(): nickname = current_user.get('nickname') o = { "name": "测试设计 %d", "desc": "测试设计介绍 %d", "img": [ "http://placehold.it/450x300?text=Design+{id}+(0)", "http://placehold.it/450x300?text=Design+{id}+(1)", "http://placehold.it/450x300?text=Design+{id}+(2)" ] } l = [] WORKS = 10 for i in range(WORKS): l.append(o.copy()) l[-1]['name'] %= i l[-1]['desc'] %= i l[-1]['img'] = [j.format(id=i) for j in l[-1]['img']] l = random.shuffle(l) # list of bools: if user has voted the entry voted = [False] * WORKS return render_template('index.html', data=l, voted=voted, nickname=nickname)
def postfeedback(): """Handler to create a ticket from user feedback.""" feedback = request.form.get('feedback') if feedback == '': return jsonify(success=False), 400 replytoaddr = request.form.get('replytoaddr', None) if replytoaddr is None: if current_user.is_anonymous: return jsonify(success=False), 403 else: replytoaddr = current_user.get('email') if replytoaddr == '': return jsonify(success=False), 403 content = 'Feedback:\n{feedback}'.format(feedback=feedback) message = { 'sender': current_app.config['CFG_SITE_SUPPORT_EMAIL'], 'recipients': [current_app.config['INSPIRELABS_FEEDBACK_EMAIL']], 'subject': 'INSPIRE Labs Feedback', 'body': content, 'reply_to': replytoaddr } sending = send_email.delay(message) if sending.failed(): return jsonify(success=False), 500 else: return jsonify(success=True)
def index(): pages = current_wiki.index() user = current_user.get("roles") isAdmin = False if 'admin' in user: isAdmin = True return render_template('index.html', pages=pages, isAdmin = isAdmin)
def get_zip_base(user=None): ''' get zip base path for current user ''' if not user: user = current_user.get() ftp_path = current_app.config.get('USERFILES_PATH') ftp_folder = os.path.abspath(os.path.join(ftp_path, user.email)) return ftp_folder
def get_ftp_base(user=None): ''' get ftp base path for current user ''' if not user: user = current_user.get() ftp_path = current_app.config.get('FTP_PATH') ftp_folder = os.path.abspath(os.path.join(ftp_path, user.email)) print ftp_folder return ftp_folder
def rss(collection, p, jrec, so, rm): """Render RSS feed.""" of = 'xr' argd = wash_search_urlargd(request.args) argd['of'] = 'id' # update search arguments with the search user preferences if 'rg' not in request.values and current_user.get('rg'): argd['rg'] = current_user.get('rg') rg = int(argd['rg']) qid = get_search_query_id(**argd) recids = Query(p).search(collection=collection.name) ctx = dict(records=len(recids), qid=qid, rg=rg) return response_formated_records(recids, collection, of, **ctx)
def allowed_email_domain(current_user_id, brief, data_api_client=None): if not all([current_user_id, brief, data_api_client]): return False if not brief.get('users') or brief.get('users')[0] is None: return False current_user = data_api_client.get_user(current_user_id).get('users') email_domain = current_user.get('email_address').split('@')[-1] brief_user_email = brief.get('users')[0].get('emailAddress').split('@')[-1] return email_domain == brief_user_email
def get_records_for_user(qid, uid): key = get_search_results_cache_key_from_qid(qid) data = search_results_cache.get(key) if data is None: return intbitset([]) cc = search_results_cache.get(key + '::cc') return get_records_that_can_be_displayed( current_user.get('precached_permitted_restricted_collections', []), intbitset().fastload(data), cc)
def settings(): email = current_user.get('email') editor = current_user.get('editor') settingsUrl = "settings" if email == "": email = "Enter your email" if editor == "": editor = "Enter the path to your preferred text editor" form = SettingsForm() if form.validate_on_submit(): return render_template('settings.html', form=form, email=email, editor=editor, settingsUrl=settingsUrl) return render_template('settings.html', form=form, email=email, editor=editor, settingsUrl=settingsUrl)
def rss(collection, p, jrec, so, rm): """Render RSS feed.""" from invenio.legacy.search_engine import perform_request_search of = 'xr' argd = wash_search_urlargd(request.args) argd['of'] = 'id' # update search arguments with the search user preferences if 'rg' not in request.values and current_user.get('rg'): argd['rg'] = current_user.get('rg') rg = int(argd['rg']) qid = get_search_query_id(**argd) recids = perform_request_search(req=request.get_legacy_request(), **argd) ctx = dict(records=len( get_current_user_records_that_can_be_displayed(qid)), qid=qid, rg=rg) return response_formated_records(recids, collection, of, **ctx)
def rss(collection, p, jrec, so, rm): """Render RSS feed.""" of = 'xr' argd = wash_search_urlargd(request.args) argd['of'] = 'id' # update search arguments with the search user preferences if 'rg' not in request.values and current_user.get('rg'): argd['rg'] = current_user.get('rg') rg = int(argd['rg']) qid = get_search_query_id(**argd) recids = Query(p).search(collection=collection.name) ctx = dict( records=len(recids), qid=qid, rg=rg ) return response_formated_records(recids, collection, of, **ctx)
def rss(collection, p, jrec, so, rm): """Render RSS feed.""" from invenio.legacy.search_engine import perform_request_search of = 'xr' argd = wash_search_urlargd(request.args) argd['of'] = 'id' # update search arguments with the search user preferences if 'rg' not in request.values and current_user.get('rg'): argd['rg'] = current_user.get('rg') rg = int(argd['rg']) qid = get_search_query_id(**argd) recids = perform_request_search(req=request.get_legacy_request(), **argd) ctx = dict( records=len(get_current_user_records_that_can_be_displayed(qid)), qid=qid, rg=rg ) return response_formated_records(recids, collection, of, **ctx)
def oai_get_recid(identifier): """Returns the recid corresponding to the OAI identifier. Prefer a non deleted record if multiple recids matches but some of them are deleted (e.g. in case of merging). Returns None if no record matches.""" if identifier: recids = search_pattern(p=identifier, f=CFG_OAI_ID_FIELD, m='e', ap=-9) if recids: displayable_recids = get_records_that_can_be_displayed( current_user.get('precached_permitted_restricted_collections', []), recids) for recid in displayable_recids: if record_exists(recid) > 0: return recid return None
def admin(): """ This is the admin route, this will only allow certain user in and redirect those without the permissions to the index with a message. The admin page will have the option of deleting a user , or listing the users with relevant info """ roles = current_user.get('roles') if 'ADMIN' in roles: return render_template('admin.html') else: flash('Insufficient Permissions to access this page', 'danger') return redirect(url_for('wiki.home'))
def rssfeed(): """ The user can provide the RSS Feed's url that they wish to view title/link information for. To view a different RSS Feed's data they just need to enter another feed's url. :return: rssfeed.html and the feed data that was parsed (each entry's title and link) """ form = RssfeedForm() if form.validate_on_submit(): rssurl = form.rssurl.data if (get_feed_title(rssurl) != "PLEASE PROVIDE A DIFFERENT RSS FEED URL"): # save rssurl in users.json current_user.set('rssurl', rssurl) form.rssurl.data = current_user.get('rssurl') rssurl = form.rssurl.data rssdata = get_rss_data(rssurl) channeltitle = get_feed_title(rssurl) return render_template('rssfeed.html', form=form, rssdata=rssdata, channeltitle=channeltitle)
def admin_page(): if not current_user.get('administrator'): return redirect(request.args.get("next") or url_for('wiki.home')) form = EditUserForm() if form.validate_on_submit(): if current_users.get_user(form.user_edit.data): #todo: !=None maybe if current_users.get_user( form.user_edit.data).get('administrator'): flash('Cannot delete administrators.', 'error') else: current_users.delete_user(form.user_edit.data) else: flash('User not found.', 'error') form.user_edit.data = '' users = {} x = current_users.read() #returns a dict object with unicode values for key, values in x.items(): name = key.encode('ascii', 'ignore') current_data = (values[u'creation_time']).encode('ascii', 'ignore') users[name] = current_data return render_template('admin_page.html', users=users, form=form)
def add_gamer_profile(): """ add gamer profile for current user """ user_id = current_user.get().id user = User.objects.get_or_404(id=user_id) # should we validate object_id here? # auto populate with g.formdata game_form = GamerForm(g.formdata) game_form.populate_obj(user.gamer) if request.files and request.files['avatar']: filename = Avatars.save(request.files['avatar']) user.gamer.avatar = Avatars.url(filename) # manually handle games user.gamer.games = [Game(id=_id) for _id in request.form.getlist('games')] user.save() return user
def get_locale(): """Compute the language needed to return the answer to the client.""" from invenio_base.i18n import wash_language required_ln = None passed_ln = request.values.get('ln', type=str) if passed_ln: # If ln is specified explictly as a GET or POST argument # let's take it! required_ln = wash_language(passed_ln) if passed_ln != required_ln: # But only if it was a valid language required_ln = None if required_ln is None and 'ln' not in session: # If there is no language saved into the session... user_language = current_user.get('language') if user_language: # ... and the user is logged in, we try to take it from its # settings. required_ln = user_language else: # Otherwise we try to guess it from its request headers for value, quality in request.accept_languages: value = str(value) ln = wash_language(value) if ln == value or ln[:2] == value[:2]: required_ln = ln break else: # Too bad! We stick to the default :-) required_ln = current_app.config.get('CFG_SITE_LANG') elif required_ln is None: required_ln = session.get('ln') assert required_ln is not None if required_ln != session.get('ln', current_app.config.get('CFG_SITE_LANG')): session['ln'] = required_ln return required_ln
def index(): """Index.""" # load plugins plugins = filter(lambda x: x.is_authorized and x.widget, map(lambda x: x(), _USER_SETTINGS.values())) closed_plugins = [] plugin_sort = (lambda w, x: x.index(w.name) if w.name in x else len(x)) dashboard_settings = current_user.get('dashboard_settings', {}) if current_user.is_super_admin: # Check for a new release of Invenio from invenio.ext.script import check_for_software_updates check_for_software_updates(flash_message=True) if dashboard_settings: order_left = dashboard_settings.get('orderLeft', []) or [] order_middle = dashboard_settings.get('orderMiddle', []) or [] order_right = dashboard_settings.get('orderRight', []) or [] def extract_plugins(x): return [p for p in plugins if p.name in x if p] plugins_left = sorted(extract_plugins(order_left), key=lambda w: plugin_sort(w, order_left)) plugins_middle = sorted(extract_plugins(order_middle), key=lambda w: plugin_sort(w, order_middle)) plugins_right = sorted(extract_plugins(order_right), key=lambda w: plugin_sort(w, order_right)) closed_plugins = [ p for p in plugins if p not in plugins_left and p not in plugins_middle and p not in plugins_right ] plugins = [plugins_left, plugins_middle, plugins_right] else: plugins = sorted(plugins, key=lambda w: plugin_sort(w, plugins)) plugins = [plugins[i:i + 3] for i in range(0, len(plugins), 3)] return render_template('accounts/index.html', plugins=plugins, closed_plugins=closed_plugins)
def index(): """Index.""" # load plugins plugins = filter(lambda x: x.is_authorized and x.widget, map(lambda x: x(), _USER_SETTINGS.values())) closed_plugins = [] plugin_sort = (lambda w, x: x.index(w.name) if w.name in x else len(x)) dashboard_settings = current_user.get('dashboard_settings', {}) if current_user.is_super_admin: # Check for a new release of Invenio from invenio.ext.script import check_for_software_updates check_for_software_updates(flash_message=True) if dashboard_settings: order_left = dashboard_settings.get('orderLeft', []) or [] order_middle = dashboard_settings.get('orderMiddle', []) or [] order_right = dashboard_settings.get('orderRight', []) or [] def extract_plugins(x): return [p for p in plugins if p.name in x if p] plugins_left = sorted(extract_plugins(order_left), key=lambda w: plugin_sort(w, order_left)) plugins_middle = sorted(extract_plugins(order_middle), key=lambda w: plugin_sort(w, order_middle)) plugins_right = sorted(extract_plugins(order_right), key=lambda w: plugin_sort(w, order_right)) closed_plugins = [p for p in plugins if p not in plugins_left and p not in plugins_middle and p not in plugins_right] plugins = [plugins_left, plugins_middle, plugins_right] else: plugins = sorted(plugins, key=lambda w: plugin_sort(w, plugins)) plugins = [plugins[i:i+3] for i in range(0, len(plugins), 3)] return render_template('accounts/index.html', plugins=plugins, closed_plugins=closed_plugins)
def unsbscribe(): user = current_user.get() if user.notif == 1: user.notif = False user.save() return redirect(url_for('main.my_account'))
def customEditor(url): source_path = current_wiki.attr_by_url("path", url) editor_path = current_user.get("editor") system(editor_path + " " + source_path) return redirect(url)
def can_access_deposit_type(type_): """Return True if current user can access given deposition type.""" if type_ is None: default_type = deposit_default_type.get() type_ = default_type and default_type.get_identifier() or None return type_ in current_user.get('precached_allowed_deposition_types', [])
def search(collection, p, of, ot, so, sf, sp, rm): """Render search page.""" if 'action_browse' in request.args \ or request.args.get('action', '') == 'browse': return browse() if 'c' in request.args and len(request.args) == 1 \ and len(request.args.getlist('c')) == 1: return redirect(url_for('.collection', name=request.args.get('c'))) if 'f' in request.args: args = request.args.copy() args['p'] = "{0}:{1}".format(args['f'], args['p']) del args['f'] return redirect('.search', **args) argd = argd_orig = wash_search_urlargd(request.args) # fix for queries like `/search?p=+ellis` p = p.strip().encode('utf-8') jrec = request.values.get('jrec', 1, type=int) # update search arguments with the search user preferences if 'rg' not in request.values and current_user.get('rg'): argd['rg'] = int(current_user.get('rg')) rg = int(argd['rg']) collection_breadcrumbs(collection) qid = get_search_query_id(p=p, cc=collection.name) recids = Query(p).search(collection=collection.name) records = len(recids) recids = sort_and_rank_records(recids, so=so, rm=rm, sf=sf, sp=sp, p=p, of='id', rg=rg, jrec=jrec) # back-to-search related code if request and not isinstance(request.get_legacy_request(), cStringIO.OutputType): # store the last search results page session['websearch-last-query'] = request.get_legacy_request() \ .unparsed_uri hit_limit = current_app.config['CFG_WEBSEARCH_PREV_NEXT_HIT_LIMIT'] if len(recids) > hit_limit: last_query_hits = None else: last_query_hits = recids # store list of results if user wants to display hits # in a single list, or store list of collections of records # if user displays hits split by collections: session["websearch-last-query-hits"] = last_query_hits ctx = dict( facets=facets.get_facets_config(collection, qid), records=records, rg=rg, create_nearest_terms_box=lambda: _create_neareset_term_box(argd_orig), easy_search_form=EasySearchForm(csrf_enabled=False), ot=ot) # TODO add search services # # WebSearch services # from invenio.modules.search import services # if jrec <= 1 and \ # (em == "" and True or (EM_REPOSITORY["search_services"] in em)): # user_info = collect_user_info(req) # # display only on first search page, and only if wanted # # when 'em' param set. # for answer_relevance, answer_html in services.get_answers( # req, user_info, of, cc, colls_to_search, p, f, ln): # req.write('<div class="searchservicebox">') # req.write(answer_html) # if verbose > 8: # write_warning("Service relevance: %i" % # answer_relevance, req=req) # req.write('</div>') # TODO add external collection search # if not of in ['hcs', 'hcs2']: # perform_external_collection_search_with_em( # req, cc, [p, p1, p2, p3], f, ec, verbose, # ln, selected_external_collections_infos, em=em) return response_formated_records(recids, collection, of, **ctx)
def search(collection, p, of, ot, so, sf, sp, rm): """Render search page.""" if 'action_browse' in request.args \ or request.args.get('action', '') == 'browse': return browse() if 'c' in request.args and len(request.args) == 1 \ and len(request.args.getlist('c')) == 1: return redirect(url_for('.collection', name=request.args.get('c'))) if 'f' in request.args: args = request.args.copy() args['p'] = "{0}:{1}".format(args['f'], args['p']) del args['f'] return redirect('.search', **args) argd = argd_orig = wash_search_urlargd(request.args) # fix for queries like `/search?p=+ellis` p = p.strip().encode('utf-8') jrec = request.values.get('jrec', 1, type=int) # update search arguments with the search user preferences if 'rg' not in request.values and current_user.get('rg'): argd['rg'] = int(current_user.get('rg')) rg = int(argd['rg']) collection_breadcrumbs(collection) qid = get_search_query_id(p=p, cc=collection.name) recids = Query(p).search(collection=collection.name) records = len(recids) recids = sort_and_rank_records(recids, so=so, rm=rm, sf=sf, sp=sp, p=p, of='id', rg=rg, jrec=jrec) # back-to-search related code if request and not isinstance(request.get_legacy_request(), cStringIO.OutputType): # store the last search results page session['websearch-last-query'] = request.get_legacy_request() \ .unparsed_uri hit_limit = current_app.config['CFG_WEBSEARCH_PREV_NEXT_HIT_LIMIT'] if len(recids) > hit_limit: last_query_hits = None else: last_query_hits = recids # store list of results if user wants to display hits # in a single list, or store list of collections of records # if user displays hits split by collections: session["websearch-last-query-hits"] = last_query_hits ctx = dict( facets=facets.get_facets_config(collection, qid), records=records, rg=rg, create_nearest_terms_box=lambda: _create_neareset_term_box(argd_orig), easy_search_form=EasySearchForm(csrf_enabled=False), ot=ot ) # TODO add search services # # WebSearch services # from invenio.modules.search import services # if jrec <= 1 and \ # (em == "" and True or (EM_REPOSITORY["search_services"] in em)): # user_info = collect_user_info(req) # # display only on first search page, and only if wanted # # when 'em' param set. # for answer_relevance, answer_html in services.get_answers( # req, user_info, of, cc, colls_to_search, p, f, ln): # req.write('<div class="searchservicebox">') # req.write(answer_html) # if verbose > 8: # write_warning("Service relevance: %i" % # answer_relevance, req=req) # req.write('</div>') # TODO add external collection search # if not of in ['hcs', 'hcs2']: # perform_external_collection_search_with_em( # req, cc, [p, p1, p2, p3], f, ec, verbose, # ln, selected_external_collections_infos, em=em) return response_formated_records(recids, collection, of, **ctx)
def me(): """ get logined user detail info """ return current_user.get()
def get_timezone(): """Return the timezone from user settings.""" return current_user.get('timezone')
def me(): """ get logined user detail info """ result = dict(has_login=False) if current_user.is_authenticated(): result.update(dict(has_login=True,user=current_user.get())) return result
def vote(product_id, action): if datetime.datetime.utcnow() > datetime.datetime(2017, 3, 16, 16, 0, 0): return jsonify({'success': False, 'error': '投票已截止'}) if action == 'vote': ff_vote_count = FFVote.query.equal_to('authUser', current_user).count() if ff_vote_count >= const.VOTE_LIMIT: return jsonify({ 'success': False, 'error': '最多只能投 ' + str(const.VOTE_LIMIT) + ' 票' }) try: ff_product = FFProduct.query.get(product_id) except LeanCloudError as _: return jsonify({'success': False, 'error': '没有查询到该作品'}) try: ff_auth = FFAuth.query.get(current_user.id) except LeanCloudError as _: return jsonify({'success': False, 'error': '没有查询到该用户'}) ff_vote = None try: ff_vote = FFVote.query.equal_to('authUser', ff_auth).equal_to( 'targetProduct', ff_product).first() except LeanCloudError as _: pass if action == 'vote': if ff_vote: return jsonify({'success': False, 'error': '已经投过'}) try: ff_vote = FFVote() ff_vote.set('authUser', ff_auth) ff_vote.set('targetProduct', ff_product) ff_vote.save() except LeanCloudError as _: return jsonify({'success': False, 'error': '写入数据库失败'}) try: vote_count = ff_product.get('vote') + 1 ff_product.set('vote', vote_count) ff_product.save() vote_result = current_user.get('voteResult') if ff_product.id not in vote_result: vote_result.append(ff_product.id) current_user.set('voteResult', vote_result) current_user.save() except LeanCloudError as _: pass return jsonify({'success': True, 'error': ''}) if action == 'undo': if not ff_vote: return jsonify({'success': True, 'error': ''}) try: ff_vote.destroy() except LeanCloudError as _: return jsonify({'success': False, 'error': '删除失败'}) try: vote_count = ff_product.get('vote') - 1 ff_product.set('vote', vote_count) ff_product.save() vote_result = current_user.get('voteResult') if ff_product.id in vote_result: vote_result.remove(ff_product.id) current_user.set('voteResult', vote_result) current_user.save() except LeanCloudError as _: pass return jsonify({'success': True, 'error': ''})
def subscribe(): user = current_user.get() if user.notif == 0: user.notif = True user.save() return redirect(url_for('main.my_account'))
def _default_rg(): """Get number of records per page from user settings.""" rg = cfg['CFG_WEBSEARCH_DEF_RECORDS_IN_GROUPS'] if 'rg' not in request.values and current_user.get('rg'): rg = current_user.get('rg') return int(rg) or 1