コード例 #1
0
def admin(t):

    user_admin = UserAdmin()

    user_admin.fields['privileges'].name_form = SelectForm

    user_admin.create_forms(['username', 'password', 'email', 'privileges'])

    user_admin.forms['privileges'].arr_select = {
        0: I18n.lang('admin', 'without_privileges', 'Without privileges'),
        1: I18n.lang('admin', 'selected_privileges', 'Selected privileges'),
        2: I18n.lang('admin', 'administrator', 'Administrator')
    }

    user_admin.fields['password'].protected = False

    url = make_url('admin/ausers', {})

    admin = GenerateAdminClass(user_admin, url, t)

    admin.list.fields_showed = ['username', 'privileges']

    admin.list.search_fields = ['username']

    #admin.list.limit_pages=5

    return admin.show()
コード例 #2
0
ファイル: corefields.py プロジェクト: chorizon/cromosoma
 def __init__(self, name, size=1):
     
     required=False
     
     self.yes=I18n.lang('common', 'yes', 'Yes')
     self.no=I18n.lang('common', 'no', 'No')
     
     super(IntegerField, self).__init__(name, size, required)
コード例 #3
0
ファイル: admin.py プロジェクト: webtsys/paramecio
 def show_formatted(self, value):
     
     value=int(value)
     
     if value==0:
         return I18n.lang('admin', 'without_privileges', 'Without privileges')
     elif value==1:
         return I18n.lang('admin', 'selected_privileges', 'Selected privileges')
     elif value==2:
         return I18n.lang('admin', 'administrator', 'Administrator')
コード例 #4
0
    def show_formatted(self, value):

        value = int(value)

        if value == 0:
            return I18n.lang('admin', 'without_privileges',
                             'Without privileges')
        elif value == 1:
            return I18n.lang('admin', 'selected_privileges',
                             'Selected privileges')
        elif value == 2:
            return I18n.lang('admin', 'administrator', 'Administrator')
コード例 #5
0
ファイル: usermodel.py プロジェクト: chorizon/cromosoma
    def check_all_fields(self, dict_values, external_agent, yes_update=False, errors_set="insert"):
        
        try:
            
            fields, values, update_values=super().check_all_fields(dict_values, external_agent, yes_update, errors_set)
        except: 
            
            return False
        
        # Check if passwords matches
        
        if self.password_field in dict_values:
            
            dict_values['repeat_password']=dict_values.get('repeat_password', '')
            
            if dict_values['repeat_password']!=dict_values[self.password_field]:
                
                if dict_values[self.password_field].strip()!="":
                    
                    self.fields[self.password_field].error=True
                    self.fields[self.password_field].txt_error=I18n.lang('common', 'error_passwords_no_match', 'Error: passwords doesn\'t match')
                
                return False

        # Check if exists user with same email or password
        
        
        if self.username_field in dict_values:
        
            self.conditions=['WHERE username=%s', [dict_values[self.username_field]]]

        
        if self.email_field in dict_values:
        
            if len(self.conditions)>0:
        
                self.conditions[0]+=' OR email=%s'
            else:
                self.conditions[0]='WHERE email=%s'
                self.conditions[1]=[]
        
            self.conditions[1].append([dict_values[self.email_field]])
        
        if self.select_count()>0:
            
            self.fields[self.username_field].error=True
            self.fields[self.username_field].txt_error=I18n.lang('common', 'error_username_or_password_exists', 'Error: username or email exists in database')
            
            return False

        return fields, values, update_values
コード例 #6
0
ファイル: lists.py プロジェクト: webtsys/paramecio
 def __init__(self, model, url, t):
     
     self.t=t
     
     self.model=model
     
     if len(self.model.forms)==0:
     
         self.model.create_forms()
     
     self.fields=model.fields.keys()
     
     self.fields_showed=self.fields
     
     self.url=url
     
     self.limit_pages=20
     
     self.order_defaults=['ASC', 'DESC']
     
     self.order_class=['up', 'down']
     
     self.s=get_session()
     
     #self.s['order']=self.s.get('order', 0)
     
     self.order_by=self.order_defaults[0]
     
     self.change_order={}
     
     self.yes_search=True
     
     self.search_text=''
     
     self.initial_num_pages=20
     
     request.query.get('begin_page', '0')
     
     try: 
     
         self.begin_page=int(request.query.begin_page)
         
     except ValueError:
         self.begin_page=0
     
     if self.begin_page<0:
         self.begin_page=0
     
     self.search_fields=self.fields
     
     #self.yes_options=True
     
     self.arr_extra_fields=[I18n.lang('common', 'options', 'Options')]
     
     self.arr_extra_options=[SimpleList.standard_options]
     
     self.jln='<br />'
