Example #1
0
def test(request):
  if request.method == 'POST':
    items = request.POST.items()
    pks = filter(lambda (x, y): x.isdigit() and y == 'on', items)
    pks = map(lambda x: x[0], pks)
    cards = Card.objects.filter(pk__in=pks)
    cards = generateFullCardListFromQueryset(cards)
    return render_to_response('test/test.html', {
        'cards': cards,
      }, context_instance=RequestContext(request)
    )
  return HttpResponseRedirect('/myCards')
Example #2
0
def csv(request):
  csv_data = []
  if request.method == 'POST':
    items = request.POST.items()
    pks = filter(lambda (x, y): x.isdigit() and y == 'on', items)
    pks = map(lambda x: x[0], pks)
    cards = Card.objects.filter(pk__in=pks)
    cards = generateFullCardListFromQueryset(cards)
    
    header = ('front', 'back', 'priority', 'tags', 'sources')
    csv_data.append(header)
    for card in cards:
      csvList = []
      csvList.append(csvEscape(card.card['front']))
      csvList.append(csvEscape(card.card['back']))
      csvList.append("priority " + card.card['priority'])
      tags = csvEscape(', '.join(card.tagList))
      csvList.append(tags)
      sources = csvEscape(', '.join(card.sourceList))
      csvList.append(sources)
      csv_data.append(tuple(csvList))


    # The data is hard-coded here, but you could load it from a database or
    # some other source.
    """csv_data = (
        ('First row', 'Foo', 'Bar', 'Baz'),
        ('Second row', 'A', 'B', 'C', '"Testing"', "Here's a quote"),
    )"""
    
  response = HttpResponse(mimetype='text/csv')
  response['Content-Disposition'] = 'attachment; filename=cards.csv'

  t = loader.get_template('csv.txt')
  c = Context({
      'data': tuple(csv_data),
  })
  response.write(t.render(c))
  return response
Example #3
0
def csv(request):
    csv_data = []
    if request.method == 'POST':
        items = request.POST.items()
        pks = filter(lambda (x, y): x.isdigit() and y == 'on', items)
        pks = map(lambda x: x[0], pks)
        cards = Card.objects.filter(pk__in=pks)
        cards = generateFullCardListFromQueryset(cards)

        header = ('front', 'back', 'priority', 'tags', 'sources')
        csv_data.append(header)
        for card in cards:
            csvList = []
            csvList.append(csvEscape(card.card['front']))
            csvList.append(csvEscape(card.card['back']))
            csvList.append("priority " + card.card['priority'])
            tags = csvEscape(', '.join(card.tagList))
            csvList.append(tags)
            sources = csvEscape(', '.join(card.sourceList))
            csvList.append(sources)
            csv_data.append(tuple(csvList))

        # The data is hard-coded here, but you could load it from a database or
        # some other source.
        """csv_data = (
        ('First row', 'Foo', 'Bar', 'Baz'),
        ('Second row', 'A', 'B', 'C', '"Testing"', "Here's a quote"),
    )"""

    response = HttpResponse(mimetype='text/csv')
    response['Content-Disposition'] = 'attachment; filename=cards.csv'

    t = loader.get_template('csv.txt')
    c = Context({
        'data': tuple(csv_data),
    })
    response.write(t.render(c))
    return response
Example #4
0
def reviewIncorrectCards(cards, request):
  return render_to_response('test/review.html', {
      'cards': generateFullCardListFromQueryset(cards),
    }, context_instance=RequestContext(request)
  )
Example #5
0
def getDailyCards(settings):
  maxCards = settings.dailyTestMaxItems
  cards = Card.objects.filter(settings=settings, donottest=False, nextTest__lte=datetime.date.today()).order_by('nextTest').only('front', 'back')[:maxCards]
  return generateFullCardListFromQueryset(cards)