Ejemplo n.º 1
0
def _stack():
    """
    Administer a stack of slides.
    """
    context = make_context(asset_depth=1)

    sequence = SlideSequence.select()
    sequence_dicts = sequence.dicts()

    time = 0

    for slide in sequence:
        time += slide.slide.time_on_screen

    for slide_dict in sequence_dicts:
        for slide in sequence:
            if slide.slide.slug == slide_dict['slide']:
                slide_dict['name'] = slide.slide.name
                slide_dict['time_on_screen'] = slide.slide.time_on_screen

                if slide_dict['slide'].startswith('tumblr'):
                    slide_dict['news_item'] = True

    context.update({
        'sequence': sequence_dicts,
        'slides': Slide.select().dicts(),
        'graphics': Slide.select().where(fn.Lower(fn.Substr(Slide.slug, 1, 6)) != 'tumblr').order_by(Slide.slug).dicts(),
        'news':  Slide.select().where(fn.Lower(fn.Substr(Slide.slug, 1, 6)) == 'tumblr').order_by(Slide.slug.desc()).dicts(),
        'time': time,
    })

    return render_template('admin/stack.html', **context)
Ejemplo n.º 2
0
  def test_slide_insert(self):
    print "in test_slide_insert"
    setup(self)

    self.assertEqual(Slide.objects.count(), 2)
    slide3 = Slide(lesson=Lesson.objects.get(pk=1), name="Slide3", content="<h1>Slide3</h1>", position=3, googleStyles=" ")
    slide3.save()
    self.assertEqual(Slide.objects.count(), 3)
Ejemplo n.º 3
0
def edit_job(slug):
    try:
        j = Job.objects.get(site=g.site.domain, slug=slug)
    except Job.DoesNotExist:
        abort(404)

    if not g.site.domain == g.user:
        abort(403)

    if request.method == "POST":
        j.name = request.form.get("name")
        #j.slug = slugify(j.name)
        j.categories = [
            c.strip() for c in request.form.get("categories").split(",")
        ]
        j.intro = request.form.get("intro")
        j.description = request.form.get("description")
        j.slides = []
        texts = request.form.getlist("text")
        image_urls = request.form.getlist("image_url")
        captions = request.form.getlist("caption")
        caption_links = request.form.getlist("caption_link")
        for text, image_url, caption, caption_link in zip(
                texts, image_urls, captions, caption_links):
            if text or image_url:
                j.slides.append(
                    Slide(text=text,
                          image_url=image_url,
                          caption=caption,
                          caption_link=caption_link))
        j.save()
        return redirect(url_for(".job", slug=j.slug))

    return render_template("edit_job.html", job=j)
Ejemplo n.º 4
0
def _build_horizontal_slides(photos):
    slides = set()

    for photo in photos:
        slides.add(Slide(photo))

    return slides
Ejemplo n.º 5
0
def move_slide(request, slide_id, direction):
    slide = get_object_or_404(Slide, pk=slide_id)
    slide_to_move_up = None
    slide_to_move_down = None
    
    if not ( (direction == 'up' and slide.is_first()) or (direction == 'down' and slide.is_last()) ):
        if direction == 'up':
            slide_to_move_up = slide
            slide_to_move_down = Slide.objects.get(presentation=slide.presentation.id, order_number=slide.order_number-1)
        else:
            slide_to_move_down = slide
            slide_to_move_up = Slide.objects.get(presentation=slide.presentation.id, order_number=slide.order_number+1)
        print "slide to move up: %d", slide_to_move_up.id
        print "slide to move down: %D", slide_to_move_down.id
        Slide.swich_slides_order(slide_to_move_up, slide_to_move_down)
    return redirect(slide.presentation.get_details_url())
Ejemplo n.º 6
0
def new_slide(journey_id):
    journey = Journey.query.filter_by(id=journey_id, user_id=current_user.id).first()
    if not journey:
        flash(BAD_KITTY, 'danger')
        return redirect(url_for('index'))

    form = NewSlideForm(journey_id=journey_id)
    if form.validate_on_submit():
        slide = Slide()
        slide.create(form.data['title'], form.data['description'], journey_id)
        db.session.add(slide)
        db.session.commit()
        flash('Slide added to journey, you can now add photos to your slide.', 'success')
        return redirect(url_for('new_photo', slide_id=slide.id))

    flash_errors(form)
    return render_template('new-slide.html', form=form, title='New Slide')
