Пример #1
0
    def setUp(self):
        "Initial Setup"

        if not self.prepared:
            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.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()
                    
            self.client = Client()  
            
            self.prepared = True
Пример #2
0
    def setUp(self):
        "Initial Setup"
        if not self.prepared:
            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()

            self.prepared = True
Пример #3
0
 def setUp(self):
     "Initial Setup"
     
     if not self.prepared:
         # Clean up first
         Object.objects.all().delete()
         
         # Create objects
         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.contact_type = ContactType(name='Person')
         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.field = ContactField(name='Test', label='test', field_type='text')
         self.field.set_default_user()
         self.field.save()
                 
         self.client = Client()
         
         self.prepared = True
Пример #4
0
    def setUp(self):
        "Initial Setup"

        if not self.prepared:
            Object.objects.all().delete()

            # Create objects
            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.perspective = Perspective(name='test')
            self.perspective.set_default_user()
            self.perspective.save()

            self.group = Group(name='test')
            self.group.save()

            self.client = Client()

            self.prepared = True
Пример #5
0
 def setUp(self):
     "Initial Setup"
     
     if not self.prepared:
         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.report = Report(name='test')
         self.report.set_default_user()
         self.report.save()
         
         self.chart = Chart(name='test_chart', report=self.report)
         self.chart.set_default_user()
         self.chart.save()
             
         self.client = Client()
         
         self.prepared = True
