Beispiel #1
0
    def setUp(self):
        self.group = Group.objects.create(name='test')
        self.user = DjangoUser.objects.create(username=self.username)
        self.user.set_password(self.password)
        self.user.save()

        perspective = Perspective(name='default')
        perspective.set_user(self.user.profile)
        perspective.save()

        ModuleSetting.set('default_perspective', perspective.id)

        self.folder = Folder(name='test')
        self.folder.set_user(self.user.profile)
        self.folder.save()

        self.document = Document(title='test_document', folder=self.folder)
        self.document.set_user(self.user.profile)
        self.document.save()

        self.file = File(name='test_file', folder=self.folder)
        self.file.set_user(self.user.profile)
        self.file.save()

        self.link = WebLink(title='test', folder=self.folder, url='test')
        self.link.set_user(self.user.profile)
        self.link.save()
Beispiel #2
0
    def setUp(self):
        self.group, created = Group.objects.get_or_create(name='test')
        self.user, created = DjangoUser.objects.get_or_create(
            username=self.username)
        self.user.set_password(self.password)
        self.user.save()
        perspective, created = Perspective.objects.get_or_create(
            name='default')
        perspective.set_default_user()
        perspective.save()
        ModuleSetting.set('default_perspective', perspective.id)

        self.type = ItemType(name='test')
        self.type.set_default_user()
        self.type.save()

        self.status = ItemStatus(name='test')
        self.status.set_default_user()
        self.status.save()

        self.field = ItemField(name='test', label='test', field_type='text')
        self.field.set_default_user()
        self.field.save()

        self.item = Item(name='test', item_type=self.type, status=self.status)
        self.item.set_default_user()
        self.item.save()

        self.value = ItemValue(field=self.field, item=self.item)
        self.value.save()

        self.servicing = ItemServicing(name='test')
        self.servicing.set_default_user()
        self.servicing.save()
Beispiel #3
0
    def setUp(self):
        self.group, created = Group.objects.get_or_create(name='test')
        self.user, created = DjangoUser.objects.get_or_create(username=self.username)
        self.user.set_password(self.password)
        self.user.save()
        perspective, created = Perspective.objects.get_or_create(name='default')
        perspective.set_default_user()
        perspective.save()
        ModuleSetting.set('default_perspective', perspective.id)

        self.type = ItemType(name='test')
        self.type.set_default_user()
        self.type.save()

        self.status = ItemStatus(name='test')
        self.status.set_default_user()
        self.status.save()

        self.field = ItemField(
            name='test', label='test', field_type='text')
        self.field.set_default_user()
        self.field.save()

        self.item = Item(
            name='test', item_type=self.type, status=self.status)
        self.item.set_default_user()
        self.item.save()

        self.value = ItemValue(field=self.field, item=self.item)
        self.value.save()

        self.servicing = ItemServicing(name='test')
        self.servicing.set_default_user()
        self.servicing.save()
Beispiel #4
0
    def setUp(self):
        self.group, created = Group.objects.get_or_create(name='test')
        duser, created = DjangoUser.objects.get_or_create(
            username=self.username)
        duser.set_password(self.password)
        duser.save()
        self.user, created = User.objects.get_or_create(user=duser)
        self.user.save()
        perspective, created = Perspective.objects.get_or_create(
            name='default')
        perspective.set_default_user()
        perspective.save()
        ModuleSetting.set('default_perspective', perspective.id)

        self.folder = KnowledgeFolder(name='test', treepath='test')
        self.folder.set_default_user()
        self.folder.save()

        self.category = KnowledgeCategory(name='test', treepath='test')
        self.category.set_default_user()
        self.category.save()

        self.item = KnowledgeItem(name='test',
                                  folder=self.folder,
                                  category=self.category,
                                  treepath='test')
        self.item.set_default_user()
        self.item.save()

        # parent folder
        self.parent = KnowledgeFolder(name='test', treepath='test')
        self.parent.set_default_user()
        self.parent.save()

        self.client = Client()
