Beispiel #1
0
    def check(my):
        search_key = my.kwargs.get('search_key')
        my.sobject = SearchKey.get_by_search_key(search_key)

        from pyasm.web import WebContainer
        web = WebContainer.get_web()

        my.old_password = web.get_form_value("old password")
        if isinstance(my.old_password, list):
            my.old_password = my.old_password[0]
        #encrypted = md5.new(my.old_password).hexdigest()
        encrypted = hashlib.md5(my.old_password).hexdigest()

        if encrypted != my.sobject.get_value('password'):
            raise UserException('Old password is incorrect.')
        my.password = web.get_form_value("password")
        if isinstance(my.password, list):
            my.password = my.password[0]

        if my.sobject == None:
            return UserException("Current user cannot be determined.")

        my.re_enter = web.get_form_value("password re-enter")
        if isinstance(my.re_enter, list):
            my.re_enter = my.re_enter[0]
        if my.re_enter != "" and my.re_enter != my.password:
            raise UserException(
                "Passwords must match. Please fill in the re-enter.")

        return True
    def postprocess(my):

        sobject = my.sobject

        subcontext = my.get_value()
        context = sobject.get_value("context")

        # if it is a simple context and no subcontext provided, return
        if not subcontext and context.find('/') == -1:
            return

        # replace the new subcontext

        # if existing context is empty, raise UserException
        # avoid value like '/subcontext'

        if not context:
            raise UserException(
                'A context should be filled in first before entering a subcontext.'
            )

        if context.find("/") != -1:
            context, old_subcontext = context.split("/", 1)

        if subcontext.strip():
            context = "%s/%s" % (context, subcontext)
        elif subcontext.strip() == '':
            # the case of removing the subcontext
            context = context

        my.sobject.set_value("context", context)
        my.sobject.commit()
Beispiel #3
0
    def get_new_code(my, related_asset):

        related_code = related_asset.get_value("code")
        related_type = my.get_value("type")
        if not related_type:
            raise UserException(
                "Suffix (define the list by clicking on the edit icon) cannot be empty"
            )
        # find all of the other related assets that match
        search = Search("prod/asset")
        search.add_where("code like '%s_%s%%'" % (related_code, related_type))
        search.add_order_by("code desc")
        last_asset = search.get_sobject()
        if last_asset:
            last_code = last_asset.get_code()
            # get the related index
            if my.search_type == 'flash/asset':
                from pyasm.flash import FlashCodeNaming
                naming = FlashCodeNaming(last_asset, last_code)
            elif my.search_type == 'prod/asset':
                from pyasm.prod.biz import ProdAssetCodeNaming
                naming = ProdAssetCodeNaming(last_asset, last_code)
            related_index = naming.get_related_index()
        else:
            related_index = 0

        # build up the code
        new_code = '%s_%s%02d' % \
            (related_code, related_type, related_index+1)
        return new_code
Beispiel #4
0
 def check_unique(my):
     search = Search('config/widget_config')
     search.add_filter("view", my.view)
     search.add_filter("search_type", my.search_type)
     search.add_user_filter()
     config_sobj = search.get_sobject()
     if config_sobj and my.unique:
         view = my.view.replace('link_search:', '')
         raise UserException('This view [%s] already exists' % view)
     return True
Beispiel #5
0
    def check(self):
        self.web = WebContainer.get_web()
        self.items = self.web.get_form_value('%s|%s' %(self.name, CreateSelectWdg.SELECT_ITEMS))
        self.type = self.web.get_form_value(CreateSelectWdg.TYPE)

        
        if self.type == 'map' and ':' not in self.items:
            raise UserException('The values in the drop-down does not appear to be a map.\
                    Please choose "sequence" for Type and retry.') 
        return True
Beispiel #6
0
    def check(self):
        web = WebContainer.get_web()
        if not web.get_form_value(self.COPY_BUTTON):
            return False

        self.category = web.get_form_value("clipboard_category")
        if not self.category:
            raise UserException("You need to select a watch list")
            return False

        return True
Beispiel #7
0
    def check(my):
        # make this a callback for now
        my.init() 
       
        # check for required columns
        sobj = SObjectFactory.create(my.search_type)
        required_columns = sobj.get_required_columns()
        for required in required_columns:
            if required in my.columns:
                continue
            else:
                raise UserException('Missing required column [%s] in the input CSV' % required)

        return True
Beispiel #8
0
    def execute(self):
        assert self.sobject != None

        if self.password == "":
            if self.sobject.is_insert():
                raise UserException("Empty password.  Go back and re-enter")
            else:
                return
        
        # encrypt the password
        #encrypted = md5.new(self.password).hexdigest()
        encrypted = hashlib.md5.new(self.password).hexdigest()
        self.sobject.set_value("password", encrypted)

        self.sobject.commit()

        self.description = "Password changed for [%s]." %self.sobject.get_value('login')
