Esempio n. 1
0
def run(url, dry=False):
    """return a tuple of (result, error)"""
    original = url
    _context = None

    for match in URLMatch.objects.all():
        regex = re.compile(match.string)
        if regex.findall(url):
            transforms = (URLTransform.objects.filter(
                match=match).order_by('order'))
            for transform in transforms:
                find_regex = re.compile(transform.find)
                if _context is None:
                    _context = create_context()
                # the `replace_with` string might have variables in it
                replace_with_template = Template(transform.replace_with)
                replace_with = replace_with_template.render(_context)
                # if this is a `dry` run we don't want to accidentally
                # reveal a real password
                if dry:
                    from airmozilla.manage.helpers import (
                        scrub_transform_passwords)
                    replace_with = scrub_transform_passwords(replace_with)
                url = find_regex.sub(replace_with, url)
            match.use_count += 1

    if original != url and not dry:
        match.save()

    return url, None
Esempio n. 2
0
def get_video_tagged(event, request, autoplay=False, tag=None):

    def poster_url(geometry='896x504', crop='center'):
        image = event.picture and event.picture.file or event.placeholder_img
        return thumbnail(image, geometry, crop=crop).url

    context = {
        'md5': lambda s: hashlib.md5(s).hexdigest(),
        'event': event,
        'request': request,
        'datetime': datetime.datetime.utcnow(),
        'vidly_tokenize': vidly.tokenize,
        'edgecast_tokenize': edgecast_tokenize,
        'akamai_tokenize': akamai_tokenize,
        'popcorn_url': event.popcorn_url,
        'autoplay': autoplay and 'true' or 'false',  # javascript
        'poster_url': poster_url,
    }
    if isinstance(event.template_environment, dict):
        context.update(event.template_environment)
    if tag:
        submissions = VidlySubmission.objects.filter(
            tag=tag,
            event=event
        )
        if not submissions.exists():
            raise VidlySubmission.DoesNotExist(tag)
        context['tag'] = tag
    template = Template(event.template.content)
    try:
        template_tagged = template.render(context)
    except vidly.VidlyTokenizeError, msg:
        template_tagged = '<code style="color:red">%s</code>' % msg
Esempio n. 3
0
def run(url, dry=False):
    """return a tuple of (result, error)"""
    original = url
    _context = None

    for match in URLMatch.objects.all():
        regex = re.compile(match.string)
        if regex.findall(url):
            transforms = (
                URLTransform.objects.filter(match=match).order_by('order')
            )
            for transform in transforms:
                find_regex = re.compile(transform.find)
                if _context is None:
                    _context = create_context()
                # the `replace_with` string might have variables in it
                replace_with_template = Template(transform.replace_with)
                replace_with = replace_with_template.render(_context)
                # if this is a `dry` run we don't want to accidentally
                # reveal a real password
                if dry:
                    from airmozilla.manage.helpers import (
                        scrub_transform_passwords
                    )
                    replace_with = scrub_transform_passwords(replace_with)
                url = find_regex.sub(replace_with, url)
            match.use_count += 1

    if original != url and not dry:
        match.save()

    return url, None
Esempio n. 4
0
    def get(self, request, slug):
        try:
            event = Event.objects.get(slug=slug)
        except Event.DoesNotExist:
            try:
                event = Event.objects.get(slug__iexact=slug)
            except Event.DoesNotExist:
                try:
                    old_slug = EventOldSlug.objects.get(slug=slug)
                    return redirect('main:event', slug=old_slug.event.slug)
                except EventOldSlug.DoesNotExist:
                    # does it exist as a static page
                    return self.cant_find_event(request, slug)

        if not self.can_view_event(event, request.user):
            return self.cant_view_event(event, request)

        warning = None
        if event.status not in (Event.STATUS_SCHEDULED, Event.STATUS_PENDING):
            if not request.user.is_active:
                return http.HttpResponse('Event not scheduled')
            else:
                warning = "Event is not publicly visible - not scheduled."

        if event.approval_set.filter(approved=False).exists():
            if not request.user.is_active:
                return http.HttpResponse('Event not approved')
            else:
                warning = "Event is not publicly visible - not yet approved."

        hits = None

        template_tagged = ''
        if event.template and not event.is_upcoming():
            context = {
                'md5': lambda s: hashlib.md5(s).hexdigest(),
                'event': event,
                'request': request,
                'datetime': datetime.datetime.utcnow(),
                'vidly_tokenize': vidly.tokenize,
                'edgecast_tokenize': edgecast_tokenize,
                'popcorn_url': event.popcorn_url,
            }
            if isinstance(event.template_environment, dict):
                context.update(event.template_environment)
            template = Template(event.template.content)
            try:
                template_tagged = template.render(context)
            except vidly.VidlyTokenizeError, msg:
                template_tagged = '<code style="color:red">%s</code>' % msg

            stats_query = (
                EventHitStats.objects.filter(event=event)
                .values_list('total_hits', flat=True)
            )
            for total_hits in stats_query:
                hits = total_hits