Ejemplo n.º 7
0
def delete_slide(request, presentation_id, slide_id):
    confirmation = False
    slide = get_object_or_404(Slide, pk=slide_id)
    presentation = get_object_or_404(Presentation, pk=presentation_id)
    
    if request.method == "POST" and request.POST['confirm'] == 'Tak':
        slide_order_nb = slide.order_number
        slide.delete()
        Slide.repair_slide_order(presentation_id, slide_order_nb)
        
        confirmation = True
    ctx = {
           'confirmation': confirmation,
           'slide': slide,
           'presentation': presentation,
    }    
    return render_to_response('presentation/delete_slide.html', ctx)
Ejemplo n.º 8
0
def new_slide(journey_id):
    journey = Journey.query.filter_by(id=journey_id,
                                      user_id=current_user.id).first()
    if not journey:
        flash(BAD_KITTY, 'danger')
        return redirect(url_for('index'))

    form = NewSlideForm(journey_id=journey_id)
    if form.validate_on_submit():
        slide = Slide()
        slide.create(form.data['title'], form.data['description'], journey_id)
        db.session.add(slide)
        db.session.commit()
        flash('Slide added to journey, you can now add photos to your slide.',
              'success')
        return redirect(url_for('new_photo', slide_id=slide.id))

    flash_errors(form)
    return render_template('new-slide.html', form=form, title='New Slide')
Ejemplo n.º 9
0
def slide_create(request):
    """
    If the request is a GET, renders a form to create a new slide from a slide
    bundle. If the request is a POST, it should contain a bundle that is used to
    create a new slide. The slide's metadata is populated from the bundle's
    manifest file.
    """
    if request.method == 'POST':
        f = CreateSlideForm(request.POST, request.FILES)
        if f.is_valid():
            tf = tarfile.open(fileobj=request.FILES['bundle'])
            s = Slide(user=request.user,
                      title='Uploaded %s' % (tf.__hash__()))
            s.populate_from_bundle(request.FILES['bundle'], tf)
            return redirect('orwell-slide-index')
    else:
        f = CreateSlideForm()
    return render_to_response('orwell/create-slide.html', {'form':f},
                              context_instance=RequestContext(request))
Ejemplo n.º 10
0
def pdf_slide_create(request):
    """
    If the request is a GET, renders a form to create a new slide from a PDF. If
    the request is a POST, uses the information in the POST data to create a new
    slide from a PDF included in that data.
    """
    if request.method == 'POST':
        f = CreatePDFSlideForm(request.POST, request.FILES)
        if f.is_valid():
            def in_cur_dir(path):
                return os.path.join(os.path.dirname(__file__),path)
            fpath = handle_uploaded_file(request.FILES['pdf'])
            convert_pdf(fpath,  in_cur_dir("PDFslide/pdf.png"), (1920,1080))
            convert_pdf(fpath,  in_cur_dir("PDFslide/_thumb.png"), (200, 113))
            t = RenderTemplate(open(in_cur_dir('PDFslide/manifest.js.tmp')).read())
            manifest = open(in_cur_dir('PDFslide/manifest.js'), 'w+')
            manifest.write(t.render(Context({'title':f.cleaned_data['title'],
                                             'duration':f.cleaned_data['duration'],
                                             'priority':f.cleaned_data['priority']})))
            manifest.close()
            bundle_loc = in_cur_dir('bundle.tar.gz')
            PDFslide_loc = in_cur_dir('PDFslide')
            os.chdir(PDFslide_loc)
            os.system('tar -zcf %s *' % bundle_loc)

            s = Slide(user=request.user,
                      title=f.cleaned_data['title'],
                      duration=f.cleaned_data['duration'],
                      priority=f.cleaned_data['priority'])

            s.populate_from_bundle(File(open(bundle_loc)), tarfile.open(bundle_loc))
            # remove these so as not to cause problems for the next pdf slide
            os.remove(in_cur_dir("PDFslide/pdf.png"))
            os.remove(in_cur_dir("PDFslide/_thumb.png"))
            os.remove(in_cur_dir("PDFslide/manifest.js"))
            os.remove(bundle_loc)
            os.remove(fpath)
            return redirect('orwell-slide-index')
    else:
        f = CreatePDFSlideForm()
    return render_to_response('orwell/create-pdf-slide.html', {'form':f},
                              context_instance=RequestContext(request))