Beispiel #5
0
    def setUp(self):
        self.group = Group.objects.create(name='test')
        self.user = DjangoUser.objects.create(username=self.username)
        self.user.set_password(self.password)
        self.user.save()

        perspective = Perspective(name='default')
        perspective.set_user(self.user.profile)
        perspective.save()

        ModuleSetting.set('default_perspective', perspective.id)

        self.folder = Folder(name='test')
        self.folder.set_user(self.user.profile)
        self.folder.save()

        self.document = Document(title='test_document', folder=self.folder)
        self.document.set_user(self.user.profile)
        self.document.save()

        self.file = File(name='test_file', folder=self.folder)
        self.file.set_user(self.user.profile)
        self.file.save()

        self.link = WebLink(title='test', folder=self.folder, url='test')
        self.link.set_user(self.user.profile)
        self.link.save()
Beispiel #6
0
    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
Beispiel #7
0
    def setUp(self):
        self.group, created = Group.objects.get_or_create(name='test')
        self.user, created = DjangoUser.objects.get_or_create(username=self.username)
        self.user.set_password(self.password)
        self.user.save()

        perspective, created = Perspective.objects.get_or_create(name='default')
        perspective.set_default_user()
        perspective.save()
        ModuleSetting.set('default_perspective', perspective.id)

        self.contact_type = ContactType(name='test')
        self.contact_type.set_default_user()
        self.contact_type.save()

        self.contact = Contact(name='test', contact_type=self.contact_type)
        self.contact.set_default_user()
        self.contact.save()

        self.stream = MessageStream(name='test')
        self.stream.set_default_user()
        self.stream.save()

        self.message = Message(
            title='test', body='test', author=self.contact, stream=self.stream)
        self.message.set_default_user()
        self.message.save()
Beispiel #8
0
    def setUp(self):
        self.group, created = Group.objects.get_or_create(name='test')
        self.user, created = DjangoUser.objects.get_or_create(username=self.username)
        self.user.set_password(self.password)
        self.user.save()
        perspective, created = Perspective.objects.get_or_create(name='default')
        perspective.set_default_user()
        perspective.save()
        ModuleSetting.set('default_perspective', perspective.id)

        self.contact_type = ContactType(name='test')
        self.contact_type.set_default_user()
        self.contact_type.save()

        self.contact = Contact(name='test', contact_type=self.contact_type)
        self.contact.set_default_user()
        self.contact.save()

        self.category = Category(name='test')
        self.category.set_default_user()
        self.category.save()

        self.equity = Equity(
            issue_price=10, sell_price=10, issuer=self.contact, owner=self.contact)
        self.equity.set_default_user()
        self.equity.save()

        self.asset = Asset(name='test', owner=self.contact)
        self.asset.set_default_user()
        self.asset.save()

        self.tax = Tax(name='test', rate=10)
        self.tax.set_default_user()
        self.tax.save()

        self.currency = Currency(code="GBP",
                                 name="Pounds",
                                 symbol="L",
                                 is_default=True)
        self.currency.set_default_user()
        self.currency.save()

        self.account = Account(
            name='test', owner=self.contact, balance_currency=self.currency)
        self.account.set_default_user()
        self.account.save()

        self.liability = Liability(name='test',
                                   source=self.contact,
                                   target=self.contact,
                                   account=self.account,
                                   value=10,
                                   value_currency=self.currency)
        self.liability.set_default_user()
        self.liability.save()

        self.transaction = Transaction(name='test', account=self.account, source=self.contact,
                                       target=self.contact, value=10, value_currency=self.currency)
        self.transaction.set_default_user()
        self.transaction.save()
Beispiel #9
0
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)
Beispiel #10
0
    def setUp(self):
        self.group, created = Group.objects.get_or_create(name='test')
        duser, created = DjangoUser.objects.get_or_create(username=self.username)
        duser.set_password(self.password)
        duser.save()
        self.user, created = User.objects.get_or_create(user=duser)
        self.user.save()
        perspective, created = Perspective.objects.get_or_create(name='default')
        perspective.set_default_user()
        perspective.save()
        ModuleSetting.set('default_perspective', perspective.id)

        self.folder = KnowledgeFolder(name='test', treepath='test')
        self.folder.set_default_user()
        self.folder.save()

        self.category = KnowledgeCategory(name='test', treepath='test')
        self.category.set_default_user()
        self.category.save()

        self.item = KnowledgeItem(name='test', folder=self.folder,
                                  category=self.category, treepath='test')
        self.item.set_default_user()
        self.item.save()

        # parent folder
        self.parent = KnowledgeFolder(name='test', treepath='test')
        self.parent.set_default_user()
        self.parent.save()

        self.client = Client()
