Ejemplo n.º 1
0
    def merge_objects(self, alias_objects=[]):
        from django.contrib.contenttypes.fields import GenericForeignKey
        from lucterios.framework.signal_and_lock import Signal

        if not isinstance(alias_objects, list):
            alias_objects = [alias_objects]

        primary_class = self.__class__
        for alias_object in alias_objects:
            if not isinstance(alias_object, primary_class):
                raise TypeError('Only models of same class can be merged')

        generic_fields = []
        for model in apps.get_models():
            generic_fields.extend(
                filter(lambda x: isinstance(x, GenericForeignKey),
                       model.__dict__.values()))

        blank_local_fields = set([
            field.attname for field in self._meta.local_fields
            if getattr(self, field.attname) in [None, '']
        ])

        for alias_object in alias_objects:
            self._merge_fields_object(alias_object)
            self._merge_genericfield_object(alias_object, generic_fields)
            self._merge_blankfield_object(alias_object, blank_local_fields)
            alias_object.delete()
        self.save()
        Signal.call_signal("post_merge", self)
Ejemplo n.º 2
0
def post_after_migrate(sender, **kwargs):
    if ('exception' not in kwargs) and ('app_config' in kwargs) and (
            kwargs['app_config'].name == 'lucterios.CORE'):
        from django.conf import settings
        set_locale_lang(settings.LANGUAGE_CODE)
        six.print_('check parameters')
        Signal.call_signal("checkparam")
        six.print_('convert data')
        Signal.call_signal("convertdata")
Ejemplo n.º 3
0
def get_url_patterns():
    res = _init_url_patterns()
    for appname in settings.INSTALLED_APPS:
        appmodule = import_module(appname)
        is_lucterios_ext = False
        for _, modname, ispkg in pkgutil.iter_modules(appmodule.__path__):
            if (modname[:5] == 'views') and not ispkg:
                view = import_module(appname + '.' + modname)
                for obj in inspect.getmembers(view):
                    try:
                        if obj[1].url_text != '':
                            if inspect.isclass(obj[1]):
                                is_lucterios_ext = True
                                as_view_meth = getattr(obj[1], "as_view")
                                res.append(
                                    url(r"^%s$" % obj[1].url_text,
                                        as_view_meth()))
                    except AttributeError:
                        pass
            elif settings.APPLIS_MODULE == appmodule:
                is_lucterios_ext = True
        if not is_lucterios_ext:
            try:
                patterns = getattr(import_module('%s.urls' % appname),
                                   'urlpatterns', None)
                if isinstance(patterns, (list, tuple)):
                    for url_pattern in patterns:
                        module_items = appname.split('.')
                        if module_items[0] == 'lucterios':
                            continue
                        if module_items[0] == 'django':
                            res.append(url_pattern)
                        else:
                            res.append(
                                url(
                                    r"^%s/%s" %
                                    (module_items[-1],
                                     url_pattern.pattern._regex[1:]),
                                    url_pattern.callback, None,
                                    url_pattern.pattern.name))
            except ImportError:
                pass
    print("PluginManager.get_instance")
    for plugin_item in PluginManager.get_instance():
        for view_item in plugin_item.views:
            res.append(url(r"^%s$" % view_item.url_text, view_item.as_view()))
    try:
        from django.contrib.admin.sites import site
        res.append(url(r'^accounts/login/$', site.login))
    except ImportError:
        pass
    res.extend(staticfiles_urlpatterns())
    logging.getLogger('lucterios.core.init').debug("Urls:" + '\n'.join(
        str(res_item) for res_item in res))
    Signal.call_signal("auditlog_register")
    LucteriosAuditlogModelRegistry.main_enabled()
    return res
Ejemplo n.º 4
0
def get_url_patterns():
    url_patterns = UrlPatterns()
    for appname in settings.INSTALLED_APPS:
        if not url_patterns.add_lct_application(appname):
            url_patterns.add_ext_application(appname)
    url_patterns.add_plugins()
    url_patterns.add_extra_url()
    logging.getLogger('lucterios.core.init').debug("Urls:" + '\n'.join(str(res_item) for res_item in url_patterns))
    Signal.call_signal("auditlog_register")
    LucteriosAuditlogModelRegistry.main_enabled()
    return url_patterns
Ejemplo n.º 5
0
 def valid(self):
     self.fiscal_year = FiscalYear.get_current()
     bill_list = Bill.objects.filter(Q(bill_type=self.bill_type) & Q(fiscal_year=self.fiscal_year)).exclude(status=0)
     val = bill_list.aggregate(Max('num'))
     if val['num__max'] is None:
         self.num = 1
     else:
         self.num = val['num__max'] + 1
     self.status = 1
     if self.bill_type != 0:
         self.generate_entry()
     self.save()
     Signal.call_signal("change_bill", 'valid', self, None)
