コード例 #1
0
ファイル: forms.py プロジェクト: ZAM-/trackr
    def process(self):
        # Getting ALL existing types
        all_types = PartType.objects.values('name','number') #LOD
        for item in range(0, self.total_form_count()):
            form = self.forms[item]
            bar_code = form.cleaned_data['bar_code']
            status = form.cleaned_data['status']
            serial_number = None
            ptype = None
            print 1
            for types in all_types:
                if types['number'] in bar_code:
                    ptype = types['name']
                    serial_number = bar_code.replace(types['number'],'')
                    # Empty part entry 
                    partobj = Part()
                    partobj.bar_code = bar_code
                    partobj.status = status
                    # Looking up type based on name, b/c I Needed to use a PartType object
                    partobj.type = PartType.objects.get(name=ptype)
                    partobj.serial_number = serial_number
                    partobj.save()
                    print 2
                    return partobj
                    return True
                else:
                    pass
                    

            else:
                return False
                print 3
コード例 #2
0
ファイル: forms.py プロジェクト: ZAM-/trackr
 def process(self):
     # This method will parse the list of bar_codes and create and save
     # a new part object for each bar_code. 
     for line in self.cleaned_data['file']:
         # Very poor way to do things, but it will work for now :)
         partobj=Part() # Creating model obj
         # Setting model attributes automatically
         partobj.bar_code = line 
         partobj.type = self.cleaned_data['type']
         partobj.status = self.cleaned_data['status']
         partobj.serial_number = line[10:]
         partobj.save()
コード例 #3
0
ファイル: forms.py プロジェクト: ZAM-/trackr
 def post_process(self,valid_bc_list):
     #Func to create and save Part() objects         
     all_types = PartType.objects.values('name','number')
     for item in valid_bc_list:
         partobj = Part()
         for types in all_types:
             if types['number'] in item:
                 ptype=types['name']
                 serial_number = item.replace(types['number'],'') # breaking up bar_code into PN + SN
                 partobj.bar_code = item
                 partobj.status = self.cleaned_data['status']
                 partobj.type = PartType.objects.get(number=types['number'])
                 partobj.serial_number = serial_number
                 partobj.save()
コード例 #4
0
ファイル: utils.py プロジェクト: lpj0017/b-tv
def save_part(data_dict, video,file_path):
    part_list = Part.objects.filter(cid=data_dict['cid'])

    f = open(file_path)
    if part_list.count() == 0:
        part = Part(cid=data_dict['cid'])
        part.name = data_dict['partname']
        if part.name == '':
            part.name = data_dict['title']
        part.desc = data_dict['description']
        part.video = video
        part.mp4.save('%s.mp4' % part.name, File(f))
        part.save()
    else:
        part = part_list[0]
        if not part.mp4:
            part.mp4.save('%s.mp4' % part.name, File(f))
            part.save()
    f.close()
コード例 #5
0
ファイル: views.py プロジェクト: daubers/MakeBook
def new_part(request):
    """
        Ajax method to create a new part
        returns the new parts id on success and false on failure
    """
    returndict = {}
    if request.method == 'POST':
        try:
            partdict = json.loads(request.POST['newpart'])
            newpart = Part()
            newpart.number = partdict['number']
            newpart.name = partdict['name']
            newpart.source = partdict['source']
            newpart.description = partdict['description']
            newpart.cost = float(partdict['cost'])
            newpart.save()
            returndict['id'] = newpart.id
        except Exception, e:
            returndict['error'] = e.message