Exemplo n.º 1
0
    def submit(self, **kwargs):
        """
        """
        kwargs.setdefault('name')

        # Save the media_obj!
        media_obj = save_media_obj(
            kwargs['name'], kwargs['email'],
            kwargs['title'], kwargs['description'],
            None, kwargs['file'], kwargs['url'],
        )
        email.send_media_notification(media_obj)

        # Redirect to success page!
        redirect(action='success')
Exemplo n.º 2
0
 def test_add_vimeo_video(self):
     pylons.app_globals.settings['use_embed_thumbnails'] = 'true'
     media = save_media_obj(
         u'Fake Name',
         u'*****@*****.**',
         u'Python Code Swarm',
         u'A visualization of all activity in the Python repository.',
         u'',
         None,
         u'http://www.vimeo.com/1093745'
     )
     # XXX: The following values are based on the values provided by the
     #      remote site at the time this test was written. They may change
     #      in future.
     assert media.duration == 282
     thumbnail_path = thumb_path(media, 's', exists=True)
     assert thumbnail_path is not None
     img = open(thumbnail_path)
     s = sha1(img.read()).hexdigest()
     img.close()
     assert s == '1eb9442b7864841e0f48270de7e3e871050b3876'
Exemplo n.º 3
0
 def test_add_google_video(self):
     pylons.app_globals.settings['use_embed_thumbnails'] = 'true'
     media = save_media_obj(
         u'Fake Name',
         u'*****@*****.**',
         u'Pictures at an Exhibition',
         u'A nice, long, production of the orchestrated Pictures...',
         u'',
         None,
         u'http://video.google.com/videoplay?docid=8997593004077118819'
     )
     # XXX: The following values are based on the values provided by the
     #      remote site at the time this test was written. They may change
     #      in future.
     assert media.duration == 1121
     thumbnail_path = thumb_path(media, 's', exists=True)
     assert thumbnail_path is not None
     img = open(thumbnail_path)
     s = sha1(img.read()).hexdigest()
     img.close()
     assert s == 'f8e84e4a487c9ff6ea69ac696c199ae6ac222e38'
Exemplo n.º 4
0
 def test_add_youtube_video(self):
     pylons.app_globals.settings['use_embed_thumbnails'] = 'true'
     media = save_media_obj(
         u'Fake Name',
         u'*****@*****.**',
         u'Old Spice',
         u'Isiah Mustafa stars in...',
         u'',
         None,
         u'http://www.youtube.com/watch?v=uLTIowBF0kE'
     )
     # XXX: The following values are based on the values provided by the
     #      remote site at the time this test was written. They may change
     #      in future.
     assert media.duration == 32
     thumbnail_path = thumb_path(media, 's', exists=True)
     assert thumbnail_path is not None
     img = open(thumbnail_path)
     s = sha1(img.read()).hexdigest()
     img.close()
     assert s == 'f0a3f5991fa032077faf2d3c698a6cf3e9dcadc1'
Exemplo n.º 5
0
    def submit_async(self, **kwargs):
        """Ajax form validation and/or submission.

        This is the save handler for :class:`~mediacore.forms.media.UploadForm`.

        When ajax is enabled this action is called for each field as the user
        fills them in. Although the entire form is validated, the JS only
        provides the value of one field at a time,

        :param validate: A JSON list of field names to check for validation
        :parma \*\*kwargs: One or more form field values.
        :rtype: JSON dict
        :returns:
            :When validating one or more fields:

            valid
                bool
            err
                A dict of error messages keyed by the field names

            :When saving an upload:

            success
                bool
            redirect
                If valid, the redirect url for the upload successful page.

        """
        if 'validate' in kwargs:
            # we're just validating the fields. no need to worry.
            fields = json.loads(kwargs['validate'])
            err = {}
            for field in fields:
                if field in tmpl_context.form_errors:
                    err[field] = tmpl_context.form_errors[field]

            data = dict(
                valid = len(err) == 0,
                err = err
            )
        else:
            # We're actually supposed to save the fields. Let's do it.
            if len(tmpl_context.form_errors) != 0:
                # if the form wasn't valid, return failure
                tmpl_context.form_errors['success'] = False
                data = tmpl_context.form_errors
            else:
                # else actually save it!
                kwargs.setdefault('name')

                media_obj = save_media_obj(
                    kwargs['name'], kwargs['email'],
                    kwargs['title'], kwargs['description'],
                    None, kwargs['file'], kwargs['url'],
                )
                email.send_media_notification(media_obj)
                data = dict(
                    success = True,
                    redirect = url_for(action='success')
                )

        return data