本文整理汇总了Python中anaf.core.models.ModuleSetting.get_for_module方法的典型用法代码示例。如果您正苦于以下问题:Python ModuleSetting.get_for_module方法的具体用法?Python ModuleSetting.get_for_module怎么用?Python ModuleSetting.get_for_module使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类anaf.core.models.ModuleSetting
的用法示例。
在下文中一共展示了ModuleSetting.get_for_module方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from anaf.core.models import ModuleSetting [as 别名]
# 或者: from anaf.core.models.ModuleSetting import get_for_module [as 别名]
def __init__(self, user, *args, **kwargs):
"Sets choices and initial value"
super(SettingsForm, self).__init__(*args, **kwargs)
self.user = user
self.fields['default_contact_type'].label = _('Default Contact Type')
self.fields['default_contact_type'].queryset = Object.filter_permitted(user,
ContactType.objects, mode='x')
try:
conf = ModuleSetting.get_for_module('anaf.messaging', 'default_contact_type',
user=user)[0]
default_contact_type = ContactType.objects.get(pk=long(conf.value))
self.fields[
'default_contact_type'].initial = default_contact_type.id
except:
pass
self.fields['default_imap_folder'].label = _('Default IMAP Folder')
try:
conf = ModuleSetting.get_for_module('anaf.messaging', 'default_imap_folder',
user=user)[0]
self.fields['default_imap_folder'].initial = conf.value
except:
self.fields[
'default_imap_folder'].initial = settings.ANAF_MESSAGING_IMAP_DEFAULT_FOLDER_NAME
self.fields['signature'].label = _('Signature')
try:
conf = ModuleSetting.get_for_module('anaf.messaging', 'signature',
user=user, strict=True)[0]
signature = conf.value
self.fields['signature'].initial = signature
except:
pass
示例2: email_caller_on_new_ticket
# 需要导入模块: from anaf.core.models import ModuleSetting [as 别名]
# 或者: from anaf.core.models.ModuleSetting import get_for_module [as 别名]
def email_caller_on_new_ticket(sender, instance, created, **kwargs):
"When a new ticket is created send an email to the caller"
if created:
send_email_to_caller = False
try:
conf = ModuleSetting.get_for_module(
'anaf.services', 'send_email_to_caller')[0]
send_email_to_caller = conf.value
except:
send_email_to_caller = settings.ANAF_SEND_EMAIL_TO_CALLER
if send_email_to_caller:
# don't send email to yourself
creator_contact = None
if instance.creator:
creator_contact = instance.creator.get_contact()
if instance.caller and instance.caller != creator_contact:
if not instance.reference:
if instance.queue:
instance.reference = instance.queue.ticket_code + \
str(instance.id)
else:
instance.reference = str(instance.id)
instance.save()
subject = "[#{0!s}] {1!s}".format(instance.reference, instance.name)
# Construct context and render to html, body
context = {'ticket': instance}
try:
conf = ModuleSetting.get_for_module(
'anaf.services', 'send_email_template')[0]
send_email_template = conf.value
html = render_string_template(send_email_template, context)
except:
html = render_to_string(
'services/emails/notify_caller', context, response_format='html')
body = strip_tags(html)
if instance.queue and instance.queue.message_stream:
stream = instance.queue.message_stream
if stream.outgoing_server_name:
try:
caller_email = instance.caller.get_email()
if caller_email:
toaddr = caller_email
ssl = False
if stream.outgoing_server_type == 'SMTP-SSL':
ssl = True
email = BaseEmail(stream.outgoing_server_name,
stream.outgoing_server_username,
stream.outgoing_password,
stream.outgoing_email,
toaddr, subject, body, html=html,
ssl=ssl)
email.process_email()
except:
pass
示例3: create_instance
# 需要导入模块: from anaf.core.models import ModuleSetting [as 别名]
# 或者: from anaf.core.models.ModuleSetting import get_for_module [as 别名]
def create_instance(self, request, *args, **kwargs):
ticket = Ticket(creator=request.user.profile)
if not request.agent:
if request.queue:
ticket.queue = request.queue
if request.queue.default_ticket_status:
ticket.status = request.queue.default_ticket_status
else:
try:
conf = ModuleSetting.get_for_module(
'anaf.services', 'default_ticket_status')[0]
ticket.status = TicketStatus.objects.get(
pk=long(conf.value))
except:
if 'statuses' in request.context:
try:
ticket.status = request.context['statuses'][0]
except:
pass
ticket.priority = request.queue.default_ticket_priority
ticket.service = request.queue.default_service
else:
try:
conf = ModuleSetting.get_for_module(
'anaf.services', 'default_ticket_status')[0]
ticket.status = TicketStatus.objects.get(
pk=long(conf.value))
except:
if 'statuses' in request.context:
try:
ticket.status = request.context['statuses'][0]
except:
pass
try:
conf = ModuleSetting.get_for_module(
'anaf.services', 'default_ticket_queue')[0]
ticket.queue = TicketQueue.objects.get(pk=long(conf.value))
except:
if 'queues' in request.context:
try:
ticket.queue = request.context['queues'][0]
except:
pass
try:
ticket.caller = request.user.profile.get_contact()
except:
pass
return ticket
示例4: invoice
# 需要导入模块: from anaf.core.models import ModuleSetting [as 别名]
# 或者: from anaf.core.models.ModuleSetting import get_for_module [as 别名]
def invoice(self):
"Create a new sale order for self"
new_invoice = SaleOrder()
try:
conf = ModuleSetting.get_for_module(
'anaf.sales', 'default_order_status')[0]
new_invoice.status = long(conf.value)
except Exception:
ss = SaleStatus.objects.all()[0]
new_invoice.status = ss
so = SaleSource.objects.all()[0]
new_invoice.source = so
new_invoice.client = self.client
new_invoice.reference = "Subscription Invoice " + \
str(datetime.today().strftime('%Y-%m-%d'))
new_invoice.save()
try:
op = self.orderedproduct_set.filter(
trash=False).order_by('-date_created')[0]
opn = OrderedProduct()
opn.order = new_invoice
opn.product = self.product
opn.quantity = op.quantity
opn.discount = op.discount
opn.subscription = self
opn.save()
except IndexError:
opn = OrderedProduct()
opn.order = new_invoice
opn.product = self.product
opn.quantity = 1
opn.subscription = self
opn.save()
return new_invoice.reference
示例5: settings_view
# 需要导入模块: from anaf.core.models import ModuleSetting [as 别名]
# 或者: from anaf.core.models.ModuleSetting import get_for_module [as 别名]
def settings_view(request, response_format='html'):
"Settings"
if not request.user.profile.is_admin('anaf.infrastructure'):
return user_denied(request, message="You are not an Administrator of the Infrastructure module",
response_format=response_format)
item_types = ItemType.objects.all().filter(trash=False)
item_statuses = ItemStatus.objects.all().filter(trash=False)
item_fields = ItemField.objects.all().filter(trash=False)
default_item_status = None
try:
conf = ModuleSetting.get_for_module(
'anaf.infrastructure', 'default_item_status')[0]
default_item_status = ItemStatus.objects.get(
pk=long(conf.value), trash=False)
except Exception:
pass
context = _get_default_context(request)
context.update({'item_types': item_types,
'item_fields': item_fields,
'item_statuses': item_statuses,
'default_item_status': default_item_status})
return render_to_response('infrastructure/settings_view', context,
context_instance=RequestContext(request), response_format=response_format)
示例6: messaging_compose
# 需要导入模块: from anaf.core.models import ModuleSetting [as 别名]
# 或者: from anaf.core.models.ModuleSetting import get_for_module [as 别名]
def messaging_compose(request, response_format='html'):
"New message page"
user = request.user.profile
if request.POST:
if 'cancel' not in request.POST:
message = Message()
message.author = user.get_contact()
if not message.author:
return user_denied(request,
message="You can't send message without a Contact Card assigned to you.",
response_format=response_format)
form = MessageForm(
request.user.profile, None, None, request.POST, instance=message)
if form.is_valid():
message = form.save()
message.recipients.add(user.get_contact())
message.set_user_from_request(request)
message.read_by.add(user)
try:
# if email entered create contact and add to recipients
if 'multicomplete_recipients' in request.POST and request.POST['multicomplete_recipients']:
try:
conf = ModuleSetting.get_for_module(
'anaf.messaging', 'default_contact_type')[0]
default_contact_type = ContactType.objects.get(
pk=long(conf.value))
except Exception:
default_contact_type = None
emails = request.POST[
'multicomplete_recipients'].split(',')
for email in emails:
emailstr = unicode(email).strip()
if re.match('[a-zA-Z0-9+_\-\.][email protected][0-9a-zA-Z][.-0-9a-zA-Z]*.[a-zA-Z]+', emailstr):
contact, created = Contact.get_or_create_by_email(
emailstr, contact_type=default_contact_type)
message.recipients.add(contact)
if created:
contact.set_user_from_request(request)
except:
pass
# send email to all recipients
message.send_email()
return HttpResponseRedirect(reverse('messaging'))
else:
return HttpResponseRedirect(reverse('messaging'))
else:
form = MessageForm(request.user.profile, None)
context = _get_default_context(request)
context.update({'form': form})
return render_to_response('messaging/message_compose', context,
context_instance=RequestContext(request), response_format=response_format)
示例7: process_msg
# 需要导入模块: from anaf.core.models import ModuleSetting [as 别名]
# 或者: from anaf.core.models.ModuleSetting import get_for_module [as 别名]
def process_msg(self, msg, attrs, attachments):
"""Save message, Cap!"""
from anaf.messaging.models import Message
try:
conf = ModuleSetting.get_for_module("anaf.messaging", "default_contact_type")[0]
default_contact_type = ContactType.objects.get(pk=long(conf.value))
except:
default_contact_type = None
email_author, created = Contact.get_or_create_by_email(
attrs.author_email, attrs.author_name, default_contact_type
)
if created:
email_author.copy_permissions(self.stream)
# check if the message is already retrieved
existing = Message.objects.filter(
stream=self.stream, title=attrs.subject, author=email_author, body=attrs.body
).exists()
if not existing:
message = None
if attrs.subject[:3] == "Re:":
# process replies
if attrs.subject[:4] == "Re: ":
original_subject = attrs.subject[4:]
else:
original_subject = attrs.subject[3:]
try:
query = (
Q(reply_to__isnull=True)
& Q(recipients=email_author)
& (Q(title=original_subject) | Q(title=attrs.subject))
)
original = Message.objects.filter(query).order_by("-date_created")[:1][0]
message = Message(
title=attrs.subject, body=attrs.body, author=email_author, stream=self.stream, reply_to=original
)
if attrs.email_date:
message.date_created = attrs.email_date
message.save()
message.copy_permissions(original)
original.read_by.clear()
except IndexError:
pass
if not message:
message = Message(title=attrs.subject, body=attrs.body, author=email_author, stream=self.stream)
if attrs.email_date:
message.date_created = attrs.email_date
message.save()
message.copy_permissions(self.stream)
message.recipients.add(email_author)
示例8: save
# 需要导入模块: from anaf.core.models import ModuleSetting [as 别名]
# 或者: from anaf.core.models.ModuleSetting import get_for_module [as 别名]
def save(self, *args, **kwargs):
"Automatically set order reference"
super(SaleOrder, self).save(*args, **kwargs)
try:
conf = ModuleSetting.get_for_module(
'anaf.sales', 'order_fulfil_status')[0]
fulfil_status = long(conf.value)
if self.status.id == fulfil_status:
self.fulfil()
except Exception:
pass
示例9: create_ticket_from_message
# 需要导入模块: from anaf.core.models import ModuleSetting [as 别名]
# 或者: from anaf.core.models.ModuleSetting import get_for_module [as 别名]
def create_ticket_from_message(sender, instance, created, **kwargs):
"""
Get a signal from messaging.models
Check if (new) message's stream is also assigned to Ticket Queue
Create a new ticket from that message
Rename original message title
"""
if created and getattr(instance, 'auto_notify', True):
if instance.reply_to:
tickets = instance.reply_to.ticket_set.all()
for ticket in tickets:
record = TicketRecord()
record.sender = instance.author
record.record_type = 'manual'
record.body = instance.body
record.save()
record.about.add(ticket)
ticket.set_last_updated()
else:
stream = instance.stream
queues = TicketQueue.objects.filter(message_stream=stream)
if stream and queues:
queue = queues[0]
ticket = Ticket()
try:
conf = ModuleSetting.get_for_module(
'anaf.services', 'default_ticket_status')[0]
ticket.status = TicketStatus.objects.get(
pk=long(conf.value))
except:
statuses = TicketStatus.objects.all()
ticket.status = statuses[0]
ticket.queue = queue
ticket.caller = instance.author
ticket.details = instance.body
ticket.message = instance
ticket.name = instance.title
ticket.auto_notify = False
ticket.save()
try:
if stream.creator:
ticket.set_user(stream.creator)
elif queue.creator:
ticket.set_user(queue.creator)
else:
ticket.copy_permissions(queue)
except:
pass
# Rename original message title
instance.title = "[#" + ticket.reference + "] " + instance.title
instance.save()
示例10: create
# 需要导入模块: from anaf.core.models import ModuleSetting [as 别名]
# 或者: from anaf.core.models.ModuleSetting import get_for_module [as 别名]
def create(self, request, *args, **kwargs):
"Send email to some recipients"
user = request.user.profile
if request.data is None:
return rc.BAD_REQUEST
if 'stream' in request.data:
stream = getOrNone(MessageStream, request.data['stream'])
if stream and not user.has_permission(stream, mode='x'):
return rc.FORBIDDEN
message = Message()
message.author = user.get_contact()
if not message.author:
return rc.FORBIDDEN
form = MessageForm(user, None, None, request.data, instance=message)
if form.is_valid():
message = form.save()
message.recipients.add(user.get_contact())
message.set_user_from_request(request)
message.read_by.add(user)
try:
# if email entered create contact and add to recipients
if 'multicomplete_recipients' in request.POST and request.POST['multicomplete_recipients']:
try:
conf = ModuleSetting.get_for_module(
'anaf.messaging', 'default_contact_type')[0]
default_contact_type = ContactType.objects.get(
pk=long(conf.value))
except Exception:
default_contact_type = None
emails = request.POST[
'multicomplete_recipients'].split(',')
for email in emails:
emailstr = unicode(email).strip()
if re.match('[a-zA-Z0-9+_\-\.][email protected][0-9a-zA-Z][.-0-9a-zA-Z]*.[a-zA-Z]+', emailstr):
contact, created = Contact.get_or_create_by_email(
emailstr, contact_type=default_contact_type)
message.recipients.add(contact)
if created:
contact.set_user_from_request(request)
except:
pass
# send email to all recipients
message.send_email()
return message
else:
self.status = 400
return form.errors
示例11: __init__
# 需要导入模块: from anaf.core.models import ModuleSetting [as 别名]
# 或者: from anaf.core.models.ModuleSetting import get_for_module [as 别名]
def __init__(self, stream):
self.stream = stream
self.active = True
try:
conf = ModuleSetting.get_for_module("anaf.messaging", "default_imap_folder")[0]
folder_name = conf.value
except:
folder_name = None
super(EmailStream, self).__init__(
stream.incoming_server_type,
stream.incoming_server_name,
stream.incoming_server_username,
stream.incoming_password,
folder_name,
)
示例12: check_status
# 需要导入模块: from anaf.core.models import ModuleSetting [as 别名]
# 或者: from anaf.core.models.ModuleSetting import get_for_module [as 别名]
def check_status(self):
"""
Checks and sets the state of the subscription
"""
if not self.active:
return 'Inactive'
if self.expiry and datetime.now() > datetime.combine(self.expiry, time.min):
self.deactivate()
return 'Expired'
if not self.cycle_end:
self.renew()
cycle_end = self.cycle_end
# check if we're in the 5 day window before the cycle ends for this
# subscription
if datetime.now().date() >= cycle_end:
cycle_start = self.get_cycle_start()
# if we haven't already invoiced them, invoice them
grace = 3
if datetime.now().date() - cycle_end > timedelta(days=grace):
# Subscription has overrun and must be shut down
return self.deactivate()
try:
conf = ModuleSetting.get_for_module(
'anaf.sales', 'order_fulfil_status')[0]
order_fulfil_status = SaleStatus.objects.get(
pk=long(conf.value))
except Exception:
order_fulfil_status = None
if self.orderedproduct_set.filter(order__datetime__gte=cycle_start).filter(
order__status=order_fulfil_status):
return 'Paid'
elif self.orderedproduct_set.filter(order__datetime__gte=cycle_start):
return 'Invoiced'
else:
self.invoice()
return 'Invoiced'
else:
return 'Active'
示例13: sync
# 需要导入模块: from anaf.core.models import ModuleSetting [as 别名]
# 或者: from anaf.core.models.ModuleSetting import get_for_module [as 别名]
def sync(user=None):
if user:
conf = ModuleSetting.get('nuvius_profile', user=user, strict=True)
else:
conf = ModuleSetting.get('nuvius_profile')
for item in conf:
profile = item.loads()
user = item.user
if user:
connector = Connector(profile_id=profile['id'])
active_resources = ModuleSetting.get_for_module(
'anaf.identities', 'integration_resource', user=user, strict=True)
for resource in active_resources:
res = resource.loads()
response = connector.get(
'/service/contact-book/contact/data.json/id' + profile['id'] + '/app' + str(res.resource_id))
data = DataBlock(response['data'])
if data.result_name == 'success':
_do_sync(data, user)