Beispiel #11
0
def htdate(context, date, dateformat="DATE_FORMAT"):
    """ Render date in the current locale

    To render date in a custom format use Django format, details:
    http://docs.djangoproject.com/en/dev/ref/templates/builtins/#date

    """

    if not date:
        return ""

    lang = translation.get_language()

    localeformat = dateformat
    formatspath = getattr(settings, "FORMAT_MODULE_PATH", "anaf.formats")
    try:
        modulepath = formatspath + "." + lang + ".formats"
        module = __import__(modulepath, fromlist=[str(modulepath)])
        localeformat = getattr(module, dateformat, dateformat)
    except ImportError:
        pass

    request = context["request"]

    user = None
    if request.user.username:
        try:
            user = request.user.profile
        except Exception:
            pass

    # timezone
    default_timezone = settings.ANAF_SERVER_DEFAULT_TIMEZONE
    try:
        conf = ModuleSetting.get("default_timezone")[0]
        default_timezone = conf.value
    except:
        pass

    try:
        conf = ModuleSetting.get("default_timezone", user=user)[0]
        default_timezone = conf.value
    except Exception:
        default_timezone = settings.ANAF_SERVER_TIMEZONE[default_timezone][0]

    all_timezones = settings.ANAF_SERVER_TIMEZONE
    title = all_timezones[int(default_timezone)][1]
    GMT = title[4:10]  # with sign e.g. +06:00
    sign = GMT[0:1]  # + or -
    hours = int(GMT[1:3])  # e.g. 06
    mins = int(GMT[4:6])

    if sign == "-":
        date = date - timedelta(hours=hours, minutes=mins)
    else:
        date = date + timedelta(hours=hours, minutes=mins)

    result = djangodate(date, localeformat)
    return Markup(result)
Beispiel #12
0
def htdate(context, date, dateformat='DATE_FORMAT'):
    """ Render date in the current locale

    To render date in a custom format use Django format, details:
    http://docs.djangoproject.com/en/dev/ref/templates/builtins/#date

    """

    if not date:
        return ''

    lang = translation.get_language()

    localeformat = dateformat
    formatspath = getattr(settings, 'FORMAT_MODULE_PATH', 'anaf.formats')
    try:
        modulepath = formatspath + "." + lang + ".formats"
        module = __import__(modulepath, fromlist=[str(modulepath)])
        localeformat = getattr(module, dateformat, dateformat)
    except ImportError:
        pass

    request = context['request']

    user = None
    if request.user.username:
        try:
            user = request.user.profile
        except Exception:
            pass

    # timezone
    default_timezone = settings.ANAF_SERVER_DEFAULT_TIMEZONE
    try:
        conf = ModuleSetting.get('default_timezone')[0]
        default_timezone = conf.value
    except:
        pass

    try:
        conf = ModuleSetting.get('default_timezone', user=user)[0]
        default_timezone = conf.value
    except Exception:
        default_timezone = settings.ANAF_SERVER_TIMEZONE[default_timezone][0]

    all_timezones = settings.ANAF_SERVER_TIMEZONE
    title = all_timezones[int(default_timezone)][1]
    GMT = title[4:10]  # with sign e.g. +06:00
    sign = GMT[0:1]  # + or -
    hours = int(GMT[1:3])  # e.g. 06
    mins = int(GMT[4:6])

    if sign == "-":
        date = date - timedelta(hours=hours, minutes=mins)
    else:
        date = date + timedelta(hours=hours, minutes=mins)

    result = djangodate(date, localeformat)
    return Markup(result)
