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
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
def __init__(self, user, *args, **kwargs): "Sets choices and initial value" super(SettingsForm, self).__init__(*args, **kwargs) self.fields['my_company'].queryset = Object.filter_permitted(user, Contact.objects) self.fields['my_company'].widget.attrs.update({'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup')}) self.fields['default_account'].queryset = Object.filter_permitted(user, Account.objects) # Translation self.fields['default_currency'].label=_('Base Currency') self.fields['my_company'].label=_('My Company') self.fields['default_account'].label=_('Default Account') try: self.fields['default_currency'].widget.attrs.update({'popuplink': reverse('finance_currency_add')}) self.fields['default_currency'].queryset = Currency.objects.all() self.fields['default_currency'].initial = Currency.objects.get(is_default=True) except Exception: pass try: conf = ModuleSetting.get_for_module('maker.finance', 'my_company')[0] my_company = Contact.objects.get(pk=long(conf.value)) self.fields['my_company'].initial = my_company.id except Exception: pass try: conf = ModuleSetting.get_for_module('maker.finance', 'default_account')[0] default_account = Account.objects.get(pk=long(conf.value)) self.fields['default_account'].initial = default_account.id except Exception: pass
def __init__(self, user, lead, *args, **kwargs): super(OpportunityForm, self).__init__(*args, **kwargs) self.fields['lead'].queryset = Object.filter_permitted(user, Lead.objects) self.fields['contact'].queryset = Object.filter_permitted(user, Contact.objects) self.fields['contact'].widget.attrs.update({'popuplink': reverse('identities_contact_add')}) self.fields['contact'].widget.attrs.update({'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup')}) self.fields['products_interested'].queryset = Object.filter_permitted(user, Product.objects) self.fields['products_interested'].widget.attrs.update({'popuplink': reverse('sales_product_add')}) try: conf = ModuleSetting.get_for_module('maker.sales', 'default_order_product')[0] self.fields['products_interested'].initial = [long(conf.value)] except: pass self.fields['source'].queryset = Object.filter_permitted(user, SaleSource.objects.filter(active=True)) self.fields['status'].queryset = Object.filter_permitted(user, SaleStatus.objects.filter(use_opportunities=True)) self.fields['assigned'].widget.attrs.update({'class': 'multicomplete', 'callback': reverse('identities_ajax_user_lookup')}) try: conf = ModuleSetting.get_for_module('maker.sales', 'default_opportunity_status')[0] self.fields['status'].initial = long(conf.value) except: pass if lead: self.fields['lead'].initial = lead.id self.fields['contact'].initial = lead.contact_id self.fields['products_interested'].initial = [i.id for i in lead.products_interested.only('id')] self.fields['source'].initial = lead.source_id self.fields['assigned'].initial = [i.id for i in lead.assigned.only('id')] else: del self.fields['lead'] self.fields['products_interested'].help_text = "" self.fields['assigned'].help_text = "" self.fields['expected_date'].widget.attrs.update({'class': 'datepicker'}) self.fields['closed_date'].widget.attrs.update({'class': 'datepicker'}) self.fields['contact'].label = _("Contact") self.fields['products_interested'].label = _("Products interested") self.fields['source'].label = _("Source") self.fields['expected_date'].label = _("Expected date") self.fields['closed_date'].label = _("Closed date") self.fields['assigned'].label = _("Assigned to") self.fields['amount_display'].label = _("Amount") self.fields['amount_currency'].label = _("Currency") self.fields['amount_currency'].widget.attrs.update({'popuplink': reverse('finance_currency_add')}) self.fields['amount_currency'].initial = Currency.objects.get(is_default=True) self.fields['probability'].label = _("Probability") self.fields['status'].label = _("Status") self.fields['details'].label = _("Details")
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
def __init__(self, *args, **kwargs): self.user = kwargs.pop('user', None) super(UpdateRecordForm, self).__init__(*args, **kwargs) self.fields['body'].required = True self.fields['body'].label = _("Details") self.fields['recipients'].help_text = "" self.fields['recipients'].required = False self.fields['recipients'].widget.attrs.update({'class': 'multicomplete', 'callback': reverse('identities_ajax_access_lookup')}) # get default permissions from settings try: conf = ModuleSetting.get_for_module('maker.core', 'default_permissions')[0] default_permissions = conf.value except: default_permissions = settings.MAKER_DEFAULT_PERMISSIONS if self.user and 'userallgroups' in default_permissions: self.fields['recipients'].initial = [i.id for i in self.user.other_groups.all().only('id')] self.fields['recipients'].initial.append(self.user.default_group.id) elif self.user and 'usergroup' in default_permissions: self.fields['recipients'].initial = [self.user.default_group.id]
def __init__(self, user, *args, **kwargs): super(ChangeSetForm, self ).__init__(*args, **kwargs) self.user = None if user: self.user = user self.fields['name'].label = _("Name") self.fields['name'].widget.attrs.update({'size': 50}) self.fields['object'].label = _("Object") self.fields['object'] = ObjectModelChoiceField(label=_("Object"), queryset = Object.filter_permitted(user, Object.objects)) self.fields['object'].widget.attrs.update({'class': 'autocomplete', 'callback': reverse('core_ajax_object_lookup')}) if 'object_id' in kwargs: self.fields['parent'].initial = kwargs['object_id'] del kwargs['object_id'] try: conf = ModuleSetting.get_for_module('maker.changes', 'default_changeset_status')[0] default_changeset_status = ChangeSetStatus.objects.get(pk=long(conf.value)) if not default_changeset_status.trash: self.fields['status'].initial = default_changeset_status.id except Exception: pass self.fields['status'].label = _("Status") self.fields['details'].label = _("Details")
def __init__(self, user, project_id, *args, **kwargs): super(MilestoneForm, self ).__init__(*args, **kwargs) self.fields['name'].label = _("Name") self.fields['project'].label = _("Project") self.fields['project'].queryset = Object.filter_permitted(user, Project.objects, mode='x') if project_id: self.fields['project'].initial = project_id self.fields['status'].label = _("Status") self.fields['status'].queryset = Object.filter_permitted(user, TaskStatus.objects, mode='x') try: conf = ModuleSetting.get_for_module('maker.projects', 'default_task_status')[0] self.fields['status'].initial = long(conf.value) except Exception: pass # Set datepicker self.fields['start_date'].label = _("Start date") self.fields['start_date'].widget.attrs.update({'class': 'datetimepicker'}) self.fields['end_date'].label = _("End date") self.fields['end_date'].widget.attrs.update({'class': 'datetimepicker'}) if 'instance' in kwargs: instance = kwargs['instance'] if instance.start_date: self.fields['start_date'].widget.attrs.update({'initial': instance.start_date.strftime('%s')}) if instance.end_date: self.fields['end_date'].widget.attrs.update({'initial': instance.end_date.strftime('%s')}) self.fields['details'].label = _("Details")
def __init__(self, user, *args, **kwargs): super(EquityForm, self ).__init__(*args, **kwargs) self.fields['equity_type'].label = _("Equity type") self.fields['issue_price'].label = _("Issue price") self.fields['sell_price'].label = _("Sell price") self.fields['issuer'].label = _("Issuer") self.fields['owner'].label = _("Owner") self.fields['amount'].label = _("Quantity") self.fields['purchase_date'].label = _("Purchase date") self.fields['details'].label = _("Details") self.fields['owner'].queryset = Object.filter_permitted(user, Contact.objects) self.fields['owner'].widget.attrs.update({'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup')}) self.fields['owner'].widget.attrs.update({'popuplink': reverse('identities_contact_add')}) self.fields['issuer'].queryset = Object.filter_permitted(user, Contact.objects) self.fields['issuer'].widget.attrs.update({'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup')}) self.fields['issuer'].widget.attrs.update({'popuplink': reverse('identities_contact_add')}) try: conf = ModuleSetting.get_for_module('maker.finance', 'my_company')[0] self.fields['issuer'].initial = long(conf.value) except Exception: pass self.fields['purchase_date'].widget.attrs.update({'class': 'datepicker'})
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)
def __init__(self, user, order, *args, **kwargs): super(OrderedProductForm, self).__init__(*args, **kwargs) self.fields['subscription'].queryset = Object.filter_permitted(user, Subscription.objects) self.fields['subscription'].widget.attrs.update({'class': 'autocomplete', 'callback': reverse('sales_ajax_subscription_lookup')}) self.fields['subscription'].widget.attrs.update({'popuplink': reverse('sales_subscription_add')}) self.fields['subscription'].label = _("Subscription") self.fields['product'].queryset = Object.filter_permitted(user, Product.objects.filter(active=True)) if user.is_admin('maker.sales'): self.fields['product'].widget.attrs.update({'popuplink': reverse('sales_product_add')}) self.fields['product'].label = _("Product") try: conf = ModuleSetting.get_for_module('maker.sales', 'default_order_product')[0] # AJAX to set the initial rate as the currency converted value of product sell price self.fields['product'].initial = long(conf.value) except: pass # Tax self.fields['tax'].widget.attrs.update({'popuplink': reverse('finance_tax_add')}) # TODO: rate # self.fields['rate_display'].label = _("Rate") # self.fields['rate_display'].help_text = order.currency.code self.fields['quantity'].label = _("Quantity") self.fields['quantity'].initial = 1 self.fields['discount'].label = _("Discount") self.fields['discount'].help_text = "%"
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
def __init__(self, user, stream_id, message=None, *args, **kwargs): super(MessageForm, self ).__init__(*args, **kwargs) self.fields['title'].label = _("Subject") self.fields['title'].widget = forms.TextInput(attrs = {'size':'40'}) self.fields['stream'].queryset = Object.filter_permitted(user, MessageStream.objects, mode='x') self.fields['stream'].label = _("Stream") self.fields['recipients'].label = _("To") self.fields['recipients'].help_text = "" self.fields['recipients'].widget.attrs.update({'class': 'multicomplete', 'callback': reverse('identities_ajax_contact_lookup')}) if stream_id: self.fields['stream'].initial = stream_id self.fields['stream'].widget = forms.HiddenInput() elif self.fields['stream'].queryset: self.fields['stream'].initial = self.fields['stream'].queryset[0].id self.fields['body'].label = _("Body") # signature try: conf = ModuleSetting.get_for_module('maker.messaging', 'signature', user=user, strict=True)[0] signature = conf.value self.fields['body'].initial = signature except: pass
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)
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)
def __init__(self, user, *args, **kwargs): super(LiabilityForm, self ).__init__(*args, **kwargs) self.fields['name'].label = _("Name") self.fields['category'].label = _("Category") self.fields['source'].label = _("Source") self.fields['target'].label = _("Target") self.fields['account'].label = _("Bank Account") self.fields['due_date'].label = _("Due date") self.fields['value_currency'].label = _("Currency") self.fields['value_currency'].widget.attrs.update({'popuplink': reverse('finance_currency_add')}) self.fields['value_currency'].initial = Currency.objects.get(is_default=True) self.fields['value_display'].label = _("Value") self.fields['details'].label = _("Details") self.fields['target'].queryset = Object.filter_permitted(user, Contact.objects) self.fields['target'].widget.attrs.update({'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup')}) self.fields['target'].widget.attrs.update({'popuplink': reverse('identities_contact_add')}) self.fields['account'].queryset = Object.filter_permitted(user, Account.objects) try: conf = ModuleSetting.get_for_module('maker.finance', 'default_account')[0] self.fields['account'].initial = long(conf.value) except Exception: pass self.fields['due_date'].widget.attrs.update({'class': 'datepicker'}) del self.fields['source']
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
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
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)
def __init__(self, user, *args, **kwargs): "Sets choices and initial value" super(SettingsForm, self).__init__(*args, **kwargs) self.fields['default_perspective'].label = _("Default Perspective") self.fields['language'].label = _("Language") self.fields['default_timezone'].label = _("Time Zone") self.fields['email_notifications'].label = _("E-mail Notifications") self.user = user self.fields['default_perspective'].queryset = Object.filter_permitted(user, Perspective.objects) try: conf = ModuleSetting.get_for_module('maker.core', 'default_perspective', user=self.user)[0] default_perspective = Perspective.objects.get(pk=long(conf.value)) self.fields['default_perspective'].initial = default_perspective.id except: pass self.fields['default_timezone'].choices = getattr(settings, 'MAKER_SERVER_TIMEZONE') timezone = settings.MAKER_SERVER_DEFAULT_TIMEZONE try: conf = ModuleSetting.get('default_timezone', user=user)[0] timezone = conf.value except: pass self.fields['default_timezone'].initial = timezone self.fields['language'].choices = getattr(settings, 'MAKER_LANGUAGES', [('es', 'Spanish')]) language = getattr(settings, 'MAKER_LANGUAGES_DEFAULT', '') try: conf = ModuleSetting.get('language', user=user)[0] language = conf.value except IndexError: pass self.fields['language'].initial = language try: conf = ModuleSetting.get('email_notifications', user=user)[0] self.fields['email_notifications'].initial = conf.value except: self.fields['email_notifications'].initial = settings.MAKER_ALLOW_EMAIL_NOTIFICATIONS perspective = user.get_perspective() modules = perspective.modules.filter(display=True).order_by('title') if not modules: modules = Module.objects.filter(display=True).order_by('title') self.fields['notifications_for_modules'].choices = [(module.pk, module.title) for module in modules] try: modules = NotificationSetting.objects.get(owner = self.user).modules.all() self.fields['notifications_for_modules'].initial = [m.pk for m in modules] except (NotificationSetting.DoesNotExist, NotificationSetting.MultipleObjectsReturned): pass
def __init__(self, user, *args, **kwargs): "Sets choices and initial value" super(SettingsForm, self).__init__(*args, **kwargs) self.fields['default_contact_type'].queryset = Object.filter_permitted(user, ContactType.objects) try: conf = ModuleSetting.get_for_module('maker.identities', 'default_contact_type')[0] default_task_status = ContactType.objects.get(pk=long(conf.value)) self.fields['default_contact_type'].initial = default_task_status.id except Exception: pass
def __init__(self, user, *args, **kwargs): "Sets choices and initial value" super(SettingsForm, self).__init__(*args, **kwargs) self.fields['default_item_status'].queryset = ItemStatus.objects.filter(trash=False) try: conf = ModuleSetting.get_for_module('maker.infrastructure', 'default_item_status')[0] default_item_status = ItemStatus.objects.get(pk=long(conf.value), trash=False) self.fields['default_item_status'].initial = default_item_status.id except Exception: pass
def __init__(self, user, *args, **kwargs): "Sets choices and initial value" super(SettingsForm, self).__init__(*args, **kwargs) self.fields['default_task_status'].queryset = Object.filter_permitted(user, TaskStatus.objects, mode='x') try: conf = ModuleSetting.get_for_module('maker.projects', 'default_task_status')[0] default_task_status = TaskStatus.objects.get(pk=long(conf.value)) self.fields['default_task_status'].initial = default_task_status.id except Exception: pass
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+_\-\.]+@[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)
def __init__(self, user, *args, **kwargs): "Sets choices and initial value" super(SettingsForm, self).__init__(*args, **kwargs) # Translate self.fields['default_ticket_status'].label = _('Default Ticket Status') self.fields['default_ticket_queue'].label = _('Default Queue') self.fields['send_email_to_caller'].label = _("Notify Caller By E-mail") self.fields['send_email_template'].label = _("E-mail Template") self.fields['default_ticket_status'].queryset = Object.filter_permitted(user, TicketStatus.objects, mode='x') self.fields['default_ticket_queue'].queryset = Object.filter_permitted(user, TicketQueue.objects, mode='x') try: conf = ModuleSetting.get_for_module('maker.services', 'default_ticket_status')[0] default_ticket_status = TicketStatus.objects.get(pk=long(conf.value)) self.fields['default_ticket_status'].initial = default_ticket_status.id except Exception: pass try: conf = ModuleSetting.get_for_module('maker.services', 'default_ticket_queue')[0] default_ticket_queue = TicketQueue.objects.get(pk=long(conf.value)) self.fields['default_ticket_queue'].initial = default_ticket_queue.id except Exception: pass try: conf = ModuleSetting.get_for_module('maker.services', 'send_email_to_caller')[0] self.fields['send_email_to_caller'].initial = conf.value except: self.fields['send_email_to_caller'].initial = settings.MAKER_SEND_EMAIL_TO_CALLER # notification template try: conf = ModuleSetting.get_for_module('maker.services', 'send_email_template')[0] self.fields['send_email_template'].initial = conf.value except Exception: self.fields['send_email_template'].initial = get_template_source('services/emails/notify_caller.html')
def __init__(self, user, *args, **kwargs): "Sets choices and initial value" super(SettingsForm, self).__init__(*args, **kwargs) self.fields['default_changeset_status'].queryset = ChangeSetStatus.objects.filter(trash=False) try: conf = ModuleSetting.get_for_module('maker.changes', 'default_changeset_status')[0] default_changeset_status = ChangeSetStatus.objects.get(pk=long(conf.value)) if not default_changeset_status.trash: self.fields['default_changeset_status'].initial = default_changeset_status.id except Exception: pass
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()
def __init__(self, user, *args, **kwargs): super(LeadForm, self).__init__(*args, **kwargs) self.fields['contact'].queryset = Object.filter_permitted(user, Contact.objects) self.fields['contact'].widget.attrs.update({'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup')}) self.fields['contact'].widget.attrs.update({'popuplink': reverse('identities_contact_add')}) self.fields['contact'].label = _("Contact") self.fields['source'].queryset = Object.filter_permitted(user, SaleSource.objects.filter(active=True)) self.fields['source'].label = _("Source") self.fields['products_interested'].queryset = Object.filter_permitted(user, Product.objects) self.fields['products_interested'].help_text = "" self.fields['products_interested'].widget.attrs.update({'popuplink': reverse('sales_product_add')}) self.fields['products_interested'].label = _("Products interested") self.fields['assigned'].help_text = "" self.fields['assigned'].label = _("Assigned to") self.fields['assigned'].widget.attrs.update({'class': 'multicomplete', 'callback': reverse('identities_ajax_user_lookup')}) try: conf = ModuleSetting.get_for_module('maker.sales', 'default_order_product')[0] self.fields['products_interested'].initial = [long(conf.value)] except: pass self.fields['status'].queryset = Object.filter_permitted(user, SaleStatus.objects.filter(use_leads=True)) self.fields['status'].label = _("Status") try: conf = ModuleSetting.get_for_module('maker.sales', 'default_lead_status')[0] self.fields['status'].initial = long(conf.value) except: pass self.fields['contact_method'].label = _("Contact method") self.fields['details'].label = _("Details")
def settings_view(request, response_format='html'): "Settings admin view" # default content type try: conf = ModuleSetting.get_for_module('maker.messaging', 'default_contact_type', user=request.user.get_profile())[0] default_contact_type = ContactType.objects.get(pk=long(conf.value)) except: default_contact_type = None # default imap folder try: conf = ModuleSetting.get_for_module('maker.messaging', 'default_imap_folder')[0] default_imap_folder = conf.value except: default_imap_folder = getattr(settings, 'MAKER_MESSAGING_IMAP_DEFAULT_FOLDER_NAME', 'UNSEEN') # signature try: conf = ModuleSetting.get_for_module('maker.messaging', 'signature', user=request.user.get_profile(), strict=True)[0] signature = conf.value except: signature = '' types = Object.filter_by_request(request, ContactType.objects.order_by('name')) context = _get_default_context(request) context.update({'types':types, 'signature': signature, 'default_contact_type': default_contact_type, 'default_imap_folder': default_imap_folder}) return render_to_response('messaging/settings_view', context, context_instance=RequestContext(request), response_format=response_format)
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+_\-\.]+@[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