本文整理汇总了Python中django_tools.middlewares.ThreadLocal.get_current_user方法的典型用法代码示例。如果您正苦于以下问题:Python ThreadLocal.get_current_user方法的具体用法?Python ThreadLocal.get_current_user怎么用?Python ThreadLocal.get_current_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django_tools.middlewares.ThreadLocal
的用法示例。
在下文中一共展示了ThreadLocal.get_current_user方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_request
# 需要导入模块: from django_tools.middlewares import ThreadLocal [as 别名]
# 或者: from django_tools.middlewares.ThreadLocal import get_current_user [as 别名]
def process_request(self, request):
url = request.get_full_path()
if url.startswith('/copo', 0, 5):
doc = Submission().get_incomplete_submissions_for_user(request.user.id, figshare)
data_dict = dict()
token = None
if doc.count() > 0:
if 'code' in request.GET and 'state' in request.GET:
token_obtained = True
for d in doc:
if d.get('token_obtained') == 'false':
token_obtained = False
break
if not token_obtained:
# get new token from Figshare
code = request.GET.get('code')
client_id = FIGSHARE_CREDENTIALS['client_id']
token_url = FIGSHARE_API_URLS['authorization_token']
# now get token
data = {
'client_id': client_id,
'code': code,
'client_secret': FIGSHARE_CREDENTIALS['client_secret'],
'grant_type': 'authorization_code',
'scope': 'all'
}
try:
r = requests.post(token_url, data)
data_dict = ast.literal_eval(r.content.decode('utf-8'))
token = data_dict['token']
t = Figshare().put_token_for_user(user_id=ThreadLocal.get_current_user().id, token=token)
if t:
# mark fighshare submissions for this user as token obtained
Submission().mark_all_token_obtained(user_id=request.user.id)
# if all is well, the access token will be stored in FigshareSubmussionCollection
except Exception as e:
print(e)
else:
# retrieve token
token = Figshare().get_token_for_user(user_id=ThreadLocal.get_current_user().id)
# request.session['partial_submissions'] = doc
else:
request.session['partial_submissions'] = None
示例2: done
# 需要导入模块: from django_tools.middlewares import ThreadLocal [as 别名]
# 或者: from django_tools.middlewares.ThreadLocal import get_current_user [as 别名]
def done(self, form_list, **kwargs):
invoice = None
from django_tools.middlewares import ThreadLocal
user = ThreadLocal.get_current_user().username
klient = Klient.objects.get(nazwa=user)
for form in form_list:
if isinstance(form, ZamowienieForm):
invoiceData = form.cleaned_data
invoiceData.update({
'klient': klient
})
invoice = Zamowienie(**invoiceData)
invoice.save()
elif isinstance(form, BaseFormSet):
for posForm in form.forms:
if isinstance(posForm, PozycjaZamowieniaForm):
positionData = posForm.cleaned_data
positionData.update({
'zamowienie': invoice
})
position = PozycjaZamowienia(**positionData)
position.save()
else:
posForm.save()
self.storage.reset()
return render_to_response('wizard/stepDone.html',
{'zamowienie': invoice,
'pozycje': PozycjaZamowienia.objects.filter(zamowienie_id=invoice.pk)},
context_instance=RequestContext(ThreadLocal.get_current_request()))
示例3: view_orcid_profile
# 需要导入模块: from django_tools.middlewares import ThreadLocal [as 别名]
# 或者: from django_tools.middlewares.ThreadLocal import get_current_user [as 别名]
def view_orcid_profile(request):
user = ThreadLocal.get_current_user()
op = Orcid().get_orcid_profile(user)
data_dict = {'op': op}
# data_dict = jsonpickle.encode(data_dict)
return render(request, 'copo/orcid_profile.html', data_dict)
示例4: create_sra_person
# 需要导入模块: from django_tools.middlewares import ThreadLocal [as 别名]
# 或者: from django_tools.middlewares.ThreadLocal import get_current_user [as 别名]
def create_sra_person(self):
"""
create an (SRA) person record and attach to profile
Args:
profile_id: to be linked to created record
Returns:
"""
user = ThreadLocal.get_current_user()
auto_fields = {
'copo.person.roles.annotationValue': 'SRA Inform On Status',
'copo.person.lastName': user.last_name,
'copo.person.firstName': user.first_name,
'copo.person.roles.annotationValue_1': 'SRA Inform On Error',
'copo.person.email': user.email
}
people = self.get_all_records()
sra_roles = list()
for record in people:
for role in record.get("roles", list()):
sra_roles.append(role.get("annotationValue", str()))
# has sra roles?
has_sra_roles = all(x in sra_roles for x in ['SRA Inform On Status', 'SRA Inform On Error'])
if not has_sra_roles:
kwargs = dict()
self.save_record(auto_fields, **kwargs)
return
示例5: GET_FOR_USER
# 需要导入模块: from django_tools.middlewares import ThreadLocal [as 别名]
# 或者: from django_tools.middlewares.ThreadLocal import get_current_user [as 别名]
def GET_FOR_USER(self, user=None):
if (user == None):
user = ThreadLocal.get_current_user().id
docs = Profiles.find({'user_id': user})
if not docs:
pass
return docs
示例6: save
# 需要导入模块: from django_tools.middlewares import ThreadLocal [as 别名]
# 或者: from django_tools.middlewares.ThreadLocal import get_current_user [as 别名]
def save(self, *args, **kwargs):
current_user = ThreadLocal.get_current_user()
if current_user and isinstance(current_user, User):
if self.pk == None or kwargs.get("force_insert", False): # New model entry
self.createby = current_user
self.lastupdateby = current_user
return super(UpdateUserBaseModel, self).save(*args, **kwargs)
示例7: get_for_user
# 需要导入模块: from django_tools.middlewares import ThreadLocal [as 别名]
# 或者: from django_tools.middlewares.ThreadLocal import get_current_user [as 别名]
def get_for_user(self, user=None):
if not user:
user = ThreadLocal.get_current_user().id
docs = self.get_collection_handle().find({"user_id": user, "deleted": data_utils.get_not_deleted_flag()}).sort(
[['_id', -1]])
if docs:
return docs
else:
return None
示例8: purge_descriptions
# 需要导入模块: from django_tools.middlewares import ThreadLocal [as 别名]
# 或者: from django_tools.middlewares.ThreadLocal import get_current_user [as 别名]
def purge_descriptions(self):
"""
purges the Description collection of all 'obsolete' tokens
:return:
"""
user_id = ThreadLocal.get_current_user().id
bulk = self.DescriptionCollection.initialize_unordered_bulk_op()
bulk.find({'user_id': user_id}).remove()
bulk.execute()
示例9: __init__
# 需要导入模块: from django_tools.middlewares import ThreadLocal [as 别名]
# 或者: from django_tools.middlewares.ThreadLocal import get_current_user [as 别名]
def __init__(self, target_object, data=None, initial=None):
""" prefill some user info """
if initial is None:
initial = {}
current_user = ThreadLocal.get_current_user()
if current_user.is_authenticated():
initial["name"] = current_user.get_full_name() or current_user.username
initial["email"] = current_user.email
super(PyLucidCommentForm, self).__init__(target_object, data, initial)
示例10: save
# 需要导入模块: from django_tools.middlewares import ThreadLocal [as 别名]
# 或者: from django_tools.middlewares.ThreadLocal import get_current_user [as 别名]
def save(self, *args, **kwargs):
"""
Automatic update createby and lastupdateby attributes with the request object witch must be
the first argument.
"""
current_user = ThreadLocal.get_current_user()
if current_user and isinstance(current_user, User):
if self.pk == None or kwargs.get("force_insert", False): # New model entry
self.createby = current_user
self.lastupdateby = current_user
return super(UpdateInfoBaseModel, self).save(*args, **kwargs)
示例11: all_accessible
# 需要导入模块: from django_tools.middlewares import ThreadLocal [as 别名]
# 或者: from django_tools.middlewares.ThreadLocal import get_current_user [as 别名]
def all_accessible(self, user=None, filter_showlinks=False):
""" returns a PageTree queryset with all items that the given user can access. """
if user == None:
user = ThreadLocal.get_current_user()
queryset = self.model.on_site.order_by("position")
queryset = self.filter_accessible(queryset, user)
if filter_showlinks:
# Filter PageTree.showlinks
queryset = queryset.filter(showlinks=True)
return queryset
示例12: create_description
# 需要导入模块: from django_tools.middlewares import ThreadLocal [as 别名]
# 或者: from django_tools.middlewares.ThreadLocal import get_current_user [as 别名]
def create_description(self, stages=list(), attributes=dict()):
self.purge_descriptions()
fields = dict(
stages=stages,
attributes=attributes,
created_on=data_utils.get_datetime(),
user_id=ThreadLocal.get_current_user().id
)
doc = self.DescriptionCollection.insert(fields)
# return inserted record
df = self.GET(str(doc))
return df
示例13: isValidCredentials
# 需要导入模块: from django_tools.middlewares import ThreadLocal [as 别名]
# 或者: from django_tools.middlewares.ThreadLocal import get_current_user [as 别名]
def isValidCredentials(self, user_id):
# check if token exists for user
token = Figshare().get_token_for_user(user_id=ThreadLocal.get_current_user().id)
if token:
# now check if token works
headers = {'Authorization': 'token ' + token['token']}
r = requests.get('https://api.figshare.com/v2/account/articles', headers=headers)
if r.status_code == 200:
return True
else:
# we have an invalid token stored, so we should delete it and prompt the user for a new one
Figshare().delete_tokens_for_user(user_id=user_id)
return False
示例14: get_profiles_status
# 需要导入模块: from django_tools.middlewares import ThreadLocal [as 别名]
# 或者: from django_tools.middlewares.ThreadLocal import get_current_user [as 别名]
def get_profiles_status(self):
from .copo_da import Profile
# this method examines all the profiles owned by the current user and returns
# the number of profiles which have been marked as dirty
issues = {}
issue_desc = []
issue_id = []
issues_count = 0
try:
user_id = ThreadLocal.get_current_user().id
prof = Profiles.find({"user_id": user_id})
except AttributeError as e:
prof = []
# iterate profiles and find collections which are dirty
for p in prof:
try:
collections_ids = p['collections']
except:
issues_count += 1
context = {}
context["profile_name"] = p['title']
context["link"] = reverse('copo:view_copo_profile', args=[p["_id"]])
issue_desc.append(STATUS_CODES['PROFILE_EMPTY'].format(**context))
break
# now get the corresponding collection_heads
collections_heads = Collections.find({'_id': {'$in': collections_ids}},
{'is_clean': 1, 'collection_details': 1})
# for c in collections_heads:
# try:
# if c['is_clean'] == 0:
# profile = Profile().get_profile_from_collection_id(c["_id"])
# issues_count += 1
# context = {}
# context["profile_name"] = p['title']
# context["link"] = reverse('copo:view_copo_profile', args=[profile["_id"]])
#
# # now work out why the collection is dirty
# if False:
# pass
# else:
# issue_desc.append(STATUS_CODES['PROFILE_NOT_DEPOSITED'].format(**context))
# except:
# pass
issues['issue_id_list'] = issue_id
issues['num_issues'] = issues_count
issues['issue_description_list'] = issue_desc
return issues
示例15: save_record
# 需要导入模块: from django_tools.middlewares import ThreadLocal [as 别名]
# 或者: from django_tools.middlewares.ThreadLocal import get_current_user [as 别名]
def save_record(self, auto_fields=dict(), **kwargs):
if kwargs.get("datafile_ids", list()):
datafile_ids = kwargs.get("datafile_ids")
kwargs["bundle"] = datafile_ids
# get the target repository from one of the files
repo = DataFile().get_record_property(datafile_ids[0], "target_repository")
for k, v in dict(
repository=repo,
status=False,
complete='false',
user_id=ThreadLocal.get_current_user().id,
).items():
auto_fields[self.get_qualified_field(k)] = v
return super(Submission, self).save_record(auto_fields, **kwargs)