Beispiel #9
0
    def check(my):
        # make this a callback for now
        from pyasm.web import WebContainer
        web = WebContainer.get_web()
        
        my.search_type = web.get_form_value("search_type_filter")
        my.file_path = web.get_form_value("file_path")
        my.web_url = web.get_form_value("web_url")
        my.test_run = web.get_form_value("test_run")=='true'

        my.triggers_mode = web.get_form_value("triggers_mode")
        if  my.triggers_mode in ['', 'True']:
            my.triggers_mode = True
        elif my.triggers_mode == 'False':
            my.triggers_mode = False 

        if my.web_url:
            import urllib2
            response = urllib2.urlopen(url)
            csv = response.read()
            my.file_path = "/tmp/test.csv"
            f = open(my.file_path, 'w')
            f.write(csv)
            f.close()



        # either unknown or utf-8
        my.encoder = web.get_form_value("encoder")
        my.id_col = web.get_form_value("id_col")
        if not my.id_col:
            my.id_col = 'id'
        num_columns = web.get_form_value("num_columns")
        if num_columns:
            num_columns = int(num_columns)
        else:
            num_columns = 0

        # indices of the enabled columns
        my.enabled_idx = []
        my.columns = []
        my.new_columns = []
        my.new_column_types = []


        for i in range(0, num_columns):
            enabled =  web.get_form_value("column_enabled_%s" % i)
            if enabled  in ['on','true']:
                my.enabled_idx.append(i)

            column =  web.get_form_value("column_%s" % i)
            my.columns.append(column)

            new_column = web.get_form_value("new_column_%s" % i)
            if isinstance(new_column, unicode):
                new_column = my.strip_punctuation(new_column)
            new_column_type = web.get_form_value("new_column_type_%s" % i)
            my.new_columns.append(new_column)
            my.new_column_types.append(new_column_type)

        # check for required columns
        sobj = SObjectFactory.create(my.search_type)
        required_columns = sobj.get_required_columns()
        for required in required_columns:
            if required in my.columns:
                continue
            else:
                raise UserException('Missing required column [%s] in the input CSV' % required)

        my.has_title = web.get_form_value("has_title") == 'on'
        my.lowercase_title = web.get_form_value("lowercase_title") == 'on'
        return True
Beispiel #10
0
    def check(self):
        # make this a callback for now
        from pyasm.web import WebContainer
        web = WebContainer.get_web()
        
        self.search_type = web.get_form_value("search_type_filter")
        self.file_path = web.get_form_value("file_path")
        self.web_url = web.get_form_value("web_url")
        self.test_run = web.get_form_value("test_run")=='true'
        
        self.start_index = web.get_form_value("start_index")
        if self.start_index:
            try:
                self.start_index = int(self.start_index)
            except:
                self.start_index = None

        self.triggers_mode = web.get_form_value("triggers_mode")
        if  self.triggers_mode in ['', 'True']:
            self.triggers_mode = True
        elif self.triggers_mode == 'False':
            self.triggers_mode = False 

        if self.web_url:
            import urllib2
            response = urllib2.urlopen(url)
            csv = response.read()
            self.file_path = "/tmp/test.csv"
            f = open(self.file_path, 'w')
            f.write(csv)
            f.close()



        # either unknown or utf-8
        self.encoder = web.get_form_value("encoder")
        self.id_col = web.get_form_value("id_col")
        if not self.id_col:
            self.id_col = 'id'
        num_columns = web.get_form_value("num_columns")
        if num_columns:
            num_columns = int(num_columns)
        else:
            num_columns = 0

        # indices of the enabled columns
        self.enabled_idx = []
        self.columns = []
        self.new_columns = []
        self.new_column_types = []
        self.note_processes = []


        for i in range(0, num_columns):
            enabled =  web.get_form_value("column_enabled_%s" % i)
            if enabled  in ['on','true']:
                self.enabled_idx.append(i)

            # Default column name or '' for new columns
            column =  web.get_form_value("column_%s" % i)
            self.columns.append(column)
 
            # New column name if column==''
            new_column = web.get_form_value("new_column_%s" % i)
            if isinstance(new_column, unicode):
                new_column = self.strip_punctuation(new_column)
            self.new_columns.append(new_column)
            
            # New column type if column==''
            new_column_type = web.get_form_value("column_type_%s" % i)
            self.new_column_types.append(new_column_type)

            # New note process if column==('note')
            new_note_process = web.get_form_value("note_process_%s" % i)
            self.note_processes.append(new_note_process)

        # check for required columns
        sobj = SObjectFactory.create(self.search_type)
        required_columns = sobj.get_required_columns()
        for required in required_columns:
            if required in self.columns:
                continue
            else:
                raise UserException('Missing required column [%s] in the input CSV' % required)

        self.has_title = web.get_form_value("has_title") == 'on'
        self.lowercase_title = web.get_form_value("lowercase_title") == 'on'
        return True