Esempio n. 5
0
    def get(self, request, slug):
        event = self.get_event(slug, request)
        if isinstance(event, http.HttpResponse):
            return event

        if not self.can_view_event(event, request):
            return self.cant_view_event(event, request)

        warning = None
        if event.status not in (Event.STATUS_SCHEDULED, Event.STATUS_PENDING):
            if not request.user.is_superuser:
                self.template_name = 'main/event_not_scheduled.html'
            else:
                warning = "Event is not publicly visible - not scheduled."

        if event.approval_set.filter(approved=False).exists():
            if not request.user.is_active:
                return http.HttpResponse('Event not approved')
            else:
                warning = "Event is not publicly visible - not yet approved."

        hits = None

        template_tagged = ''
        if event.template and not event.is_upcoming():
            # The only acceptable way to make autoplay be on
            # is to send ?autoplay=true
            # All other attempts will switch it off.
            autoplay = request.GET.get('autoplay', 'false') == 'true'
            context = {
                'md5': lambda s: hashlib.md5(s).hexdigest(),
                'event': event,
                'request': request,
                'datetime': datetime.datetime.utcnow(),
                'vidly_tokenize': vidly.tokenize,
                'edgecast_tokenize': edgecast_tokenize,
                'popcorn_url': event.popcorn_url,
                'autoplay': autoplay and 'true' or 'false',  # javascript
            }
            if isinstance(event.template_environment, dict):
                context.update(event.template_environment)
            template = Template(event.template.content)
            try:
                template_tagged = template.render(context)
            except vidly.VidlyTokenizeError, msg:
                template_tagged = '<code style="color:red">%s</code>' % msg

            stats_query = (
                EventHitStats.objects.filter(event=event)
                .values_list('total_hits', flat=True)
            )
            for total_hits in stats_query:
                hits = total_hits
Esempio n. 6
0
    def get(self, request, slug):
        event = self.get_event(slug, request)
        if isinstance(event, http.HttpResponse):
            return event

        if not self.can_view_event(event, request):
            return self.cant_view_event(event, request)

        warning = None
        if event.status not in (Event.STATUS_SCHEDULED, Event.STATUS_PENDING):
            if not request.user.is_superuser:
                self.template_name = 'main/event_not_scheduled.html'
            else:
                warning = "Event is not publicly visible - not scheduled."

        if event.approval_set.filter(approved=False).exists():
            if not request.user.is_active:
                return http.HttpResponse('Event not approved')
            else:
                warning = "Event is not publicly visible - not yet approved."

        hits = None

        template_tagged = ''
        if event.template and not event.is_upcoming():
            # The only acceptable way to make autoplay be on
            # is to send ?autoplay=true
            # All other attempts will switch it off.
            autoplay = request.GET.get('autoplay', 'false') == 'true'
            context = {
                'md5': lambda s: hashlib.md5(s).hexdigest(),
                'event': event,
                'request': request,
                'datetime': datetime.datetime.utcnow(),
                'vidly_tokenize': vidly.tokenize,
                'edgecast_tokenize': edgecast_tokenize,
                'popcorn_url': event.popcorn_url,
                'autoplay': autoplay and 'true' or 'false',  # javascript
            }
            if isinstance(event.template_environment, dict):
                context.update(event.template_environment)
            template = Template(event.template.content)
            try:
                template_tagged = template.render(context)
            except vidly.VidlyTokenizeError, msg:
                template_tagged = '<code style="color:red">%s</code>' % msg

            stats_query = (EventHitStats.objects.filter(
                event=event).values_list('total_hits', flat=True))
            for total_hits in stats_query:
                hits = total_hits
