Exemple #1
0
def test_databases(request):

    set = request.GET['set']
    if set == 'true':
        f = MediaFile(file_id='testfileid',
                      user_id=1,
                      filename='testfilename',
                      upload_time=datetime.utcnow(),
                      view_count=0)  #time.ctime #datetime.datetime
        f.save()

    retr = MediaFile.objects.all()[0]

    file_id = retr.file_id
    user_id = retr.user_id
    filename = retr.filename
    upload_time = retr.upload_time
    view_count = retr.view_count

    return render_to_response(
        'test-databases.html', {
            'file_id': file_id,
            'user_id': user_id,
            'filename': filename,
            'upload_time': upload_time,
            'view_count': view_count
        })
Exemple #2
0
    def store_file(self, file_path, generated_filename, user_id, status):
        # Save to DB
        (d_time, d_seconds) = get_duration(generated_filename)
        media_file = MediaFile(
            filename=os.path.basename(file_path),
            status=status,
            user_id=user_id,
            size=os.path.getsize(generated_filename),
            generated_filename=os.path.basename(generated_filename),
            duration=d_seconds)
        self.db.session.add(media_file)
        self.db.session.commit()

        return media_file
Exemple #3
0
def media_add_ajax(request):
    """
    This is the end point for the ajax file uploads. It will
    always return "application/json".
    """
    if request.method == 'POST':
        uploaded_files = []

        for key, upload in request.FILES.items():
            media_file = MediaFile()
            media_file.title = request.POST.get('title')
            media_file.slug = slugify(media_file.title)
            media_file.caption = request.POST.get('caption')
            media_file.created_by = request.user
            media_file.media_file = upload

            if upload.content_type in ['image/jpeg', 'image/png', 'image/gif']:
                media_file.thumbnail = upload
                media_file.thumbnail_medium = upload

            media_file.save()

            if media_file.thumbnail == '':
                thumbnail_url = STATIC_URL + 'img/default_thumbnail.png'
            else:
                thumbnail_url = media_file.thumbnail.url

            uploaded_files.append({
                'file_name': media_file.media_file.name,
                'pk': media_file.pk,
                'thumbnail_url': thumbnail_url,
                'title': media_file.title,
            })

        # Remember, this has to be JSON serializable
        ret_json = {
            'files': uploaded_files,
            'success': True,
        }

        response = HttpResponse(json.dumps(ret_json),
                                content_type="application/json")
        response['Content-Disposition'] = 'inline; filename="files.json"'

        return response

    else:
        return HttpResponseRedirect(reverse('thathweb.media.views.media_add'))
Exemple #4
0
def load_all_fixtures(db, app):

    user_datastore = SQLAlchemyUserDatastore(db, User, Role)

    # Load default fixtures
    role = user_datastore.create_role(name=app.config['VOXO_ROLE_USER'],
                                      description='User role')
    admin_role = user_datastore.create_role(name=app.config['VOXO_ROLE_ADMIN'],
                                            description='Admin role')
    server_role = user_datastore.create_role(
        name=app.config['VOXO_ROLE_SERVER'], description='Server role')

    user_vjousse = registerable.register_user(email='*****@*****.**',
                                              password='******')
    user_datastore.add_role_to_user(user_vjousse, role)

    print("{user} with token {token} created.".format(
        user=user_vjousse.email, token=user_vjousse.get_auth_token()))

    user = registerable.register_user(email='*****@*****.**',
                                      password='******')
    user_datastore.add_role_to_user(user, admin_role)
    user_datastore.add_role_to_user(user, role)

    print("{user} with token {token} created.".format(
        user=user.email, token=user.get_auth_token()))

    server = registerable.register_user(email='*****@*****.**',
                                        password='******')
    user_datastore.add_role_to_user(server, server_role)

    print("{user} with token {token} created.".format(
        user=server.email, token=server.get_auth_token()))

    asr_model_french = AsrModel(name="french.studio.fr_FR",
                                description="General purpose french model")

    asr_model_french.users.append(user_vjousse)

    db.session.add(asr_model_french)
    db.session.flush()

    asr_model_english = AsrModel(name="english.studio",
                                 description="General purpose english model")

    asr_model_english.users.append(user_vjousse)

    db.session.add(asr_model_english)
    db.session.flush()

    media_file = MediaFile(filename='fixture_file.wav',
                           status=FileStatus.Success,
                           user_id=user_vjousse.id,
                           size=2500,
                           generated_filename='fixture_file_UUID.wav',
                           duration=70)

    db.session.add(media_file)
    db.session.flush()

    process = Process(
        file_id=media_file.id,
        status=DecodeStatus.Queued,
    )

    db.session.add(process)
    db.session.flush()

    transcription = Transcription(
        auto_filename='transcription.xml',
        ref_filename='transcription.txt',
        user_id=user_vjousse.id,
    )

    db.session.add(transcription)
    db.session.flush()

    process = Process(file_id=media_file.id,
                      status=DecodeStatus.Queued,
                      type=ProcessType.TranscriptionAlignment,
                      transcription_id=transcription.id)

    db.session.add(process)
    db.session.flush()

    db.session.commit()