Beispiel #13
0
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
Beispiel #14
0
 def setUp(self):
     self.group, created = Group.objects.get_or_create(name='test')
     self.user, created = DjangoUser.objects.get_or_create(username=self.username)
     self.user.set_password(self.password)
     self.user.save()
     perspective, created = Perspective.objects.get_or_create(name='default')
     perspective.set_default_user()
     perspective.save()
     ModuleSetting.set('default_perspective', perspective.id)
Beispiel #15
0
    def setUp(self):
        self.group, created = Group.objects.get_or_create(name='test')
        self.user, created = DjangoUser.objects.get_or_create(username=self.username)
        self.user.set_password(self.password)
        self.user.save()
        perspective, created = Perspective.objects.get_or_create(name='default')
        perspective.set_default_user()
        perspective.save()

        ModuleSetting.set('default_perspective', perspective.id)

        self.contact_type = ContactType(name='test')
        self.contact_type.set_default_user()
        self.contact_type.save()

        self.contact = Contact(name='test', contact_type=self.contact_type)
        self.contact.related_user = self.user.profile
        self.contact.set_default_user()
        self.contact.save()

        self.project = Project(name='test', manager=self.contact, client=self.contact)
        self.project.set_default_user()
        self.project.save()

        self.status = TaskStatus(name='test')
        self.status.set_default_user()
        self.status.save()

        self.milestone = Milestone(name='test', project=self.project, status=self.status)
        self.milestone.set_default_user()
        self.milestone.save()

        self.task = Task(name='test', project=self.project, status=self.status, caller=self.contact)
        self.task.set_default_user()
        self.task.save()

        self.task_assigned = Task(name='test', project=self.project, status=self.status)
        self.task_assigned.save()
        self.task_assigned.assigned.add(self.user.profile)

        self.time_slot = TaskTimeSlot(task=self.task, details='test', time_from=datetime.now(), user=self.user.profile)
        self.time_slot.set_default_user()
        self.time_slot.save()

        self.parent = Project(name='test')
        self.parent.set_default_user()
        self.parent.save()

        self.parent_task = Task(
            name='test', project=self.project, status=self.status, priority=3)
        self.parent_task.set_default_user()
        self.parent_task.save()

        self.client = Client()

        self.client.login(username=self.username, password=self.password)
Beispiel #16
0
    def save(self):
        "Form processor"
        try:
            ModuleSetting.set_for_module(
                'default_item_status',
                self.cleaned_data['default_item_status'].id,
                'anaf.infrastructure')

        except Exception:
            return False
Beispiel #17
0
    def save(self):
        "Form processor"
        try:
            ModuleSetting.set_for_module('default_task_status',
                                         self.cleaned_data[
                                             'default_task_status'].id,
                                         'anaf.projects')

        except Exception:
            return False
Beispiel #18
0
    def save(self):
        "Form processor"
        try:
            ModuleSetting.set_for_module('default_item_status',
                                         self.cleaned_data[
                                             'default_item_status'].id,
                                         'anaf.infrastructure')

        except Exception:
            return False
Beispiel #19
0
    def save(self):
        "Form processor"
        try:
            ModuleSetting.set_for_module('default_contact_type',
                                         self.cleaned_data[
                                             'default_contact_type'].id,
                                         'anaf.identities')

        except Exception:
            return False
Beispiel #20
0
 def setUp(self):
     self.group, created = Group.objects.get_or_create(name='test')
     self.user, created = DjangoUser.objects.get_or_create(
         username=self.username)
     self.user.set_password(self.password)
     self.user.save()
     perspective, created = Perspective.objects.get_or_create(
         name='default')
     perspective.set_default_user()
     perspective.save()
     ModuleSetting.set('default_perspective', perspective.id)
Beispiel #21
0
    def save(self):
        "Form processor"
        try:
            ModuleSetting.set_for_module('default_changeset_status',
                                         self.cleaned_data[
                                             'default_changeset_status'].id,
                                         'anaf.changes')
            return True

        except Exception:
            return False
Beispiel #22
0
    def save(self):
        "Form processor"
        try:
            ModuleSetting.set_for_module(
                'default_changeset_status',
                self.cleaned_data['default_changeset_status'].id,
                'anaf.changes')
            return True

        except Exception:
            return False