Пример #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('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
Пример #7
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('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
Пример #8
0
    def setUp(self):
        "Initial Setup"

        if not self.prepared:
            Object.objects.all().delete()

            # Create objects

            try:
                self.group = Group.objects.get(name='test')
            except Group.DoesNotExist:
                Group.objects.all().delete()
                self.group = Group(name='test')
                self.group.save()

            try:
                self.user = DjangoUser.objects.get(username=self.username)
                self.user.set_password(self.password)
                try:
                    self.profile = self.user.get_profile()
                except Exception:
                    User.objects.all().delete()
                    self.user = DjangoUser(username=self.username, password='')
                    self.user.set_password(self.password)
                    self.user.save()
            except DjangoUser.DoesNotExist:
                User.objects.all().delete()
                self.user = DjangoUser(username=self.username, password='')
                self.user.set_password(self.password)
                self.user.save()

            try:
                perspective = Perspective.objects.get(name='default')
            except Perspective.DoesNotExist:
                Perspective.objects.all().delete()
                perspective = Perspective(name='default')
                perspective.set_default_user()
                perspective.save()

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

            self.folder = Folder(name='test')
            self.folder.set_default_user()
            self.folder.save()

            self.document = Document(title='test_document', folder=self.folder)
            self.document.set_default_user()
            self.document.save()

            self.file = File(name='test_file', folder=self.folder)
            self.file.set_default_user()
            self.file.save()

            self.link = WebLink(title='test', folder=self.folder, url='test')
            self.link.set_default_user()
            self.link.save()

            self.client = Client()

            self.prepared = True
Пример #9
0
    def setUp(self):
        "Initial Setup"
        if not self.prepared:
            # Clean up first
            Object.objects.all().delete()

            # Create objects
            try:
                self.group = Group.objects.get(name='test')
            except Group.DoesNotExist:
                Group.objects.all().delete()
                self.group = Group(name='test')
                self.group.save()

            try:
                self.user = DjangoUser.objects.get(username=self.username)
                self.user.set_password(self.password)
                try:
                    self.profile = self.user.get_profile()
                except Exception:
                    User.objects.all().delete()
                    self.user = DjangoUser(username=self.username, password='')
                    self.user.set_password(self.password)
                    self.user.save()
            except DjangoUser.DoesNotExist:
                User.objects.all().delete()
                self.user = DjangoUser(username=self.username, password='')
                self.user.set_password(self.password)
                self.user.save()

            try:
                perspective = Perspective.objects.get(name='default')
            except Perspective.DoesNotExist:
                Perspective.objects.all().delete()
                perspective = Perspective(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()

            self.prepared = True
Пример #10
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', 'maker.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.get_profile()
        except Exception:
            pass
        
    # timezone
    default_timezone = settings.MAKER_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 = getattr(settings, 'MAKER_SERVER_TIMEZONE')[default_timezone][0]
        
    all_timezones = getattr(settings, 'MAKER_SERVER_TIMEZONE', [(1, '(GMT-11:00) International Date Line West')])
    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)
Пример #11
0
 def setUp(self):
     "Initial Setup"
     
     if not self.prepared:
         # Clean up first
         Object.objects.all().delete()
         User.objects.all().delete()
             
         # Create objects
         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.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, 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()
         
         self.client = Client()
     
         self.prepared = True
Пример #12
0
    def save(self):
        "Form processor"
        try:
            ModuleSetting.set_for_module('default_task_status',
                                         self.cleaned_data['default_task_status'].id,
                                         'maker.projects')

        except Exception:
            return False
Пример #13
0
 def save(self):
     "Form processor"
     try:
         ModuleSetting.set_for_module('default_item_status',
                                      self.cleaned_data['default_item_status'].id,
                                      'maker.infrastructure')
         
     except Exception:
         return False
Пример #14
0
 def save(self):
     "Form processor"
     try:
         ModuleSetting.set_for_module('default_contact_type',
                                      self.cleaned_data['default_contact_type'].id,
                                      'maker.identities')
         
     except Exception:
         return False
Пример #15
0
    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")
Пример #16
0
    def save(self):
        "Form processor"
        try:
            ModuleSetting.set_for_module('default_changeset_status',
                                         self.cleaned_data['default_changeset_status'].id,
                                         'maker.changes')
            return True

        except Exception:
            return False
Пример #17
0
    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
Пример #18
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('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
Пример #19
0
    def save(self):
        "Form processor"
        try:
            ModuleSetting.set_for_module('default_perspective',
                                         self.cleaned_data['default_perspective'].id,
                                         'maker.core', user=self.user)
            ModuleSetting.set_for_module('default_timezone',
                                         self.cleaned_data['default_timezone'],
                                         'maker.core', user=self.user)
            ModuleSetting.set_for_module('language',
                                         self.cleaned_data['language'],
                                         'maker.core', user=self.user)
            #notification settings
            email_notifications = self.cleaned_data['email_notifications']
            notification, created = NotificationSetting.objects.get_or_create(owner=self.user)
            if email_notifications in ('d', 'w', 'm'):
                notification.ntype = email_notifications
                if not notification.enabled:
                    notification.enabled = True
                    notification.update_date(date.today())
                notification.save()
                notification.modules.clear()
                for m in Module.objects.filter(pk__in = self.cleaned_data['notifications_for_modules']):
                    notification.modules.add( m )
            else:
                notification.enabled = False
                notification.save()
            ModuleSetting.set_for_module('email_notifications',
                                         email_notifications,
                                         'maker.core', user=self.user)
            return True

        except Exception as exc:
            return False
Пример #20
0
    def setUp(self):
        "Initial Setup"

        if not self.prepared:
            # Clean up first
            Object.objects.all().delete()

            # Create objects
            try:
                self.group = Group.objects.get(name='test')
            except Group.DoesNotExist:
                Group.objects.all().delete()
                self.group = Group(name='test')
                self.group.save()

            try:
                self.user = DjangoUser.objects.get(username=self.username)
                self.user.set_password(self.password)
                try:
                    self.profile = self.user.get_profile()
                except Exception:
                    User.objects.all().delete()
                    self.user = DjangoUser(username=self.username, password='')
                    self.user.set_password(self.password)
                    self.user.save()
            except DjangoUser.DoesNotExist:
                User.objects.all().delete()
                self.user = DjangoUser(username=self.username, password='')
                self.user.set_password(self.password)
                self.user.save()

            try:
                perspective = Perspective.objects.get(name='default')
            except Perspective.DoesNotExist:
                Perspective.objects.all().delete()
                perspective = Perspective(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()

            self.client = Client()

            self.prepared = True
Пример #21
0
 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 = "%"
Пример #22
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('maker.finance', 'my_company')[0]
         self.fields['issuer'].initial = long(conf.value)
     except Exception:
         pass
     
     self.fields['purchase_date'].widget.attrs.update({'class': 'datepicker'})
Пример #23
0
    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']  
Пример #24
0
def profile_check(request):
    "If nuvius_id within GET parameters of the request, store the ID within Django session"
    nuvius_id = request.GET.get('nuvius_id', None)
    if nuvius_id:
        nuvius_key = request.GET.get('profile_key', None)
        if nuvius_key:
            con = Connector(profile_id=nuvius_id, profile_key=nuvius_key)
            profile = con.get_profile()
            try:
                if profile['key_valid']:
                    request.session['nuvius_id'] = nuvius_id
                    request.session['nuvius_profile_key'] = nuvius_key
            except KeyError:
                pass
        else:
            request.session['nuvius_id'] = nuvius_id
    
    response = HttpResponse(json.dumps(profile), mimetype='application/json')
    
    # Hardtree code
    if 'applications' in profile:
        del profile['applications']
    if 'bindings' in profile:
        del profile['bindings']
    user = request.user.get_profile()
    conf = ModuleSetting.set('nuvius_profile', '', user=user)
    conf.dumps(profile).save()
    # End of Hardtree code
    
    return response
Пример #25
0
    def save(self):
        "Form processor"
        try:
            ModuleSetting.set_for_module('my_company',
                                         self.cleaned_data['my_company'].id,
                                         'maker.finance')
            ModuleSetting.set_for_module('default_account',
                                         self.cleaned_data['default_account'].id,
                                         'maker.finance')
            currency = Currency.objects.get(pk=self.cleaned_data['default_currency'])
            currency.is_default = True
            currency.save()
            return True

        except Exception:
            return False
Пример #26
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('maker.messaging', 'signature',
                                             user=user, strict=True)[0]
         signature = conf.value
         self.fields['body'].initial = signature 
     except:
         pass
Пример #27
0
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)
Пример #28
0
def integration_view(request, conf_id, response_format='html'):
    "Integration view resource page"
    
    user = request.user.get_profile()
    
    resconf = get_object_or_404(ModuleSetting, pk=conf_id)
    res = resconf.loads()
    
    conf = ModuleSetting.get('nuvius_profile', user=user)
    try:
        profile = conf[0].loads()
    except IndexError:
        profile = None
    
    resource = None
    if profile:
        connector = Connector(request, profile_id=profile['id'])
        resource = DataBlock(connector.get_app(res.resource_id))
        if request.POST and 'delete' in request.POST:
            resconf.delete()
            return HttpResponseRedirect(reverse('events_integration_index'))
        
    context = {'conf_id': conf_id, 'resource': resource}
    
    return render_to_response('events/integration_view', context,
                              context_instance=RequestContext(request), response_format=response_format)
Пример #29
0
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)
Пример #30
0
 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