Ejemplo n.º 6
0
 def cancel(self):
     new_asset = None
     if (self.bill_type in (1, 3)):
         new_asset = Bill.objects.create(
             bill_type=2, date=date.today(), third=self.third, status=0, cost_accounting=self.cost_accounting)
         for detail in self.detail_set.all():
             detail.id = None
             detail.bill = new_asset
             detail.save()
         self.status = 2
         self.save()
         Signal.call_signal("change_bill", 'cancel', self, new_asset)
     if new_asset is not None:
         return new_asset.id
     else:
         return None
Ejemplo n.º 7
0
 def show(self, xfer):
     xfer.tab = 0
     old_item = xfer.item
     xfer.item = self.item.contact.get_final_child()
     xfer.filltab_from_model(1, 1, True, ['address', ('postal_code', 'city'), 'country', ('tel1', 'tel2')])
     btn = XferCompButton('show')
     btn.set_location(2, 5, 3, 1)
     modal_name = xfer.item.__class__.get_long_name()
     field_id = xfer.item.__class__.__name__.lower()
     if field_id == 'legalentity':
         field_id = 'legal_entity'
     btn.set_action(xfer.request, ActionsManage.get_action_url(modal_name, 'Show', xfer), close=CLOSE_NO,
                    params={field_id: six.text_type(xfer.item.id)})
     xfer.add_component(btn)
     xfer.item = old_item
     Signal.call_signal("third_addon", self.item, xfer)
Ejemplo n.º 8
0
    def fillresponse(self):
        XferListEditor.fillresponse(self)
        lbl = XferCompLabelForm("result")
        lbl.set_value_center(self.item.year.total_result_text)
        lbl.set_location(0, 10, 2)
        self.add_component(lbl)

        accompt_returned = []
        all_codes = list(self.item.year.chartsaccount_set.all().values_list('code', flat=True))
        all_codes.append('')
        Signal.call_signal("compte_no_found", all_codes, accompt_returned)
        lbl = XferCompLabelForm("CompteNoFound")
        if len(accompt_returned) > 0:
            lbl.set_value("{[u]}{[b]}%s{[/b]}{[/u]}{[br]}%s" % (_("Using codes unknows in this account chart:"), "{[br/]}".join(accompt_returned)))
        lbl.set_location(0, 11, 2)
        self.add_component(lbl)
Ejemplo n.º 9
0
Archivo: views.py Proyecto: povtux/core
def right_askpassword(request):
    if not notfree_mode_connect():
        return False
    if (len(settings.AUTHENTICATION_BACKENDS) != 1) or (settings.AUTHENTICATION_BACKENDS[0] != 'django.contrib.auth.backends.ModelBackend'):
        return False
    if (Signal.call_signal("send_connection", None, None, None) == 0):
        return False
    return not request.user.is_authenticated()
Ejemplo n.º 10
0
 def convert_to_bill(self):
     if (self.status == 1) and (self.bill_type == 0):
         new_bill = Bill.objects.create(
             bill_type=1, date=date.today(), third=self.third, status=0, comment=self.comment)
         cost_accountings = CostAccounting.objects.filter(
             Q(status=0) & Q(is_default=True))
         if len(cost_accountings) >= 1:
             new_bill.cost_accounting = cost_accountings[0]
             new_bill.save()
         for detail in self.detail_set.all():
             detail.id = None
             detail.bill = new_bill
             detail.save()
         self.status = 3
         self.save()
         Signal.call_signal("change_bill", 'convert', self, new_bill)
         return new_bill
     else:
         return None
Ejemplo n.º 11
0
 def generate_password(self):
     import random
     letter_string = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@$#%&*+='
     password = ''.join(random.choice(letter_string)
                        for _ in range(random.randint(8, 12)))
     if Signal.call_signal("send_connection", self.email, self.username, password) > 0:
         self.set_password(password)
         self.save()
         return True
     else:
         return False
Ejemplo n.º 12
0
 def generate_password(self):
     import random
     letter_string = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@$#%&*+='
     password = ''.join(random.choice(letter_string)
                        for _ in range(random.randint(8, 12)))
     if Signal.call_signal("send_connection", self.email, self.username, password) > 0:
         self.set_password(password)
         self.save()
         return True
     else:
         return False
Ejemplo n.º 13
0
 def fillresponse_header(self):
     self.filter = Q()
     if self.getparam('year') is not None:
         year = FiscalYear.get_current(self.getparam('year'))
         self.filter &= Q(year=year)
         row_id = self.get_max_row() + 1
         lbl = XferCompLabelForm('title_year')
         lbl.set_italic()
         lbl.set_value("{[b]}%s{[/b]} : %s" % (_('fiscal year'), year))
         lbl.set_location(1, row_id, 1)
         self.add_component(lbl)
     if self.getparam('cost_accounting') is not None:
         cost = CostAccounting.objects.get(id=self.getparam('cost_accounting', 0))
         self.filter &= Q(cost_accounting=cost)
         row_id = self.get_max_row() + 1
         lbl = XferCompLabelForm('title_cost')
         lbl.set_italic()
         lbl.set_value("{[b]}%s{[/b]} : %s" % (_('cost accounting'), cost))
         lbl.set_location(1, row_id, 1)
         self.add_component(lbl)
     Signal.call_signal('editbudget', self)