Beispiel #23
0
    def setUp(self):
        self.group, created = Group.objects.get_or_create(name='test')
        self.user, created = DjangoUser.objects.get_or_create(
            username=self.username)
        self.user.set_password(self.password)
        self.user.save()
        perspective, created = Perspective.objects.get_or_create(
            name='default')
        perspective.set_default_user()
        perspective.save()

        ModuleSetting.set('default_perspective', perspective.id)

        self.contact_type = ContactType(name='test')
        self.contact_type.set_default_user()
        self.contact_type.save()

        self.contact = Contact(name='test', contact_type=self.contact_type)
        self.contact.set_default_user()
        self.contact.save()

        self.status = TicketStatus(name='TestStatus')
        self.status.set_default_user()
        self.status.save()

        self.queue = TicketQueue(name='TestQueue',
                                 default_ticket_status=self.status)
        self.queue.set_default_user()
        self.queue.save()

        self.ticket = Ticket(name='TestTicket',
                             status=self.status,
                             queue=self.queue)
        self.ticket.set_default_user()
        self.ticket.save()

        self.agent = ServiceAgent(related_user=self.user.profile,
                                  available_from=datetime.time(9),
                                  available_to=datetime.time(17))
        self.agent.set_default_user()
        self.agent.save()

        self.service = Service(name='test')
        self.service.set_default_user()
        self.service.save()

        self.sla = ServiceLevelAgreement(name='test',
                                         service=self.service,
                                         client=self.contact,
                                         provider=self.contact)
        self.sla.set_default_user()
        self.sla.save()
Beispiel #24
0
    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('anaf.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('anaf.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('anaf.services',
                                                'send_email_to_caller')[0]
            self.fields['send_email_to_caller'].initial = conf.value
        except:
            self.fields[
                'send_email_to_caller'].initial = settings.ANAF_SEND_EMAIL_TO_CALLER

        # notification template
        try:
            conf = ModuleSetting.get_for_module('anaf.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')
Beispiel #25
0
    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(
                'anaf.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(
                'anaf.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(
                'anaf.services', 'send_email_to_caller')[0]
            self.fields['send_email_to_caller'].initial = conf.value
        except:
            self.fields[
                'send_email_to_caller'].initial = settings.ANAF_SEND_EMAIL_TO_CALLER

        # notification template
        try:
            conf = ModuleSetting.get_for_module(
                'anaf.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')
Beispiel #26
0
    def setUp(self):
        self.group, created = Group.objects.get_or_create(name='test')
        self.user, created = DjangoUser.objects.get_or_create(username=self.username)
        self.user.set_password(self.password)
        self.user.save()
        perspective, created = Perspective.objects.get_or_create(name='default')
        perspective.set_default_user()
        perspective.save()

        ModuleSetting.set('default_perspective', perspective.id)

        self.event = Event(name='TestStatus', end=datetime.now())
        self.event.set_default_user()
        self.event.save()
Beispiel #27
0
def htform(context, form):
    "Set time zone"

    request = context['request']

    user = None
    if request.user.username:
        try:
            user = request.user.profile
        except Exception:
            pass

    # timezone
    default_timezone = settings.ANAF_SERVER_DEFAULT_TIMEZONE
    try:
        conf = ModuleSetting.get('default_timezone')[0]
        default_timezone = conf.value
    except:
        pass

    try:
        conf = ModuleSetting.get('default_timezone', user=user)[0]
        default_timezone = conf.value
    except Exception:
        default_timezone = settings.ANAF_SERVER_TIMEZONE[default_timezone][0]

    all_timezones = settings.ANAF_SERVER_TIMEZONE
    title = all_timezones[int(default_timezone)][1]
    GMT = title[4:10]  # with sign e.g. +06:00
    sign = GMT[0:1]  # + or -
    hours = int(GMT[1:3])  # e.g. 06
    mins = int(GMT[4:6])

    if not form.errors:
        for field in form:
            try:
                date = datetime.strptime(
                    str(field.form.initial[field.name]), "%Y-%m-%d %H:%M:%S")
                if date:
                    if sign == "-":
                        field.form.initial[
                            field.name] = date - timedelta(hours=hours, minutes=mins)
                    else:
                        field.form.initial[
                            field.name] = date + timedelta(hours=hours, minutes=mins)
            except:
                pass

    return form
Beispiel #28
0
 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
Beispiel #29
0
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)
Beispiel #30
0
    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(
                'anaf.core', 'default_permissions')[0]
            default_permissions = conf.value
        except:
            default_permissions = settings.ANAF_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]
