def create_point(self):
     point = Point(0, 0)
     return MmtPoint(
         name='test point',
         geom=point,
         popup_image=self.test_img,
         banner_image=self.test_img,
         popup_audio_file=File(file=self.test_audio_file).save())
 def create_line(self):
     line_1 = LineString((0, 0), (1, 1))
     line_2 = LineString((1, 1), (2, 2))
     multiline = MultiLineString(line_1, line_2)
     return MmtLine(name='test line',
                    geom=multiline,
                    popup_image=self.test_img,
                    banner_image=self.test_img,
                    popup_audio_file=File(file=self.test_audio_file).save())
 def create_polygon(self):
     poly_1 = Polygon(((0, 0), (0, 1), (1, 1), (0, 0)))
     poly_2 = Polygon(((1, 1), (1, 2), (2, 2), (1, 1)))
     multipoly = MultiPolygon(poly_1, poly_2)
     return MmtPolygon(
         name='test polygon',
         geom=multipoly,
         popup_image=self.test_img,
         banner_image=self.test_img,
         popup_audio_file=File(file=self.test_audio_file).save())
Ejemplo n.º 4
0
    def save_report(self):
        """ method for saving report to server, to DB and sending to admins email"""
        filename, file_extension = os.path.splitext(self.filename)
        print('filename: %s, new_filename: %s, file_ext: %s' %
              (self.filename, filename, file_extension))
        report_filename = '%s_%s_%s_%s_%s%s.txt' % (
            filename, self.date['year'], self.date['month'], self.date['day'],
            self.date['hour'], self.date['minute'])
        print(report_filename)
        report_file = os.path.join(DIR['CSV'], DIR['PRICE'], DIR['LOG'],
                                   self.date['year'], self.date['month'],
                                   self.date['day'], report_filename)
        report_file_path = default_storage.save(report_file,
                                                ContentFile(self.report_text))

        folder, created = Folder.objects.get_or_create(name='NewsAuto')
        subfolder_year, created = Folder.objects.get_or_create(
            name=self.date['year'], parent=folder)
        subfolder_month, created = Folder.objects.get_or_create(
            name=self.date['month'], parent=subfolder_year)
        report_file = File(file=report_file_path)
        report_file.name = report_filename
        report_file.folder = subfolder_month
        report_file.save()
        self.send_email(report_filename)
Ejemplo n.º 5
0
    def save_report(self):
        report_filename = 'protokol_%s_%s_%s_%s_%s.txt' % (
            self.year, self.month, self.day, self.hour, self.minute)
        report_path = os.path.join(DIR['CSV'], DIR['KLIENTS'], DIR['LOG'],
                                   self.year, self.month, report_filename)

        good = len(self.report['good'])
        bad = len(self.report['bad'])
        self.report_str = 'Всего записей - %s, загружено - %s, не загружено - %s\n\n' % (
            good + bad, good, bad)
        for line in self.report['good']:
            self.report_str += line
        for line in self.report['bad']:
            self.report_str += line
        report_bytes = self.report_str.encode('utf-8')
        report_path = default_storage.save(report_path,
                                           ContentFile(report_bytes))

        folder, created = Folder.objects.get_or_create(name='Klients')
        subfolder_year, created = Folder.objects.get_or_create(
            name=self.date.strftime('%Y'), parent=folder)
        subfolder_month, created = Folder.objects.get_or_create(
            name=self.date.strftime('%m'), parent=subfolder_year)

        report_file = File(file=report_path)
        report_file.name = report_filename
        report_file.folder = subfolder_month

        report_file.save()
Ejemplo n.º 6
0
    def save_report(self):
        self.report_str = 'Протокол приема файла Priz.csv от %s.%s.%s %s:%s\n' % (
            self.day, self.month, self.year, self.hour, self.minute)
        self.report_str += 'Всего обработано - %s, из них принято - %s, с ошибкой - %s\n\n' % (
            self.good + self.bad, self.good, self.bad)
        for line in self.report['good']:
            self.report_str += line
        for line in self.report['bad']:
            self.report_str += line

        self.report_filename = '%s_%s_%s_%s_%s_priz.txt' % (
            self.year, self.month, self.day, self.hour, self.minute)
        report_path = os.path.join(DIR['CSV'], DIR['BONUS'], DIR['LOG'],
                                   self.year, self.month, self.report_filename)
        report_path = default_storage.save(
            report_path, ContentFile(self.report_str.encode('utf-8')))

        folder, created = Folder.objects.get_or_create(name='Priz')
        subfolder_year, created = Folder.objects.get_or_create(
            name=self.date.strftime('%Y'), parent=folder)
        subfolder_month, created = Folder.objects.get_or_create(
            name=self.date.strftime('%m'), parent=subfolder_year)

        report_file = File(file=report_path)
        report_file.name = self.report_filename
        report_file.folder = subfolder_month

        report_file.save()
    def create_audio_file(self):
        point = self.create_test_point()
        point.save()

        test_audio_file = SimpleUploadedFile(
            name=
            'Songs_of_innocence_and_experience_the_ecchoing_green_blake.mp3',
            content=open(
                'mmt_map/Songs_of_innocence_and_experience_the_ecchoing_green_blake.mp3',
                'rb').read(),
            content_type='audio/mpeg')

        return AudioFile.objects.create(title='test audio file',
                                        file=File(file=test_audio_file).save(),
                                        point=point)
Ejemplo n.º 8
0
def add_attachment_file(request, file_data, task):
    if file_data.size > defaults("TODO_MAXIMUM_ATTACHMENT_SIZE"):
        raise Exception(_("File exceeds maximum attachment size."))

    name, extension = os.path.splitext(file_data.name)

    if extension not in defaults("TODO_LIMIT_FILE_ATTACHMENTS"):
        raise Exception(_("This site does not allow upload of '{}' files.").format(extension))

    user = request.user  # !!

    if 'django_sso_app' in settings.INSTALLED_APPS:
        user_id = user.sso_id
    else:
        user_id = user.username

    created_attachment = Attachment.objects.create(
        task=task, added_by=user, created_at=timezone.now(), file=file_data
    )

    created_attachment_task = created_attachment.task
    created_attachment_task_list = created_attachment_task.task_list

    # creating filer folders
    users_folder, _created = FilerFolder.objects.get_or_create(name='users')
    user_folder, _created = FilerFolder.objects.get_or_create(name=user_id,
                                                              parent=users_folder,
                                                              owner=user)
    user_tasks_folder, _created = FilerFolder.objects.get_or_create(name='tasks',
                                                                    parent=user_folder)
    user_tasklist_folder, _created = FilerFolder.objects.get_or_create(name=created_attachment_task_list.slug,
                                                                       parent=user_tasks_folder)
    user_tasklist_task_folder, _created = FilerFolder.objects.get_or_create(name=str(created_attachment_task.id),
                                                                            parent=user_tasklist_folder)

    # creating filer file
    filer_file = FilerFile()
    filer_file.file = created_attachment.file
    filer_file.owner = user
    filer_file.original_filename = os.path.basename(created_attachment.file.name)
    filer_file.folder = user_tasklist_task_folder

    filer_file.save()

    # update attachment
    created_attachment.filer_file = filer_file
    created_attachment.save()