Ejemplo n.º 14
0
    def edit(self, xfer):
        if self.item.id is not None:
            xfer.change_to_readonly('username')
            obj_username = xfer.get_components('username')
            xfer.filltab_from_model(obj_username.col - 1, obj_username.row + 1,
                                    True, ['date_joined', 'last_login'])
        xfer.change_to_readonly('is_active')
        obj_email = xfer.get_components('email')
        xfer.tab = obj_email.tab
        new_row = obj_email.row
        ckk = XferCompCheck('password_change')
        ckk.set_location(0, new_row + 1, 1, 1)
        ckk.set_value(True)
        ckk.description = _("To change password?")
        ckk.java_script = """
var pwd_change=current.getValue();
parent.get('password1').setEnabled(pwd_change);
parent.get('password2').setEnabled(pwd_change);
"""
        xfer.add_component(ckk)

        pwd1 = XferCompPassword('password1')
        pwd1.set_location(0, new_row + 2, 1, 1)
        pwd1.empty = 1
        pwd1.description = _("password")
        xfer.add_component(pwd1)
        pwd2 = XferCompPassword('password2')
        pwd2.set_location(0, new_row + 3, 1, 1)
        pwd2.empty = 1
        pwd2.description = _("password (again)")
        xfer.add_component(pwd2)
        if Signal.call_signal("send_connection", None, None, None) > 0:
            ckkg = XferCompCheck('password_generate')
            ckkg.set_location(0, new_row + 4)
            ckkg.description = _("Generate new password?")
            ckkg.set_value(False)
            ckkg.java_script = """
    var pwd_change=current.getValue();
    parent.get('password_change').setEnabled(!pwd_change);
    parent.get('password1').setEnabled(!pwd_change);
    parent.get('password2').setEnabled(!pwd_change);
    """
            xfer.add_component(ckkg)
        if xfer.getparam("IDENT_READ") is not None:
            xfer.change_to_readonly('first_name')
            xfer.change_to_readonly('last_name')
            xfer.change_to_readonly('email')
        return LucteriosEditor.edit(self, xfer)
Ejemplo n.º 15
0
    def edit(self, xfer):
        if self.item.id is not None:
            xfer.change_to_readonly('username')
            obj_username = xfer.get_components('username')
            xfer.filltab_from_model(obj_username.col - 1, obj_username.row + 1, True, ['date_joined', 'last_login'])
        xfer.change_to_readonly('is_active')
        obj_email = xfer.get_components('email')
        xfer.tab = obj_email.tab
        new_row = obj_email.row
        ckk = XferCompCheck('password_change')
        ckk.set_location(0, new_row + 1, 1, 1)
        ckk.set_value(True)
        ckk.description = _("To change password?")
        ckk.java_script = """
var pwd_change=current.getValue();
parent.get('password1').setEnabled(pwd_change);
parent.get('password2').setEnabled(pwd_change);
"""
        xfer.add_component(ckk)

        pwd1 = XferCompPassword('password1')
        pwd1.set_location(0, new_row + 2, 1, 1)
        pwd1.empty = 1
        pwd1.description = _("password")
        xfer.add_component(pwd1)
        pwd2 = XferCompPassword('password2')
        pwd2.set_location(0, new_row + 3, 1, 1)
        pwd2.empty = 1
        pwd2.description = _("password (again)")
        xfer.add_component(pwd2)
        if Signal.call_signal("send_connection", None, None, None) > 0:
            ckkg = XferCompCheck('password_generate')
            ckkg.set_location(0, new_row + 4)
            ckkg.description = _("Generate new password?")
            ckkg.set_value(False)
            ckkg.java_script = """
    var pwd_change=current.getValue();
    parent.get('password_change').setEnabled(!pwd_change);
    parent.get('password1').setEnabled(!pwd_change);
    parent.get('password2').setEnabled(!pwd_change);
    """
            xfer.add_component(ckkg)
        if xfer.getparam("IDENT_READ") is not None:
            xfer.change_to_readonly('first_name')
            xfer.change_to_readonly('last_name')
            xfer.change_to_readonly('email')
        return LucteriosEditor.edit(self, xfer)
Ejemplo n.º 16
0
 def archive(self):
     self.status = 3
     self.save()
     Signal.call_signal("change_bill", 'archive', self, None)
Ejemplo n.º 17
0
def post_after_migrate(sender, **kwargs):
    if ('exception' not in kwargs) and ('app_config' in kwargs) and (kwargs['app_config'].name == 'lucterios.CORE'):
        from django.conf import settings
        translation.activate(settings.LANGUAGE_CODE)
        six.print_('check parameters')
        Signal.call_signal("checkparam")
Ejemplo n.º 18
0
Archivo: views.py Proyecto: povtux/core
 def fillresponse(self, params=()):
     for pname in params:
         pvalue = self.getparam(pname)
         Parameter.change_value(pname, pvalue)
     Params.clear()
     Signal.call_signal("param_change", params)