Beispiel #31
0
    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(
                'anaf.finance', 'my_company')[0]
            self.fields['issuer'].initial = long(conf.value)
        except Exception:
            pass

        self.fields['purchase_date'].widget.attrs.update(
            {'class': 'datepicker'})
Beispiel #32
0
def settings_view(request, response_format='html'):
    "Settings"

    # default changeset status
    try:
        conf = ModuleSetting.get_for_module(
            'anaf.changes', 'default_changeset_status')[0]
        default_changeset_status = ChangeSetStatus.objects.get(
            pk=long(conf.value))

    except Exception:
        default_changeset_status = None

    # check not trashed
    if default_changeset_status and default_changeset_status.trash:
        default_changeset_status = None

    settings_statuses = ChangeSetStatus.objects.filter(trash=False)

    context = _get_default_context(request)
    context.update({'default_changeset_status': default_changeset_status,
                    'settings_statuses': settings_statuses})

    return render_to_response('changes/settings_view', context,
                              context_instance=RequestContext(request), response_format=response_format)
Beispiel #33
0
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)
Beispiel #34
0
 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
Beispiel #35
0
    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('anaf.core',
                                                'default_permissions')[0]
            default_permissions = conf.value
        except:
            default_permissions = settings.ANAF_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]
Beispiel #36
0
    def setUp(self):
        self.group, created = Group.objects.get_or_create(name='test')
        self.user, created = DjangoUser.objects.get_or_create(
            username=self.username)
        self.user.set_password(self.password)
        self.user.save()
        perspective, created = Perspective.objects.get_or_create(
            name='default')
        perspective.set_default_user()
        perspective.save()

        ModuleSetting.set('default_perspective', perspective.id)

        self.event = Event(name='TestStatus', end=datetime.now())
        self.event.set_default_user()
        self.event.save()
Beispiel #37
0
 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
