Python flask_security.current_user.id() Examples
The following are 30
code examples of flask_security.current_user.id().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
flask_security.current_user
, or try the search function
.
Example #1
Source File: views.py From pygameweb with BSD 2-Clause "Simplified" License | 6 votes |
def revert(link): """ the link to make the latest version the one selected. """ if wiki_for(link).locked and not current_user.has_role('admin'): flash('Wiki page locked.') return current_app.login_manager.unauthorized() latest = request.args.get('latest', None) if latest is not None: oldone = wiki_for(link) newone = (current_session .query(Wiki) .filter(Wiki.link == link) .filter(Wiki.id == int(latest)) .first()) oldone.latest = 0 newone.latest = 1 current_session.add(newone) current_session.add(oldone) current_session.commit() return redirect(url_for('wiki.index', link=link, id=newone.id)) else: abort(404)
Example #2
Source File: api.py From udata with GNU Affero General Public License v3.0 | 6 votes |
def post(self, id): '''Add comment and optionally close a discussion given its ID''' discussion = Discussion.objects.get_or_404(id=id) form = api.validate(DiscussionCommentForm) message = Message( content=form.comment.data, posted_by=current_user.id ) discussion.discussion.append(message) message_idx = len(discussion.discussion) - 1 close = form.close.data if close: CloseDiscussionPermission(discussion).test() discussion.closed_by = current_user._get_current_object() discussion.closed = datetime.now() discussion.save() if close: on_discussion_closed.send(discussion, message=message_idx) else: on_new_discussion_comment.send(discussion, message=message_idx) return discussion
Example #3
Source File: api.py From udata with GNU Affero General Public License v3.0 | 6 votes |
def post(self, id): '''Add comment and optionally close an issue given its ID''' issue = Issue.objects.get_or_404(id=id) form = api.validate(IssueCommentForm) message = Message( content=form.comment.data, posted_by=current_user.id ) issue.discussion.append(message) message_idx = len(issue.discussion) - 1 close = form.close.data if close: CloseIssuePermission(issue).test() issue.closed_by = current_user._get_current_object() issue.closed = datetime.now() issue.save() if close: on_issue_closed.send(issue, message=message_idx) else: on_new_issue_comment.send(issue, message=message_idx) return issue
Example #4
Source File: workflow_executor.py From cloudify-manager with Apache License 2.0 | 6 votes |
def _execute_task(execution_id, execution_parameters, context, execution_creator, scheduled_time=None): # Get the host ip info and return them sm = get_storage_manager() managers = sm.list(models.Manager) context['rest_host'] = [manager.private_ip for manager in managers] context['rest_token'] = execution_creator.get_auth_token() context['tenant'] = _get_tenant_dict() context['task_target'] = MGMTWORKER_QUEUE execution_parameters['__cloudify_context'] = context message = { 'cloudify_task': {'kwargs': execution_parameters}, 'id': execution_id, 'dlx_id': None, 'execution_creator': current_user.id } if scheduled_time: message_ttl = _get_time_to_live(scheduled_time) message['dlx_id'] = execution_id _send_task_to_dlx(message, message_ttl) return _send_mgmtworker_task(message)
Example #5
Source File: association.py From contextualise with MIT License | 6 votes |
def view(map_identifier, topic_identifier, association_identifier): topic_store = get_topic_store() topic_map = topic_store.get_topic_map(map_identifier, current_user.id) if topic_map is None: abort(404) # If the map doesn't belong to the user and they don't have the right # collaboration mode on the map, then abort if not topic_map.owner and topic_map.collaboration_mode is not CollaborationMode.EDIT: abort(403) topic = topic_store.get_topic( map_identifier, topic_identifier, resolve_attributes=RetrievalMode.RESOLVE_ATTRIBUTES, ) if topic is None: abort(404) association = topic_store.get_association(map_identifier, association_identifier) return render_template("association/view.html", topic_map=topic_map, topic=topic, association=association,)
Example #6
Source File: webapp.py From Financial-Portfolio-Flask with MIT License | 6 votes |
def chart(): labels = [] valuesAmount = [] valuesInEur = [] # valuesInGBP = [] valuesInUSD = [] valuesInCNY = [] Currencies = UserCurrency.query.filter_by(id=current_user.id).all() for row in Currencies: labels.append(row.ticker) valuesAmount.append(row.amount) valuesInEur.append(row.priceInEUR) # valuesInGBP.append(row.priceInGBP) valuesInUSD.append(row.priceInUSD) valuesInCNY.append(row.priceInCHY) print(len(valuesAmount)) colors = ["#F7464A", "#46BFBD", "#FDB45C", "#FEDCBA", "#ABCDEF", "#DDDDDD", "#ABCABC"] return render_template('charts.html', set=list(zip(valuesAmount, valuesInEur, valuesInUSD, valuesInCNY, labels, colors)))
Example #7
Source File: manager.py From crestify with BSD 3-Clause "New" or "Revised" License | 6 votes |
def inject_user_tags(): if not current_user.is_authenticated: return { "user_tags": None } else: user_tags = Tag.query.filter(Tag.user == current_user.id, Tag.count > 0).all() user_tags.sort(key=lambda k: k.text.lower()) user_tags = [{'text': tag.text.encode('utf-8'), 'value': tag.text.encode('utf-8'), 'count': tag.count} for tag in user_tags if tag.text != ''] return { "user_tags": user_tags }
Example #8
Source File: association.py From contextualise with MIT License | 6 votes |
def view_member(map_identifier, topic_identifier, association_identifier, member_identifier): topic_store = get_topic_store() topic_map = topic_store.get_topic_map(map_identifier, current_user.id) if topic_map is None: abort(404) # If the map doesn't belong to the user and they don't have the right # collaboration mode on the map, then abort if not topic_map.owner and topic_map.collaboration_mode is not CollaborationMode.EDIT: abort(403) topic = topic_store.get_topic( map_identifier, topic_identifier, resolve_attributes=RetrievalMode.RESOLVE_ATTRIBUTES, ) if topic is None: abort(404) association = topic_store.get_association(map_identifier, association_identifier) member = association.get_member(member_identifier) return render_template( "association/view_member.html", topic_map=topic_map, topic=topic, association=association, member=member, )
Example #9
Source File: manager.py From crestify with BSD 3-Clause "New" or "Revised" License | 6 votes |
def bookmark_edit(bookmark_id=None): if bookmark_id: bookmark_id = hashids.decode(str(bookmark_id))[0] # Apparently, hashids.decode doesn't accept unicode input bookmarkobj = _get_user_object_or_404(Bookmark, bookmark_id, current_user.id) if bookmarkobj.tags: bookmarkobj.tags_2 = ','.join(bookmarkobj.tags).encode('utf-8') form = EditBookmarkForm(obj=bookmarkobj, csrf_enabled=False) if form.validate_on_submit(): bookmark.edit(id=bookmark_id, title=form.title.data, description=form.description.data, tags=form.tags_1.data, user_id=current_user.id) return redirect(url_for('bookmark_list')) return render_template("manager/bookmark_edit.html", form=form, bookmark_obj=bookmarkobj)
Example #10
Source File: map.py From contextualise with MIT License | 6 votes |
def delete(map_identifier): topic_store = get_topic_store() topic_map = topic_store.get_topic_map(map_identifier, current_user.id) if topic_map is None: abort(404) if not topic_map.owner: abort(403) if request.method == "POST": # Remove map from topic store topic_store.delete_topic_map(map_identifier, current_user.id) # Delete the map's directory topic_map_directory = os.path.join(bp.root_path, RESOURCES_DIRECTORY, str(map_identifier)) if os.path.isdir(topic_map_directory): shutil.rmtree(topic_map_directory) flash("Map successfully deleted.", "success") return redirect(url_for("map.index")) return render_template("map/delete.html", topic_map=topic_map)
Example #11
Source File: webapp.py From Financial-Portfolio-Flask with MIT License | 6 votes |
def stocks(): # We want the price of 5+ stocks # http://finance.google.com/finance/info?client=ig&q=NASDAQ%3AAAPL,GOOG,MSFT,AMZN,TWTR if Stock.query.first() is None: print("No stock data found in DB") request = requests.get('http://finance.google.com/finance/info?client=ig&q=NASDAQ%3AAAPL,GOOG,MSFT,AMZN,TWTR,EA,FB,NVDA,CSCO') request.encoding = 'utf-8' # We need to change encoding as this API uses ISO and i use utf-8 everywhere else o = request.text[4:] # The response object contains some characters at start that we cant parse. Trim these off result = json.loads(o) # After we trim the characters, turn back into JSON for i in result: # Now! Thats what I call Pythonic u = Stock(ticker=i['t'], last=i['l'], market=i['e'], timestamp=datetime.datetime.now()) db.session.add(u) db.session.commit() else: print("Found stock data in DB") # do something # query db for stocks Stocks = UserStocks.query.filter_by(id=current_user.id).all() # pass into html using render_template return render_template("stocks.html", Stocks=Stocks)
Example #12
Source File: api.py From udata with GNU Affero General Public License v3.0 | 5 votes |
def delete(self, id, cidx): '''Delete a comment given its index''' discussion = Discussion.objects.get_or_404(id=id) if len(discussion.discussion) <= cidx: api.abort(404, 'Comment does not exist') elif cidx == 0: api.abort(400, 'You cannot delete the first comment of a discussion') discussion.discussion.pop(cidx) discussion.save() return '', 204
Example #13
Source File: views.py From pygameweb with BSD 2-Clause "Simplified" License | 5 votes |
def delete_release(project_id, release_id): """ on post, delete the release. on get, show a form for posting to delete it. """ project = project_for(project_id) if project.user.id != current_user.id: abort(404) if release_id is not None: arelease = release_for(release_id) if arelease.project.user.id != current_user.id: abort(404) if request.method == 'GET' and release_id is not None: form = ReleaseDeleteForm(obj=arelease) else: form = ReleaseDeleteForm() if form.validate_on_submit(): (current_session .query(Release) .filter(Release.id == release_id) .delete() ) current_session.commit() return redirect(url_for('project.releases', project_id=project.id)) return render_template( 'project/deleterelease.html', form=form, project_for=project_for, release_for=release_for, project_id=project_id, release_id=release_id )
Example #14
Source File: utils.py From cloudify-manager with Apache License 2.0 | 5 votes |
def all_tenants_authorization(): return ( current_user.id == constants.BOOTSTRAP_ADMIN_ID or any(r in current_user.system_roles for r in config.instance.authorization_permissions['all_tenants']) )
Example #15
Source File: views.py From pygameweb with BSD 2-Clause "Simplified" License | 5 votes |
def release_for(release_id): """ gets a project for the given """ release = (current_session .query(Release) .filter(Release.id == release_id) .first()) if not release: abort(404) if release.project.user and release.project.user.disabled != 0: abort(404) return release
Example #16
Source File: webapp.py From Financial-Portfolio-Flask with MIT License | 5 votes |
def addNewCurrency(): amount = request.form['Amount'] # Amount taken from posted form ticker = request.form['Ticker'].upper() # Ticker taken from posted form currency = Currency.query.filter_by(ticker='BTC_'+ticker).first() # query the db for currency usd2btc = Currency.query.filter_by(ticker='USDT_BTC').first() fiat = requests.get('http://api.fixer.io/latest?base=USD') usd2fiat = fiat.json() queriedCur = UserCurrency.query.filter_by(ticker='BTC_'+ticker, id=current_user.id).first() if currency is not None: if queriedCur is not None: queriedCur.amount += Decimal(amount) queriedCur.timestamp = datetime.datetime.now() queriedCur.priceInBTC = (float(currency.last)*float(queriedCur.amount)) queriedCur.priceInUSD = (queriedCur.priceInBTC * float(usd2btc.last)) queriedCur.priceInEUR = queriedCur.priceInUSD * usd2fiat['rates']['EUR'] queriedCur.priceInCHY = queriedCur.priceInUSD * usd2fiat['rates']['CNY'] print("Currency amount updated in DB") else: me = UserCurrency(amount=float(amount), id=current_user.id, ticker=currency.ticker, last=currency.last, bid=currency.bid, ask=currency.last, timestamp=datetime.datetime.now(), priceInBTC=(float(currency.last)*float(amount)), priceInUSD=(float(usd2btc.last)*(float(currency.last)*float(amount))), priceInEUR=((float(usd2btc.last)*(float(currency.last)*float(amount))*float(usd2fiat['rates']['EUR']))), priceInCHY=((float(usd2btc.last)*(float(currency.last)*float(amount)) * float(usd2fiat['rates']['CNY'])))) db.session.add(me) print("Currency added to DB") db.session.commit() else: flash('Unrecognised Ticker. Please select one of the supported tickers') return redirect(url_for('currencies')) # This route is triggered via the currency route # Db is queried for provided currency and if user has stock it removes from db and commits change # If nothing there it prints this to console and redirects
Example #17
Source File: webapp.py From Financial-Portfolio-Flask with MIT License | 5 votes |
def deleteentry(ticker): queriedCur = UserCurrency.query.filter_by(ticker=ticker, id=current_user.id).first() if queriedCur is not None: UserCurrency.query.filter_by(ticker=ticker, id=current_user.id).delete() print("Deleted Currency") else: print("Could not delete. Redirecting") db.session.commit() return redirect(url_for('currencies')) # This route is triggered via the stocks route # Db is queried for provided stock and if user has stock it removes from db and commits change # If nothing there it prints this to console and redirects
Example #18
Source File: views.py From pygameweb with BSD 2-Clause "Simplified" License | 5 votes |
def project_for(project_id): """ gets a project for the given """ project = (current_session .query(Project) .filter(Project.id == project_id) .first()) if project is None: abort(404) if project.user and project.user.disabled != 0: abort(404) return project
Example #19
Source File: views.py From pygameweb with BSD 2-Clause "Simplified" License | 5 votes |
def releases(project_id): project = (current_session .query(Project) .filter(Project.id == project_id) .filter(Project.users_id == current_user.id) .first()) if not project: abort(404) return render_template('project/releases.html', releases=project.releases, project=project) # project-Rotating+3D+Cube-1859-.html
Example #20
Source File: api.py From udata with GNU Affero General Public License v3.0 | 5 votes |
def delete(self, id): '''Unfollow an object given its ID''' model = self.model.objects.only('id').get_or_404(id=id) follow = Follow.objects.get_or_404(follower=current_user.id, following=model, until=None) follow.until = datetime.now() follow.save() count = Follow.objects.followers(model).count() return {'followers': count}, 200
Example #21
Source File: api.py From udata with GNU Affero General Public License v3.0 | 5 votes |
def delete(self, id): '''Delete a discussion given its ID''' discussion = Discussion.objects.get_or_404(id=id) discussion.delete() on_discussion_deleted.send(discussion) return '', 204
Example #22
Source File: api.py From udata with GNU Affero General Public License v3.0 | 5 votes |
def get(self, id): '''Get a discussion given its ID''' discussion = Discussion.objects.get_or_404(id=id) return discussion
Example #23
Source File: api.py From udata with GNU Affero General Public License v3.0 | 5 votes |
def get(self): '''Suggest users''' args = suggest_parser.parse_args() return [ { 'id': opt['text'], 'first_name': opt['payload']['first_name'], 'last_name': opt['payload']['last_name'], 'avatar_url': opt['payload']['avatar_url'], 'slug': opt['payload']['slug'], 'score': opt['score'], } for opt in search.suggest(args['q'], 'user_suggest', args['size']) ]
Example #24
Source File: api.py From udata with GNU Affero General Public License v3.0 | 5 votes |
def get(self): '''List all reuses related to me and my organizations.''' q = filter_parser.parse_args().get('q') owners = list(current_user.organizations) + [current_user.id] reuses = Reuse.objects.owned_by(*owners).order_by('-last_modified') if q: reuses = reuses.filter(title__icontains=q) return list(reuses)
Example #25
Source File: api.py From udata with GNU Affero General Public License v3.0 | 5 votes |
def get(self): '''List all community resources related to me and my organizations.''' q = filter_parser.parse_args().get('q') owners = list(current_user.organizations) + [current_user.id] community_resources = (CommunityResource.objects.owned_by(*owners) .order_by('-last_modified')) if q: community_resources = community_resources.filter( title__icontains=q) return list(community_resources)
Example #26
Source File: api.py From udata with GNU Affero General Public License v3.0 | 5 votes |
def get(self): '''List all datasets related to me and my organizations.''' q = filter_parser.parse_args().get('q') owners = list(current_user.organizations) + [current_user.id] datasets = Dataset.objects.owned_by(*owners).order_by('-last_modified') if q: datasets = datasets.filter(title__icontains=q) return list(datasets)
Example #27
Source File: api.py From udata with GNU Affero General Public License v3.0 | 5 votes |
def get(self): '''List all my datasets (including private ones)''' return list(Dataset.objects.owned_by(current_user.id))
Example #28
Source File: api.py From udata with GNU Affero General Public License v3.0 | 5 votes |
def get(self): '''List all my reuses (including private ones)''' return list(Reuse.objects.owned_by(current_user.id))
Example #29
Source File: api.py From udata with GNU Affero General Public License v3.0 | 5 votes |
def get(self, id): '''Get an issue given its ID''' issue = Issue.objects.get_or_404(id=id) return issue
Example #30
Source File: api.py From udata with GNU Affero General Public License v3.0 | 5 votes |
def post(self, id): '''Follow an object given its ID''' model = self.model.objects.get_or_404(id=id) follow, created = Follow.objects.get_or_create( follower=current_user.id, following=model, until=None) count = Follow.objects.followers(model).count() if not current_app.config['TESTING']: tracking.send_signal(on_new_follow, request, current_user) return {'followers': count}, 201 if created else 200