Esempio n. 7
0
def event(request, slug):
    """Video, description, and other metadata."""
    try:
        event = Event.objects.get(slug=slug)
    except Event.DoesNotExist:
        try:
            event = Event.objects.get(slug__iexact=slug)
        except Event.DoesNotExist:
            try:
                old_slug = EventOldSlug.objects.get(slug=slug)
                return redirect('main:event', slug=old_slug.event.slug)
            except EventOldSlug.DoesNotExist:
                # does it exist as a static page
                return flatpage(request, slug)

    if not can_view_event(event, request.user):
        return redirect('main:login')

    warning = None
    if event.status not in (Event.STATUS_SCHEDULED, Event.STATUS_PENDING):
        if not request.user.is_active:
            return http.HttpResponse('Event not scheduled')
        else:
            warning = "Event is not publicly visible - not scheduled."

    if event.approval_set.filter(approved=False).exists():
        if not request.user.is_active:
            return http.HttpResponse('Event not approved')
        else:
            warning = "Event is not publicly visible - not yet approved."

    template_tagged = ''
    if event.template and not event.is_upcoming():
        context = {
            'md5': lambda s: hashlib.md5(s).hexdigest(),
            'event': event,
            'request': request,
            'datetime': datetime.datetime.utcnow(),
            'vidly_tokenize': vidly.tokenize,
            'edgecast_tokenize': edgecast_tokenize,
        }
        if isinstance(event.template_environment, dict):
            context.update(event.template_environment)
        template = Template(event.template.content)
        try:
            template_tagged = template.render(context)
        except vidly.VidlyTokenizeError, msg:
            template_tagged = '<code style="color:red">%s</code>' % msg
Esempio n. 8
0
def event(request, slug):
    """Video, description, and other metadata."""
    try:
        event = Event.objects.get(slug=slug)
    except Event.DoesNotExist:
        try:
            event = Event.objects.get(slug__iexact=slug)
        except Event.DoesNotExist:
            try:
                old_slug = EventOldSlug.objects.get(slug=slug)
                return redirect('main:event', slug=old_slug.event.slug)
            except EventOldSlug.DoesNotExist:
                # does it exist as a static page
                return flatpage(request, slug)

    if not can_view_event(event, request.user):
        return redirect('main:login')

    warning = None
    if event.status != Event.STATUS_SCHEDULED:
        if not request.user.is_active:
            return http.HttpResponse('Event not scheduled')
        else:
            warning = "Event is not publicly visible - not scheduled."

    if event.approval_set.filter(approved=False).exists():
        if not request.user.is_active:
            return http.HttpResponse('Event not approved')
        else:
            warning = "Event is not publicly visible - not yet approved."
    template_tagged = ''
    if event.template and not event.is_upcoming():
        context = {
            'md5': lambda s: hashlib.md5(s).hexdigest(),
            'event': event,
            'request': request,
            'datetime': datetime.datetime.utcnow(),
            'vidly_tokenize': vidly.tokenize,
            'edgecast_tokenize': edgecast_tokenize,
        }
        if isinstance(event.template_environment, dict):
            context.update(event.template_environment)
        template = Template(event.template.content)
        try:
            template_tagged = template.render(context)
        except vidly.VidlyTokenizeError, msg:
            template_tagged = '<code style="color:red">%s</code>' % msg
Esempio n. 9
0
def event(request, slug):
    """Video, description, and other metadata."""
    try:
        event = Event.objects.get(slug=slug)
    except Event.DoesNotExist:
        old_slug = get_object_or_404(EventOldSlug, slug=slug)
        return redirect('main:event', slug=old_slug.event.slug)
    if not event.public and not request.user.is_active:
        return redirect('main:login')
    warning = None
    if event.status != Event.STATUS_SCHEDULED:
        if not request.user.is_active:
            return http.HttpResponse('Event not scheduled')
        else:
            warning = "Event is not publicly visible - not scheduled."
    if event.approval_set.filter(approved=False).exists():
        if not request.user.is_active:
            return http.HttpResponse('Event not approved')
        else:
            warning = "Event is not publicly visible - not yet approved."
    template_tagged = ''
    if event.template and not event.is_upcoming():
        context = {
            'md5': lambda s: hashlib.md5(s).hexdigest(),
            'event': event,
            'request': request,
            'datetime': datetime.datetime.utcnow(),
            'vidly_tokenize': vidly_tokenize,
        }
        if isinstance(event.template_environment, dict):
            context.update(event.template_environment)
        template = Template(event.template.content)
        template_tagged = template.render(context)
    participants = event.participants.filter(cleared=Participant.CLEARED_YES)
    return render(
        request, 'main/event.html', {
            'event': event,
            'video': template_tagged,
            'participants': participants,
            'warning': warning
        })
