Django admin after processing the downloaded file

I have a standard Django admin page that is used to upload multiple files. I want to do the following:

  • Download some files directly
  • One file must be encrypted using AES before saving (encryption can be done using python or via http on the encryption server.)
  • The mail file must be unpacked, processed and repackaged.

I only have a basic admin page. Can someone point me in the right direction where to start? Please tell me which file I need to change since I am not familiar with django yet.

Just a quick guide will be appreciated. Thank.

+5
source share
2 answers

I have not tested this code, but I can just guide you where to start. I would suggest you write the unzip code in the model save function. This is the easiest way, but not the best. A Django admin can handle multiple forms as a django admin setting.

I hope your models are somewhat similar to these

from django.db import models
from django.core.files.storage import FileSystemStorage

fs = FileSystemStorage(location="/var/www/yoursite/private/")

class SetOfFiles(models.Model):
    name = models.CharField('set name'), max_length=225, null=False, blank=False)

class File(models.Model):
    set = models.ForeignKey(SetOfFiles, verbose_name=_('set'))
    file = models.FileField(storage=fs)

    def save(self, *args, **kwargs):
        if not self.id:
            ... unzip your file ...
            ... encrypt your file if necessary ...
        super(File, self).save(*args, **kwargs)

Create admin.py in the appropriate application, setting up an administrator to handle multiple inserts:

from django.contrib import admin
class FileInline(admin.TabularInline):
    model = File
class SetOfFilesAdmin(admin.ModelAdmin):
    list_display = ('name',)
    inlines = [FileInline]
admin.site.register(SetOfFiles, SetOfFilesAdmin)

ZIP , FileBrowser, - FileBrowser. zipfile python module. PyCrypto AES.

+5

:

  • crontab ""
  • ()

1 / . # 2 , H ^ H ^ Hgood Python.

0

All Articles