本文整理汇总了Python中maker.core.models.ModuleSetting.get_for_module方法的典型用法代码示例。如果您正苦于以下问题:Python ModuleSetting.get_for_module方法的具体用法?Python ModuleSetting.get_for_module怎么用?Python ModuleSetting.get_for_module使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类maker.core.models.ModuleSetting
的用法示例。
在下文中一共展示了ModuleSetting.get_for_module方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from maker.core.models import ModuleSetting [as 别名]
# 或者: from maker.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('maker.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('maker.messaging', 'default_imap_folder',
user=user)[0]
self.fields['default_imap_folder'].initial = conf.value
except:
self.fields['default_imap_folder'].initial = settings.MAKER_MESSAGING_IMAP_DEFAULT_FOLDER_NAME
self.fields['signature'].label = _('Signature')
try:
conf = ModuleSetting.get_for_module('maker.messaging', 'signature',
user=user, strict=True)[0]
signature = conf.value
self.fields['signature'].initial = signature
except:
pass
示例2: save
# 需要导入模块: from maker.core.models import ModuleSetting [as 别名]
# 或者: from maker.core.models.ModuleSetting import get_for_module [as 别名]
def save(self):
"Form processor"
try:
ModuleSetting.set_for_module('default_perspective',
self.cleaned_data['default_perspective'].id,
'maker.core')
ModuleSetting.set_for_module('default_permissions',
self.cleaned_data['default_permissions'],
'maker.core')
ModuleSetting.set_for_module('default_timezone',
self.cleaned_data['default_timezone'],
'maker.core')
ModuleSetting.set_for_module('language',
self.cleaned_data['language'],
'maker.core')
if getattr(settings, 'MAKER_SUBSCRIPTION_CUSTOMIZATION', True):
if isinstance(self.fields['logo'], forms.FileField):
logopath = self._handle_uploaded_file('logo')
ModuleSetting.set_for_module('logopath', logopath, 'maker.core')
elif isinstance(self.fields['logo'], forms.ChoiceField):
if self.cleaned_data['logo'] == 'delete':
try:
ModuleSetting.get_for_module('maker.core', 'logopath').delete()
except:
pass
return True
except:
return False
示例3: email_caller_on_new_ticket
# 需要导入模块: from maker.core.models import ModuleSetting [as 别名]
# 或者: from maker.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('maker.services', 'send_email_to_caller')[0]
send_email_to_caller = conf.value
except:
send_email_to_caller = getattr(settings, 'HARDTREE_SEND_EMAIL_TO_CALLER', True)
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 = "[#%s] %s" % (instance.reference, instance.name)
# Construct context and render to html, body
context = {'ticket': instance}
try:
conf = ModuleSetting.get_for_module('maker.services', 'send_email_template')[0]
send_email_template = conf.value
html = render_string_template(send_email_template, context)
except Exception, e:
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
示例4: logo_image
# 需要导入模块: from maker.core.models import ModuleSetting [as 别名]
# 或者: from maker.core.models.ModuleSetting import get_for_module [as 别名]
def logo_image(request, gif=False, response_format='html'):
"Return current logo image"
staticpath = getattr(settings, 'STATIC_DOC_ROOT', './static')
logopath = staticpath + '/logo'
if gif:
logopath += '.gif'
mimetype = 'image/gif'
else:
logopath += '.png'
mimetype = 'image/png'
customlogo = ''
try:
conf = ModuleSetting.get_for_module('maker.core', 'logopath')[0]
customlogo = getattr(settings, 'MEDIA_ROOT', './static/media') + conf.value
except:
pass
logofile = ''
if customlogo:
try:
logofile = open(customlogo, 'rb')
except:
pass
if not logofile:
try:
logofile = open(logopath, 'rb')
except:
pass
return HttpResponse(logofile.read(), mimetype=mimetype)
示例5: invoice
# 需要导入模块: from maker.core.models import ModuleSetting [as 别名]
# 或者: from maker.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('maker.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
示例6: core_logo_content
# 需要导入模块: from maker.core.models import ModuleSetting [as 别名]
# 或者: from maker.core.models.ModuleSetting import get_for_module [as 别名]
def core_logo_content(context, gif=False):
"Return current logo encoded as base64"
staticpath = getattr(settings, 'STATIC_DOC_ROOT', './static')
logopath = staticpath + '/logo'
if gif:
logopath += '.gif'
mimetype = 'image/gif'
else:
logopath += '.png'
mimetype = 'image/png'
customlogo = ''
try:
conf = ModuleSetting.get_for_module('maker.core', 'logopath')[0]
customlogo = getattr(settings, 'MEDIA_ROOT', './static/media') + conf.value
except:
pass
logofile = ''
if customlogo:
try:
logofile = open(customlogo, 'r')
except:
pass
if not logofile:
try:
logofile = open(logopath, 'r')
except:
pass
result = "data:" + mimetype + ";base64," + base64.b64encode(logofile.read())
return Markup(result)
示例7: settings_view
# 需要导入模块: from maker.core.models import ModuleSetting [as 别名]
# 或者: from maker.core.models.ModuleSetting import get_for_module [as 别名]
def settings_view(request, response_format='html'):
"Settings"
if not request.user.get_profile().is_admin('maker.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('maker.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)
示例8: create_instance
# 需要导入模块: from maker.core.models import ModuleSetting [as 别名]
# 或者: from maker.core.models.ModuleSetting import get_for_module [as 别名]
def create_instance(self, request, *args, **kwargs):
ticket = Ticket(creator=request.user.get_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('maker.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('maker.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('maker.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.get_profile().get_contact()
except:
pass
return ticket
示例9: save
# 需要导入模块: from maker.core.models import ModuleSetting [as 别名]
# 或者: from maker.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('maker.sales', 'order_fulfil_status')[0]
fulfil_status = long(conf.value)
if self.status.id == fulfil_status:
self.fulfil()
except Exception:
pass
示例10: __init__
# 需要导入模块: from maker.core.models import ModuleSetting [as 别名]
# 或者: from maker.core.models.ModuleSetting import get_for_module [as 别名]
def __init__(self, stream):
self.stream = stream
self.active = True
try:
conf = ModuleSetting.get_for_module('maker.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)
示例11: messaging_compose
# 需要导入模块: from maker.core.models import ModuleSetting [as 别名]
# 或者: from maker.core.models.ModuleSetting import get_for_module [as 别名]
def messaging_compose(request, response_format='html'):
"New message page"
user = request.user.get_profile()
if request.POST:
if not 'cancel' 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.get_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('maker.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.get_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)
示例12: create_ticket_from_message
# 需要导入模块: from maker.core.models import ModuleSetting [as 别名]
# 或者: from maker.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('maker.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()
示例13: create
# 需要导入模块: from maker.core.models import ModuleSetting [as 别名]
# 或者: from maker.core.models.ModuleSetting import get_for_module [as 别名]
def create(self, request, *args, **kwargs):
"Send email to some recipients"
user = request.user.get_profile()
if request.data is None:
return rc.BAD_REQUEST
if request.data.has_key('stream'):
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('maker.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