Esempio n. 10
0
def event(request, slug):
    """Video, description, and other metadata."""
    try:
        event = Event.objects.get(slug=slug)
    except Event.DoesNotExist:
        old_slug = get_object_or_404(EventOldSlug, slug=slug)
        return redirect('main:event', slug=old_slug.event.slug)
    if not event.public and not request.user.is_active:
        return redirect('main:login')
    warning = None
    if event.status != Event.STATUS_SCHEDULED:
        if not request.user.is_active:
            return http.HttpResponse('Event not scheduled')
        else:
            warning = "Event is not publicly visible - not scheduled."
    if event.approval_set.filter(approved=False).exists():
        if not request.user.is_active:
            return http.HttpResponse('Event not approved')
        else:
            warning = "Event is not publicly visible - not yet approved."
    template_tagged = ''
    if event.template and not event.is_upcoming():
        context = {
            'md5': lambda s: hashlib.md5(s).hexdigest(),
            'event': event,
            'request': request,
            'datetime': datetime.datetime.utcnow(),
            'vidly_tokenize': vidly_tokenize,
        }
        if isinstance(event.template_environment, dict):
            context.update(event.template_environment)
        template = Template(event.template.content)
        template_tagged = template.render(context)
    participants = event.participants.filter(cleared=Participant.CLEARED_YES)
    return render(request, 'main/event.html', {
        'event': event,
        'video': template_tagged,
        'participants': participants,
        'warning': warning
    })
Esempio n. 11
0
def get_video_tagged(event, request, autoplay=False, tag=None):
    context = {
        'md5': lambda s: hashlib.md5(s).hexdigest(),
        'event': event,
        'request': request,
        'datetime': datetime.datetime.utcnow(),
        'vidly_tokenize': vidly.tokenize,
        'edgecast_tokenize': edgecast_tokenize,
        'akamai_tokenize': akamai_tokenize,
        'popcorn_url': event.popcorn_url,
        'autoplay': autoplay and 'true' or 'false',  # javascript
    }
    if isinstance(event.template_environment, dict):
        context.update(event.template_environment)
    if tag:
        submissions = VidlySubmission.objects.filter(tag=tag, event=event)
        if not submissions.exists():
            raise VidlySubmission.DoesNotExist(tag)
        context['tag'] = tag
    template = Template(event.template.content)
    try:
        template_tagged = template.render(context)
    except vidly.VidlyTokenizeError, msg:
        template_tagged = '<code style="color:red">%s</code>' % msg
Esempio n. 12
0
        results = []
        offline_manifest = SortedDict()
        for template, nodes in compressor_nodes.iteritems():
            context = Context(settings.COMPRESS_OFFLINE_CONTEXT)
            template._log = log
            template._log_verbosity = verbosity
            for node in nodes:
                context.push()
                compiled_node = env.compile(jinja2.nodes.Template(node.body))
                context.update(jingo.register.env.globals)
                context.update(jingo.register.env.filters)

                key = get_offline_hexdigest(
                    Template.from_code(
                        jingo.register.env,
                        compiled_node,
                        {}
                    ).render(context))
                try:
                    context['compress_forced'] = True
                    compiled_node = env.compile(jinja2.nodes.Template([node]))
                    result = Template.from_code(
                        env,
                        compiled_node,
                        {}).render(context)
                except Exception, e:
                    raise CommandError("An error occured during rendering %s: "
                                       "%s" % (template.template_name, e))
                offline_manifest[key] = result
                context.pop()
                results.append(result)
Esempio n. 13
0
        log.write("Compressing... ")
        count = 0
        results = []
        offline_manifest = SortedDict()
        for template, nodes in compressor_nodes.iteritems():
            context = Context(settings.COMPRESS_OFFLINE_CONTEXT)
            template._log = log
            template._log_verbosity = verbosity
            for node in nodes:
                context.push()
                compiled_node = env.compile(jinja2.nodes.Template(node.body))
                context.update(jingo.register.env.globals)
                context.update(jingo.register.env.filters)

                key = get_offline_hexdigest(
                    Template.from_code(jingo.register.env, compiled_node,
                                       {}).render(context))
                try:
                    context['compress_forced'] = True
                    compiled_node = env.compile(jinja2.nodes.Template([node]))
                    result = Template.from_code(env, compiled_node,
                                                {}).render(context)
                except Exception, e:
                    raise CommandError("An error occured during rendering %s: "
                                       "%s" % (template.template_name, e))
                offline_manifest[key] = result
                context.pop()
                results.append(result)
                count += 1

        write_offline_manifest(offline_manifest)