Ejemplo n.º 1
0
def file_upload_path(instance, filename):
    object_crm_id = instance.object.crm_id
    filename = FileProcessing(filename)
    filename = filename.newFileNameTranslitSlugify()
    # filename = filename.newFileNameFromField(instance.title)
    return 'objects/{object_crm_id}/documents/{filename}'.format(
        object_crm_id=object_crm_id, filename=filename)
Ejemplo n.º 2
0
def actions_partner_logo_upload_path(instance, filename):
    filename = FileProcessing(filename)
    if instance.name:
        filename = filename.newFileNameFromField(instance.name, 'logo', None)
        return 'actions-partners/{filename}'.format(filename=filename)
    else:
        # TODO: Show message
        pass
Ejemplo n.º 3
0
def image_upload_path(instance, filename):
    object_crm_id = instance.gallery.object.crm_id
    gallery_name = instance.gallery.id

    filename = FileProcessing(filename)
    # filename = filename.newFileNameTranslitSlugify()
    filename = filename.newFileNameGenerated()
    return 'objects/{object_crm_id}/galleries/{gallery_name}/{filename}'.format(
        object_crm_id=object_crm_id,
        gallery_name=gallery_name,
        filename=filename)
Ejemplo n.º 4
0
def file_upload_path(instance, filename):
    tender_id = instance.tender.id
    filename = FileProcessing(filename)
    filename = filename.newFileNameTranslitSlugify()
    return 'company/tenders/{tender_id}/{filename}'.format(tender_id=tender_id,
                                                           filename=filename)
Ejemplo n.º 5
0
def image_upload_path(instance, filename):
    object_crm_id = instance.object.crm_id
    filename = FileProcessing(filename)
    filename = filename.newFileNameGenerated()
    return f'objects/{object_crm_id}/info-tabs/{filename}'
Ejemplo n.º 6
0
    def get(self, request, *args, **kwargs):
        context = super().get_context_data(**kwargs)
        context['page_title'] = 'Тендеры'
        context['tenders_categories'] = Tender.CATEGORIES
        context['tender_files'] = TenderFile.objects.all()
        context['tenders'] = Tender.objects.all().order_by(
            '-active', 'date_end')

        # Query ?tender_category= processing
        if request.GET.get('tender_category'):
            context['tenders'] = Tender.objects.filter(
                category=request.GET.get('tender_category')).order_by(
                    '-active', 'date_end')
        if request.GET.get('tender_category') == 'all':
            context['tenders'] = Tender.objects.all().order_by(
                '-active', 'date_end')

        # Download all files related to tender
        get_request_tender_id = request.GET.get('download-all-tender-files')
        if get_request_tender_id:
            file_paths = list()
            for root, directories, files in os.walk(
                    './media/company/tenders/{}'.format(
                        get_request_tender_id)):
                for filename in files:
                    filepath = os.path.join(root, filename)
                    file_paths.append(filepath)

            response = HttpResponse(content_type='application/zip')
            # response = HttpResponse(content_type='application/octet-stream')
            # response = HttpResponse(content_type='application/x-zip-compressed')

            zip_file = zipfile.ZipFile(response, 'w')

            with zipfile.ZipFile(response, 'w') as zip:
                # writing each file one by one
                for file in file_paths:
                    # basename to avoid directory structure
                    zip.write(file, os.path.basename(file))

                # Get tender title
                tender_title = Tender.objects.filter(
                    id=get_request_tender_id).values_list('title', site=True)
                filename = FileProcessing(tender_title[0])
                filename = filename.translitFileName().title()
                # Formatting filename
                new_filename = '[monolit.site] tender_{id} {filename}.zip'.format(
                    filename=filename, id=get_request_tender_id)

                response[
                    'Content-Disposition'] = 'attachment; filename="{filename}"'.format(
                        filename=new_filename)
                return response
        # END Download all files related to tender

        # Object Documents Pagination
        paginator = Paginator(context['tenders'], 5)
        page_docs = self.request.GET.get('page')
        try:
            context['tenders'] = paginator.page(page_docs)
        except PageNotAnInteger:
            context['tenders'] = paginator.page(1)
        except EmptyPage:
            context['tenders'] = paginator.page(paginator.num_pages)
        # END Object Documents Pagination

        return render(request, self.template_name, context)
Ejemplo n.º 7
0
def slider_image_upload(instance, filename):
    filename = FileProcessing(filename)
    filename = filename.newFileNameGenerated()
    return f'objects-commercial/{instance.crm_id}/slider/{filename}'
Ejemplo n.º 8
0
def image_upload_path(instance, filename):
    filename = FileProcessing(filename)
    filename = filename.newFileNameGenerated()
    return f'objects-commercial/{instance.crm_id}/images/{filename}'
Ejemplo n.º 9
0
def genplan_upload_path(instance, filename):
    filename = FileProcessing(filename)
    filename = filename.newFileNameGenplan()
    return f'objects-commercial/{instance.crm_id}/{filename}'
Ejemplo n.º 10
0
def image_upload_path(instance, filename):
    filename = FileProcessing(filename)
    filename = filename.newFileNameGenerated()
    return 'company/job/{filename}'.format(filename=filename)
Ejemplo n.º 11
0
def genplan_upload_path(instance, filename):
    object_crm_id = instance.crm_id
    filename = FileProcessing(filename)
    filename = filename.newFileNameGenplan()
    return f'objects/{object_crm_id}/{filename}'
Ejemplo n.º 12
0
def actions_image_upload_path(instance, filename):
    date = instance.date_start
    filename = FileProcessing(filename)
    filename = filename.newFileNameGenerated()
    return 'actions/{date}/{filename}'.format(date=date, filename=filename)
Ejemplo n.º 13
0
def image_upload_path(instance, filename):
    date = instance.news.date
    filename = FileProcessing(filename)
    filename = filename.newFileNameGenerated()
    return 'news/{date}/{filename}'.format(date=date, filename=filename)
Ejemplo n.º 14
0
def get_file_ext(value):
    file = FileProcessing(value)
    return file.getFileExt()
Ejemplo n.º 15
0
def logo_upload_path(instance, filename):
    filename = FileProcessing(filename)
    filename = filename.newFileNameFromField(instance.name, None, 'logo')
    return 'mortgage/banks/{filename}'.format(filename=filename)
Ejemplo n.º 16
0
def file_upload_path(instance, filename):
    filename = FileProcessing(filename)
    filename = filename.newFileNameTranslitSlugify()
    return f'objects/{instance.object.crm_id}/files/{filename}'