コード例 #7
0
ファイル: usermodel.py プロジェクト: chorizon/cromosoma
 def create_forms(self, arr_fields={}):
     
     # Add password_repeat to forms from the model
     
     super().create_forms(arr_fields)
     
     if self.password_field in arr_fields and self.yes_repeat_password:
         
         repeat_password=PasswordForm('repeat_password', '')
 
         repeat_password.required=1
         
         repeat_password.label=I18n.lang('common', 'repeat_password', 'Repeat Password')
         
         self.create_form_after(self.password_field, repeat_password)
コード例 #8
0
ファイル: index.py プロジェクト: webtsys/paramecio
def set_extra_forms_user(user_admin):
    
    user_admin.fields['password'].required=True
    user_admin.fields['email'].required=True

    user_admin.create_forms(['username', 'email', 'password'])
    
    user_admin.forms['repeat_password']=PasswordForm('repeat_password', '')
    
    user_admin.forms['repeat_password'].required=1
    
    user_admin.forms['repeat_password'].label=I18n.lang('common', 'repeat_password', 'Repeat Password')


    """user_admin.create_forms()
コード例 #9
0
ファイル: ausers.py プロジェクト: webtsys/paramecio
def admin(t):
    
    user_admin=UserAdmin()
    
    user_admin.fields['privileges'].name_form=SelectForm
    
    user_admin.create_forms(['username', 'password', 'email', 'privileges'])
    
    user_admin.forms['privileges'].arr_select={0: I18n.lang('admin', 'without_privileges', 'Without privileges'), 1: I18n.lang('admin', 'selected_privileges', 'Selected privileges'), 2: I18n.lang('admin', 'administrator', 'Administrator')}
    
    user_admin.fields['password'].protected=False
    
    url=make_url('admin/ausers', {})
    
    admin=GenerateAdminClass(user_admin, url, t)
    
    admin.list.fields_showed=['username', 'privileges']
    
    admin.list.search_fields=['username']
    
    #admin.list.limit_pages=5
    
    return admin.show()
コード例 #10
0
ファイル: index.py プロジェクト: webtsys/paramecio
def home(module=''):
    
    t.clean_header_cache()
    
    #check if login
    
    user_admin=UserAdmin()
    
    s=get_session()
    
    if 'login' in s:
        
        s['id']=s.get('id', 0)
        
        user_admin.conditions=['WHERE id=%s', [s['id']]]
        
        c=user_admin.select_count()
        
        if c>0:
        
            if s['privileges']==2:
                
                #Load menu
                
                menu=OrderedDict()
                
                for key, mod in config_admin.modules_admin.items():
                    if type(mod[1]).__name__!='dict':
                        menu[key]=mod
                    else:
                        menu[key]=mod[0]
                        
                        for subkey, submod in mod[1].items():
                            menu[subkey]=submod
                            #pass
                        
                if module in menu:
                    
                    #Load module
                    
                    new_module=import_module(menu[module][1])
                    
                    if config.reloader:
                        reload(new_module)
                    
                    return t.load_template('admin/content.html', title=menu[module][0], content_index=new_module.admin(t), menu=menu)
                    
                else:
                    return t.load_template('admin/index.html', title=I18n.lang('admin', 'welcome_to_paramecio', "Welcome to Paramecio Admin!!!"), menu=menu)
                
        else:
            
            logout()
            
    else:
        
        user_admin.conditions=['WHERE privileges=%s', [2]]
        
        c=user_admin.select_count()
        
        if c>0:
            
            post={}
            
            user_admin.yes_repeat_password=False

            user_admin.fields['password'].required=True
            
            user_admin.create_forms(['username', 'password'])
            
            forms=show_form(post, user_admin.forms, t, yes_error=False)
            
            return t.load_template('admin/login.phtml', forms=forms)
            
        else:
        
            post={}
            
            set_extra_forms_user(user_admin)
            
            forms=show_form(post, user_admin.forms, t, yes_error=False)

            return t.load_template('admin/register.phtml', forms=forms)
コード例 #11
0
ファイル: lists.py プロジェクト: webtsys/paramecio
 def standard_options(url, id, arr_row):
     options=[]
     options.append('<a href="'+add_get_parameters(url, op_admin=1, id=id)+'">'+I18n.lang('common', 'edit', 'Edit')+'</a>')
     options.append('<a href="'+add_get_parameters(url, op_admin=3, id=id)+'">'+I18n.lang('common', 'delete', 'Delete')+'</a>')
     return options
コード例 #12
0
    def show(self):
        
        GetPostFiles.obtain_get()
        
        GetPostFiles.get['op_admin']=GetPostFiles.get.get('op_admin', '0')
        
        GetPostFiles.get['id']=GetPostFiles.get.get('id', '0')
        
        if GetPostFiles.get['op_admin']=='1':
            
            post=None
            
            if len(self.model.forms)==0:
                self.model.create_forms(self.arr_fields_edit)
            
            title_edit=I18n.lang('common', 'add_new_item', 'Add new item')
            
            if GetPostFiles.get['id']!='0':
                post=self.model.select_a_row(GetPostFiles.get['id'])
                title_edit=I18n.lang('common', 'edit_new_item', 'Edit item')
            
            if post==None:
                post={}
            
            form=show_form(post, self.model.forms, self.t, False)
                
            return self.t.load_template(self.template_insert, admin=self, title_edit=title_edit, form=form, model=self.model, id=GetPostFiles.get['id'])
        
        elif GetPostFiles.get['op_admin']=='2':
            
            GetPostFiles.obtain_post()
            
            post=GetPostFiles.post
            
            insert_row=self.model.insert
            
            try:
                
                GetPostFiles.get['id']=str(int(GetPostFiles.get['id']))
            
            except:
                
                GetPostFiles.get['id']='0'
            
            title_edit=I18n.lang('common', 'add_new_item', 'Add new item')
                
            
            if GetPostFiles.get['id']!='0':
                insert_row=self.model.update
                title_edit=I18n.lang('common', 'edit_new_item', 'Edit item')
                self.model.conditions=['WHERE `'+self.model.name+'`.`'+self.model.name_field_id+'`=%s', [GetPostFiles.get['id']]]
            
            if insert_row(post):
                set_flash_message(I18n.lang('common', 'task_successful', 'Task successful'))
                redirect(self.url)
            else:

                form=show_form(post, self.model.forms, self.t, True)
                return self.t.load_template(self.template_insert, admin=self, title_edit=title_edit, form=form, model=self.model, id=GetPostFiles.get['id'])

            
            pass
            
        elif GetPostFiles.get['op_admin']=='3':
    
            if GetPostFiles.get['id']!='0':
                self.model.conditions=['WHERE `'+self.model.name+'`.`'+self.model.name_field_id+'`=%s', [GetPostFiles.get['id']]]
                self.model.delete()
                set_flash_message(I18n.lang('common', 'task_successful', 'Task successful'))
                redirect(self.url)
    
        else:
            return self.t.load_template(self.template_admin, admin=self)
コード例 #13
0
ファイル: pages.py プロジェクト: webtsys/paramecio
    def show( begin_page, total_elements, num_elements, link ,initial_num_pages=20, variable='begin_page', label='', func_jscript=''):
        
        pages='';

        if begin_page>total_elements:
            begin_page=0

        # Calculamos el total de todas las páginas

        total_page=ceil(total_elements/num_elements)
        
        # Calculamos en que página nos encontramos

        actual_page=ceil(begin_page/num_elements)

        # Calculamos el total de intervalos

        total_interval=ceil(total_page/initial_num_pages)

        # Calculamos el intervalo en el que estamos

        actual_interval=floor(actual_page/initial_num_pages)

        # Calculamos el elemento de inicio del intervalo

        initial_page=ceil(actual_interval*initial_num_pages*num_elements)

        last_page=ceil(actual_interval*initial_num_pages*num_elements)+ceil(initial_num_pages*num_elements)

        if last_page>total_elements:
            last_page=total_elements

        if initial_page>0:
            initial_link=add_get_parameters(link, **{variable: '0'});
            middle_link=add_get_parameters(link, **{variable: str((initial_page-num_elements)) } );
            pages += "<a class=\""+Pages.css_class+"\" href=\""+initial_link+"\" onclick=\"func_jscript\">1</a> <a class=\""+Pages.css_class+"\" href=\""+middle_link+"\">&lt;&lt;</a> "

        arr_pages={}

        #for(x=initial_page;x<last_page;x+=num_elements)
        for x in range(initial_page, last_page, num_elements):
            
            middle_link=add_get_parameters(link, **{variable: str(x)} )

            num_page=ceil(x/num_elements)+1;
            arr_pages[x]="<a class=\""+Pages.css_class+"\" href=\""+middle_link+"\" onclick=\"func_jscript\">"+str(num_page)+"</a> "
            arr_pages[begin_page]='<span class="selected_page">'+str(num_page)+'</span> ';
            pages += arr_pages[x]

        
        if last_page<total_elements:

            middle_link=add_get_parameters(link, **{variable: str(x+num_elements)} );
            last_link=add_get_parameters(link, **{variable: str( ( ( total_page*num_elements ) - num_elements) ) } )

            pages += "<a class=\""+Pages.css_class+"\" href=\""+middle_link+"\" onclick=\"func_jscript\">&gt;&gt;</a> <a class=\"link_pages\" href=\""+last_link+"\" onclick=\"func_jscript\">"+I18n.lang('common', 'last', 'Last')+"</a>"

        
        return pages
コード例 #14
0
    def show(self):

        GetPostFiles.obtain_get()

        GetPostFiles.get['op_admin'] = GetPostFiles.get.get('op_admin', '0')

        GetPostFiles.get['id'] = GetPostFiles.get.get('id', '0')

        if GetPostFiles.get['op_admin'] == '1':

            post = None

            if len(self.model.forms) == 0:
                self.model.create_forms(self.arr_fields_edit)

            title_edit = I18n.lang('common', 'add_new_item', 'Add new item')

            if GetPostFiles.get['id'] != '0':
                post = self.model.select_a_row(GetPostFiles.get['id'])
                title_edit = I18n.lang('common', 'edit_new_item', 'Edit item')

            if post == None:
                post = {}

            form = show_form(post, self.model.forms, self.t, False)

            return self.t.load_template(self.template_insert,
                                        admin=self,
                                        title_edit=title_edit,
                                        form=form,
                                        model=self.model,
                                        id=GetPostFiles.get['id'])

        elif GetPostFiles.get['op_admin'] == '2':

            GetPostFiles.obtain_post()

            post = GetPostFiles.post

            insert_row = self.model.insert

            try:

                GetPostFiles.get['id'] = str(int(GetPostFiles.get['id']))

            except:

                GetPostFiles.get['id'] = '0'

            title_edit = I18n.lang('common', 'add_new_item', 'Add new item')

            if GetPostFiles.get['id'] != '0':
                insert_row = self.model.update
                title_edit = I18n.lang('common', 'edit_new_item', 'Edit item')
                self.model.conditions = [
                    'WHERE `' + self.model.name +
                    '`.`' + self.model.name_field_id + '`=%s',
                    [GetPostFiles.get['id']]
                ]

            if insert_row(post):
                set_flash_message(
                    I18n.lang('common', 'task_successful', 'Task successful'))
                redirect(self.url)
            else:

                form = show_form(post, self.model.forms, self.t, True)
                return self.t.load_template(self.template_insert,
                                            admin=self,
                                            title_edit=title_edit,
                                            form=form,
                                            model=self.model,
                                            id=GetPostFiles.get['id'])

            pass

        elif GetPostFiles.get['op_admin'] == '3':

            if GetPostFiles.get['id'] != '0':
                self.model.conditions = [
                    'WHERE `' + self.model.name +
                    '`.`' + self.model.name_field_id + '`=%s',
                    [GetPostFiles.get['id']]
                ]
                self.model.delete()
                set_flash_message(
                    I18n.lang('common', 'task_successful', 'Task successful'))
                redirect(self.url)

        else:
            return self.t.load_template(self.template_admin, admin=self)