Ejemplo n.º 11
0
def _stack():
    """
    Administer a stack of slides.
    """
    context = make_context(asset_depth=1)

    sequence = SlideSequence.select()
    sequence_dicts = sequence.dicts()

    time = 0

    for slide in sequence:
        time += slide.slide.time_on_screen

    for slide_dict in sequence_dicts:
        for slide in sequence:
            if slide.slide.slug == slide_dict['slide']:
                slide_dict['name'] = slide.slide.name
                slide_dict['time_on_screen'] = slide.slide.time_on_screen

                if slide_dict['slide'].startswith('tumblr'):
                    slide_dict['news_item'] = True

    context.update({
        'sequence':
        sequence_dicts,
        'slides':
        Slide.select().dicts(),
        'graphics':
        Slide.select().where(
            fn.Lower(fn.Substr(Slide.slug, 1, 6)) != 'tumblr').order_by(
                Slide.slug).dicts(),
        'news':
        Slide.select().where(
            fn.Lower(fn.Substr(Slide.slug, 1, 6)) == 'tumblr').order_by(
                Slide.slug.desc()).dicts(),
        'time':
        time,
    })

    return render_template('admin/stack.html', **context)
Ejemplo n.º 12
0
def _build_vertical_slides(photos):
    slides = set()
    idx = 0
    photos = list(photos)
    while idx < len(photos):
        idx2 = idx + 1
        while idx2 < len(photos):
            slides.add(Slide(photo1=photos[idx], photo2=photos[idx2]))
            idx2 += 1
        idx += 1

    return slides
Ejemplo n.º 13
0
def setup(self):  
  user1 = User(username="******", email="*****@*****.**", first_name="john", last_name="smith")
  user2 = User(username="******", email="*****@*****.**", first_name="sally", last_name="smith")
  user1.save()
  user2.save()
  
  teacher1 = Teacher()
  teacher1.teacher = user1
  teacher1.save()
  teacher2 = Teacher()
  teacher2.teacher = user2
  teacher2.save()  

  course1 = Course(teacher=teacher1, name="Intro1", position=1)
  course2 = Course(teacher=teacher2, name="Advanced2", position=2)
  course1.save()
  course2.save()
  
  lesson1 = Lesson(course=course1, name="Lesson1", description="Intro1 - Lesson1", position=1)
  lesson2 = Lesson(course=course1, name="Lesson2", description="Intro1 - Lesson2", position=2)
  lesson1.save()
  lesson2.save()

  slide1 = Slide(lesson=lesson1, name="Slide1", content="<h1>Slide1</h1>", position=1, googleStyles=" ")
  slide2 = Slide(lesson=lesson1, name="Slide2", content="<h1>Slide2</h1>", position=2, googleStyles=" ")
  slide1.save()
  slide2.save()
Ejemplo n.º 14
0
def cli_manage_slide(request):
    """
    Accepts POSTS from authenticated clients, and allows those clients to either
    create or modify existing slides.
    """
    if request.method == 'POST':
        f = CLICCreateSlideForm(request.POST, request.FILES)
        if f.is_valid():
            tf = tarfile.open(fileobj=request.FILES['bundle'])
            id = f.cleaned_data['id']
            create = f.cleaned_data['mode'] == 'create'
            if create and not id:
                s = Slide(user=request.user,
                          title='cli uploaded %s' % (tf.__hash__()))
            elif not create and id:
                s = Slide.objects.get(id=id)
                if not s.allowed(request.user):
                    return HttpResponse('Not allowed to modify slide')
            else:
                return HttpResponse('invalid: %s' % str(f.data))
            s.populate_from_bundle(request.FILES['bundle'], tf)
            return HttpResponse('Slide %s %sd'
                                % (s.id, f.cleaned_data['mode']))
    return HttpResponseNotAllowed(['POST'])