Beispiel #38
0
def settings_view(request, response_format='html'):
    "Settings"

    # default changeset status
    try:
        conf = ModuleSetting.get_for_module('anaf.changes',
                                            'default_changeset_status')[0]
        default_changeset_status = ChangeSetStatus.objects.get(
            pk=long(conf.value))

    except Exception:
        default_changeset_status = None

    # check not trashed
    if default_changeset_status and default_changeset_status.trash:
        default_changeset_status = None

    settings_statuses = ChangeSetStatus.objects.filter(trash=False)

    context = _get_default_context(request)
    context.update({
        'default_changeset_status': default_changeset_status,
        'settings_statuses': settings_statuses
    })

    return render_to_response('changes/settings_view',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Beispiel #39
0
    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('anaf.messaging', 'signature',
                                                user=user, strict=True)[0]
            signature = conf.value
            self.fields['body'].initial = signature
        except:
            pass
Beispiel #40
0
    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(
                'anaf.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")
Beispiel #41
0
    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(
                'anaf.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(
                'anaf.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")
Beispiel #42
0
def htform(context, form):
    "Set time zone"

    request = context["request"]

    user = None
    if request.user.username:
        try:
            user = request.user.profile
        except Exception:
            pass

    # timezone
    default_timezone = settings.ANAF_SERVER_DEFAULT_TIMEZONE
    try:
        conf = ModuleSetting.get("default_timezone")[0]
        default_timezone = conf.value
    except:
        pass

    try:
        conf = ModuleSetting.get("default_timezone", user=user)[0]
        default_timezone = conf.value
    except Exception:
        default_timezone = settings.ANAF_SERVER_TIMEZONE[default_timezone][0]

    all_timezones = settings.ANAF_SERVER_TIMEZONE
    title = all_timezones[int(default_timezone)][1]
    GMT = title[4:10]  # with sign e.g. +06:00
    sign = GMT[0:1]  # + or -
    hours = int(GMT[1:3])  # e.g. 06
    mins = int(GMT[4:6])

    if not form.errors:
        for field in form:
            try:
                date = datetime.strptime(str(field.form.initial[field.name]), "%Y-%m-%d %H:%M:%S")
                if date:
                    if sign == "-":
                        field.form.initial[field.name] = date - timedelta(hours=hours, minutes=mins)
                    else:
                        field.form.initial[field.name] = date + timedelta(hours=hours, minutes=mins)
            except:
                pass

    return form
Beispiel #43
0
    def setUp(self):
        self.group, created = Group.objects.get_or_create(name='test')
        self.user, created = DjangoUser.objects.get_or_create(username=self.username)
        self.user.set_password(self.password)
        self.user.save()
        perspective, created = Perspective.objects.get_or_create(name='default')
        perspective.set_default_user()
        perspective.save()

        ModuleSetting.set('default_perspective', perspective.id)

        self.contact_type = ContactType(name='test')
        self.contact_type.set_default_user()
        self.contact_type.save()

        self.contact = Contact(name='test', contact_type=self.contact_type)
        self.contact.set_default_user()
        self.contact.save()

        self.status = TicketStatus(name='TestStatus')
        self.status.set_default_user()
        self.status.save()

        self.queue = TicketQueue(
            name='TestQueue', default_ticket_status=self.status)
        self.queue.set_default_user()
        self.queue.save()

        self.ticket = Ticket(
            name='TestTicket', status=self.status, queue=self.queue)
        self.ticket.set_default_user()
        self.ticket.save()

        self.agent = ServiceAgent(related_user=self.user.profile, available_from=datetime.time(9),
                                  available_to=datetime.time(17))
        self.agent.set_default_user()
        self.agent.save()

        self.service = Service(name='test')
        self.service.set_default_user()
        self.service.save()

        self.sla = ServiceLevelAgreement(name='test', service=self.service,
                                         client=self.contact, provider=self.contact)
        self.sla.set_default_user()
        self.sla.save()
Beispiel #44
0
    def save(self):
        "Form processor"
        try:
            ModuleSetting.set_for_module('my_company',
                                         self.cleaned_data['my_company'].id,
                                         'anaf.finance')
            ModuleSetting.set_for_module(
                'default_account', self.cleaned_data['default_account'].id,
                'anaf.finance')
            currency = Currency.objects.get(
                pk=self.cleaned_data['default_currency'])
            currency.is_default = True
            currency.save()
            return True

        except Exception:
            return False
Beispiel #45
0
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+_\-\.]+@[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)
Beispiel #46
0
def settings_view(request, response_format='html'):
    "Settings admin view"

    # default content type
    try:
        conf = ModuleSetting.get_for_module('anaf.messaging',
                                            'default_contact_type',
                                            user=request.user.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('anaf.messaging',
                                            'default_imap_folder')[0]
        default_imap_folder = conf.value
    except:
        default_imap_folder = settings.ANAF_MESSAGING_IMAP_DEFAULT_FOLDER_NAME

    # signature
    try:
        conf = ModuleSetting.get_for_module('anaf.messaging',
                                            'signature',
                                            user=request.user.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)
Beispiel #47
0
    def save(self):
        "Form processor"
        try:
            ModuleSetting.set_for_module('my_company',
                                         self.cleaned_data['my_company'].id,
                                         'anaf.finance')
            ModuleSetting.set_for_module('default_account',
                                         self.cleaned_data[
                                             'default_account'].id,
                                         'anaf.finance')
            currency = Currency.objects.get(
                pk=self.cleaned_data['default_currency'])
            currency.is_default = True
            currency.save()
            return True

        except Exception:
            return False
Beispiel #48
0
    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('anaf.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('anaf.finance',
                                                'default_account')[0]
            default_account = Account.objects.get(pk=long(conf.value))
            self.fields['default_account'].initial = default_account.id
        except Exception:
            pass
Beispiel #49
0
    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+_\-\.]+@[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
Beispiel #50
0
 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
Beispiel #51
0
 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)
Beispiel #52
0
    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)