comparison apps/bundle/tasks.py @ 210:95edf106bdef

Create BundleVersion when uploading text bundles Forgot to add that earlier
author dellsystem <ilostwaldo@gmail.com>
date Tue, 19 Feb 2013 01:53:59 -0500
parents 4033ebe1867f
children
comparison
equal deleted inserted replaced
209:4033ebe1867f 210:95edf106bdef
72 mime_type = magic.from_file(file, mime=True) 72 mime_type = magic.from_file(file, mime=True)
73 extension = mimetypes.guess_extension(mime_type) 73 extension = mimetypes.guess_extension(mime_type)
74 74
75 if extension in archive_extensions: 75 if extension in archive_extensions:
76 new_path = file + extension 76 new_path = file + extension
77 # Save the new file name (needed for the BundleVersion)
78
79 new_file_name = os.path.basename(new_path)
77 # Treat it as an archive. Rename it to that, then extract 80 # Treat it as an archive. Rename it to that, then extract
78 os.rename(file, new_path) 81 os.rename(file, new_path)
79
80 # Create the new BundleVersion
81 new_file_name = os.path.basename(new_path)
82 BundleVersion.objects.create(bundle=bundle, file_name=new_file_name,
83 version=bundle.latest_version)
84 82
85 try: 83 try:
86 # Extract it to a directory, same path as the filename 84 # Extract it to a directory, same path as the filename
87 archive.extract(new_path, to_path=file) 85 archive.extract(new_path, to_path=file)
88 86
95 bundle_file = BundleFile(bundle=bundle, name=bundle.file_name, 93 bundle_file = BundleFile(bundle=bundle, name=bundle.file_name,
96 full_path=bundle.file_name, file_size=os.path.getsize(file), 94 full_path=bundle.file_name, file_size=os.path.getsize(file),
97 version=bundle.latest_version) 95 version=bundle.latest_version)
98 bundle_file.save_file_contents(open(file, 'rt'), 96 bundle_file.save_file_contents(open(file, 'rt'),
99 original_filename=bundle.file_name) 97 original_filename=bundle.file_name)
98 new_file_name = os.path.basename(file)
99
100 # Create the new BundleVersion
101 BundleVersion.objects.create(bundle=bundle, file_name=new_file_name,
102 version=bundle.latest_version)
100 103
101 bundle.done_uploading = True 104 bundle.done_uploading = True
102 bundle.save() 105 bundle.save()