Ejemplo n.º 15
0
def _state_house_slide(slug, page):
    """
    Serve a state slide.
    """
    from models import Race, Slide

    slide = Slide.get(Slide.slug == 'state-house-results')

    slug = slug.upper()

    races = Race.select().where(
        (Race.office_name == 'U.S. House') &
        (Race.state_postal == slug)
    ).order_by(Race.seat_number)

    timestamp = get_last_updated(races)
    context = make_context(timestamp=timestamp)

    context['slide_class'] = 'state-house'
    context['state_postal'] = slug
    context['state_name'] = app_config.STATES.get(slug)

    # Calculate BOP using all races
    context.update(app_utils.calculate_state_bop(races))

    # Filter to display races
    races = races.where(Race.featured_race == True)

    if slug in app_config.PAGINATED_STATES:
        race_count = races.count()
        page_size = race_count / 2

        if page == 1:
            races = races.limit(page_size)
        elif page == 2:
            races = races.offset(page_size)

        context['page'] = page

    if races.count():
        context['time_on_screen'] = slide.time_on_screen
        context['races'] = [race for race in races]
        context['body'] = render_template('slides/state_house.html', **context)

        return render_template('_slide.html', **context)
    else:
        return "no races", 404
Ejemplo n.º 16
0
def _state_house_slide(slug, page):
    """
    Serve a state slide.
    """
    from models import Race, Slide

    slide = Slide.get(Slide.slug == 'state-house-results')

    slug = slug.upper()

    races = Race.select().where((Race.office_name == 'U.S. House')
                                & (Race.state_postal == slug)).order_by(
                                    Race.seat_number)

    timestamp = get_last_updated(races)
    context = make_context(timestamp=timestamp)

    context['slide_class'] = 'state-house'
    context['state_postal'] = slug
    context['state_name'] = app_config.STATES.get(slug)

    # Calculate BOP using all races
    context.update(app_utils.calculate_state_bop(races))

    # Filter to display races
    races = races.where(Race.featured_race == True)

    if slug in app_config.PAGINATED_STATES:
        race_count = races.count()
        page_size = race_count / 2

        if page == 1:
            races = races.limit(page_size)
        elif page == 2:
            races = races.offset(page_size)

        context['page'] = page

    if races.count():
        context['time_on_screen'] = slide.time_on_screen
        context['races'] = [race for race in races]
        context['body'] = render_template('slides/state_house.html', **context)

        return render_template('_slide.html', **context)
    else:
        return "no races", 404
Ejemplo n.º 17
0
def slide_admin_update(request, slide_id, prefix):
    if request.is_ajax():
        form = SlideForm(request.POST) if prefix == 'None' else SlideForm(request.POST, prefix=prefix) 
        if form.is_valid():
            try:
                slide = Slide.objects.get(pk=slide_id)
                slide.lesson = form.cleaned_data['lesson']
                slide.content = form.cleaned_data['content']
                slide.googleStyles = form.cleaned_data['googleStyles']
                slide.name = form.cleaned_data['name'] 
                slide.save()
                return HttpResponse('OK')
                
            except ObjectDoesNotExist:
                # create new object
                position = None
                if Slide.objects.count() > 0:
                    slide = Slide.objects.order_by('-position').all()[0]
                    position = slide.position

                else:
                    position = 1

                newslide = Slide()
                newslide.lesson = form.cleaned_data['lesson']
                newslide.name = form.cleaned_data['name']
                newslide.content = form.cleaned_data['content']
                newslide.googleStyles = form.cleaned_data['googleStyles']
                newslide.position = position
                newslide.save()
                response = {'created_object_id': newslide.pk}
                return HttpResponse(json.dumps(response), mimetype="application/json") 
        else:
            errors_dict = {}
            if form.errors:
                for error in form.errors:
                    e = form.errors[error]
                    field = prefix+"-"+error;
                    errors_dict[field] = unicode(e)
            print errors_dict
            return HttpResponseBadRequest(json.dumps(errors_dict))
    else:
        return HttpResponseNotFound('You do not have permission to access this page!')
Ejemplo n.º 18
0
def _slide(slug):
    """
    Serve up slide html fragment
    """
    from models import Slide

    context = make_context()

    slide = Slide.get(Slide.slug == slug)
    view_name = slide.view_name

    if slide.data:
        context['body'] = slides.__dict__[view_name](slide.data)
    else:
        context['body'] = slides.__dict__[view_name]()

    context['slide_class'] = view_name.replace('_', '-')
    context['time_on_screen'] = slide.time_on_screen

    return render_template('_slide.html', **context)
