本文整理汇总了Python中core.Core.current_user方法的典型用法代码示例。如果您正苦于以下问题:Python Core.current_user方法的具体用法?Python Core.current_user怎么用?Python Core.current_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core.Core
的用法示例。
在下文中一共展示了Core.current_user方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_update_mails
# 需要导入模块: from core import Core [as 别名]
# 或者: from core.Core import current_user [as 别名]
def send_update_mails(ticket, ticket_update):
"""
Sends email to all users who commented or created ticket
"""
assigned_sent = check_assigned_to(ticket)
recipients = set([])
if not ticket.mailbox_hash:
ticket.mailbox_hash = hashlib.sha224("ticket-%s"%ticket.id).hexdigest()
ticket.save()
if ticket.assigned_to:
if ticket.assigned_to.email:
recipients.add(ticket.assigned_to.email)
if not assigned_sent and ticket.assigned_to:
if ticket.assigned_to.email in recipients:
recipients.remove(ticket.assigned_to.email)
for recipient in ticket.get_recipients():
if recipient.email:
recipients.add(recipient.email)
if Core.current_user().email:
if Core.current_user().email in recipients:
recipients.remove(Core.current_user().email)
if ticket_update.public and ticket_update.comment:
_send_to_clients(ticket, ticket_update)
msg = _create_msg(ticket, ticket_update)
send_mail(_("Ticket update"), msg, "support+"+ticket.mailbox_hash+"@focustime.no", recipients)
示例2: products
# 需要导入模块: from core import Core [as 别名]
# 或者: from core.Core import current_user [as 别名]
def products(request, id):
supplier = Core.current_user().get_permitted_objects("VIEW", Supplier).get(id=id)
products = Core.current_user().get_permitted_objects("VIEW", Product).filter(supplier=supplier)
return render(request, 'suppliers/products.html', {'title': _("Products"),
'supplier': supplier,
'products': products})
示例3: form
# 需要导入模块: from core import Core [as 别名]
# 或者: from core.Core import current_user [as 别名]
def form (request, id=False):
if id:
instance = Core.current_user().get_permitted_objects("VIEW", Group).get(id=id)
msg = _("Successfully edited group")
else:
instance = Group()
msg = _("Successfully added new group")
#Save and set to active, require valid form
if request.method == 'POST':
form = GroupForm(request.POST, instance=instance)
if form.is_valid():
o = form.save(commit=False)
o.company = Core.current_user().get_company()
o.save()
form.save_m2m()
request.message_success(msg)
return redirect(overview)
else:
form = GroupForm(instance=instance)
return render(request, "admin/groups/form.html",
{'title': _("Group"), 'group': instance, 'form': form})
示例4: is_authenticated
# 需要导入模块: from core import Core [as 别名]
# 或者: from core.Core import current_user [as 别名]
def is_authenticated(self, request):
#Check if already logged in, for use inside the application
if Core.current_user() and Core.current_user().is_authenticated():
return True
#If not, then use basic auth
else:
auth_string = request.META.get('HTTP_AUTHORIZATION', None)
if not auth_string:
return False
(authmeth, auth) = auth_string.split(" ", 1)
if not authmeth.lower() == 'basic':
return False
auth = auth.strip().decode('base64')
(username, password) = auth.split(':', 1)
if Core.login(request, username, password):
user = User.objects.get(username=username)
return user.canLogin
return False
示例5: handle
# 需要导入模块: from core import Core [as 别名]
# 或者: from core.Core import current_user [as 别名]
def handle(self, *args, **kwargs):
randomCompanyIdentifier = str(int(random.random() * 99999))
company, user = createNewCustomer(
"Ledere",
"Bjarte Hatlenes",
"superadmin" + randomCompanyIdentifier,
"superadmin" + randomCompanyIdentifier,
"Ansatte",
"Focus Security AS" + randomCompanyIdentifier,
)
self.company = company
self.user = user
Core.set_test_user(user)
password = generate_new_password_for_user(user)
print "Company: %s " % company
print "Current user is: %s " % Core.current_user()
print "Current user is: %s " % Core.current_user().username
print "Current users password: %s " % password
self.customers = []
self.projects = []
self.seed_customers()
self.seed_contacts()
self.seed_projects()
self.seed_orders()
self.seed_offers()
self.seed_tickets()
self.seed_suppliers()
self.seed_products()
示例6: filter_current_company
# 需要导入模块: from core import Core [as 别名]
# 或者: from core.Core import current_user [as 别名]
def filter_current_company(self):
#Check if no current_user
if not Core.current_user():
return None
return super(PersistentManager, self).get_query_set().filter(deleted=False,
company=Core.current_user().get_company())
示例7: save
# 需要导入模块: from core import Core [as 别名]
# 或者: from core.Core import current_user [as 别名]
def save(self, *args, **kwargs):
self.date = datetime.now()
if 'user' in kwargs:
self.creator = kwargs['user']
else:
self.creator = Core.current_user()
if Core.current_user() and Core.current_user().get_company():
self.company = Core.current_user().get_company()
super(Log, self).save()
示例8: update
# 需要导入模块: from core import Core [as 别名]
# 或者: from core.Core import current_user [as 别名]
def update(self, request, id=None):
if id:
trackers = [Core.current_user().get_permitted_objects("EDIT", TimeTracker).get(id=id)]
else:
trackers = Core.current_user().get_permitted_objects("EDIT", TimeTracker).all()
for tracker in trackers:
try:
self._do_update(request, tracker)
except ValueError as e:
return {'error': str(e)}
return {'success': True}
示例9: save
# 需要导入模块: from core import Core [as 别名]
# 或者: from core.Core import current_user [as 别名]
def save(self, *args, **kwargs):
new = False
if not self.id:
new = True
super(Project, self).save()
self.invalidate_cache()
#Give the user who created this ALL permissions on object
if new:
Core.current_user().grant_role("Owner", self)
admin_group = Core.current_user().get_company_admingroup()
if admin_group:
admin_group.grant_role("Admin", self)
示例10: disbursements
# 需要导入模块: from core import Core [as 别名]
# 或者: from core.Core import current_user [as 别名]
def disbursements(request, id=None):
instance = Disbursement()
disb = Disbursement.objects.filter(trashed=False, creator=Core.current_user())
if id:
instance = get_object_or_404(Disbursement, id=id)
#Save and set to active, require valid form
if request.method == 'POST':
form = DisbursementForm(request.POST, request.FILES, instance=instance)
if form.is_valid():
o = form.save(commit=False)
o.save()
request.message_success("Success")
instance = Disbursement()
form = DisbursementForm(instance=instance, initial={'attachment': None})
else:
form = DisbursementForm(instance=instance, initial={'attachment': None})
return render(request, "hourregistrations/disbursements.html",
{'title': _("Disbursements"), 'disbursements': disb, 'disbursement': instance, 'form': form})
示例11: edit
# 需要导入模块: from core import Core [as 别名]
# 或者: from core.Core import current_user [as 别名]
def edit(request, id):
ticket = Core.current_user().get_permitted_objects("VIEW", Ticket).get(id=id)
updates = TicketUpdate.objects.filter(ticket=ticket).order_by("-id")
#ticket.visited_by_since_last_edit.add((Core.current_user()))
if request.method == "POST":
old_ticket = copy.copy(ticket)
ticket_form = EditTicketForm(request.POST, request.FILES, instance=ticket)
if ticket_form.is_valid():
ticket = create_update_for_ticket(old_ticket, ticket_form)
ticket.invalidate_cache()
request.message_success(_("Ticket updated"))
return redirect(edit, ticket.id)
else:
ticket_form = EditTicketForm(instance=ticket)
return render(request, "tickets/edit.html", {'title': _('Update Ticket'),
'ticket': ticket,
'updates': updates,
'form': ticket_form,
})
示例12: assigned_to_user
# 需要导入模块: from core import Core [as 别名]
# 或者: from core.Core import current_user [as 别名]
def assigned_to_user(request):
tickets = Core.current_user().get_permitted_objects("VIEW", Ticket).\
filter(trashed=False, assigned_to=request.user).order_by("status", "-priority", "-date_edited")
return render(request, 'tickets/list.html', {"title": "Tickets",
"assigned_to": True,
'tickets': tickets})
示例13: process_request
# 需要导入模块: from core import Core [as 别名]
# 或者: from core.Core import current_user [as 别名]
def process_request (self, request):
# Save the current thread with the current user
Core.attach_user(request)
request.user = Core.current_user()
return None
示例14: overview_trashed
# 需要导入模块: from core import Core [as 别名]
# 或者: from core.Core import current_user [as 别名]
def overview_trashed(request):
tickets = Core.current_user().get_permitted_objects("VIEW", Ticket).filter(trashed=True).order_by("status",
"-priority",
"-date_edited")
return render(request, 'tickets/list.html',
{"title": "Tickets", 'tickets': tickets})
示例15: delete
# 需要导入模块: from core import Core [as 别名]
# 或者: from core.Core import current_user [as 别名]
def delete(self, request, id):
try:
tracker = Core.current_user().get_permitted_objects("EDIT", TimeTracker).get(id=id)
tracker.trash()
return rc.DELETED
except TimeTracker.DoesNotExist:
return rc.NOT_FOUND