Ejemplo n.º 19
0
def _slide(slug):
    """
    Serve up slide html fragment
    """
    from models import Slide

    context = make_context()

    slide = Slide.get(Slide.slug == slug)
    view_name = slide.view_name

    if slide.data:
        context['body'] = slides.__dict__[view_name](slide.data)
    else:
        context['body'] = slides.__dict__[view_name]()

    context['slide_class'] = view_name.replace('_', '-')
    context['time_on_screen'] = slide.time_on_screen

    return render_template('_slide.html', **context)
Ejemplo n.º 20
0
def new_job():
    if not g.site.domain == g.user:
        abort(403)

    j = Job()
    if request.method == "POST":
        portfolio = Portfolio.objects.get(site=g.site.domain)
        job_name = request.form.get("name")
        slugs = [__j.slug for __j in Job.objects.filter(site=g.site.domain)]
        counter = 1
        slug = slugify(job_name)
        __slug = slug
        while __slug in slugs:
            counter += 1
            __slug = "%s_%d" % (slug, counter)
        j.slug = __slug
        j.name = job_name
        j.site = g.site.domain
        j.categories = [
            c.strip() for c in request.form.get("categories").split(",")
        ]
        j.intro = request.form.get("intro")
        j.description = request.form.get("description")
        j.slides = []
        texts = request.form.getlist("text")
        image_urls = request.form.getlist("image_url")
        captions = request.form.getlist("caption")
        caption_links = request.form.getlist("caption_link")
        for text, image_url, caption, caption_link in zip(
                texts, image_urls, captions, caption_links):
            if text or image_url:
                j.slides.append(
                    Slide(text=text,
                          image_url=image_url,
                          caption=caption,
                          caption_link=caption_link))
        j.save()
        portfolio.jobs.append(j)
        portfolio.save()
        return redirect(url_for(".job", slug=j.slug))
    return render_template("edit_job.html", job=j)
Ejemplo n.º 21
0
def _state_senate_slide(slug):
    """
    Serve a state slide.
    """
    from models import Race, Slide

    slide = Slide.get(Slide.slug == 'state-senate-results')
    slug = slug.upper()

    senate_races = Race.select().where(
        (Race.office_name == 'U.S. Senate') &
        (Race.state_postal == slug)
    ).order_by(Race.seat_number)

    governor_races = Race.select().where(
        (Race.office_name == 'Governor') &
        (Race.state_postal == slug)
    )

    if senate_races.count() == 0 and governor_races.count() == 0:
        return "404", 404

    senate_updated = get_last_updated(senate_races)
    governor_updated = get_last_updated(governor_races)

    if senate_updated > governor_updated:
        timestamp = senate_updated
    else:
        timestamp = governor_updated

    context = make_context(timestamp=timestamp)
    context['state_postal'] = slug
    context['state_name'] = app_config.STATES.get(slug)

    context['slide_class'] = 'state-senate'
    context['senate'] = senate_races
    context['governor'] = governor_races
    context['time_on_screen'] = slide.time_on_screen
    context['body'] = render_template('slides/state_senate.html', **context)

    return render_template('_slide.html', **context)
Ejemplo n.º 22
0
def _state_senate_slide(slug):
    """
    Serve a state slide.
    """
    from models import Race, Slide

    slide = Slide.get(Slide.slug == 'state-senate-results')
    slug = slug.upper()

    senate_races = Race.select().where((Race.office_name == 'U.S. Senate')
                                       & (Race.state_postal == slug)).order_by(
                                           Race.seat_number)

    governor_races = Race.select().where((Race.office_name == 'Governor')
                                         & (Race.state_postal == slug))

    if senate_races.count() == 0 and governor_races.count() == 0:
        return "404", 404

    senate_updated = get_last_updated(senate_races)
    governor_updated = get_last_updated(governor_races)

    if senate_updated > governor_updated:
        timestamp = senate_updated
    else:
        timestamp = governor_updated

    context = make_context(timestamp=timestamp)
    context['state_postal'] = slug
    context['state_name'] = app_config.STATES.get(slug)

    context['slide_class'] = 'state-senate'
    context['senate'] = senate_races
    context['governor'] = governor_races
    context['time_on_screen'] = slide.time_on_screen
    context['body'] = render_template('slides/state_senate.html', **context)

    return render_template('_slide.html', **context)