Ejemplo n.º 1
0
def puzzle(request, author, number):
    """Show a puzzle by puzzle number."""
    obj = get_object_or_404(Puzzle, user__username=author, number=number)
    title = 'Crossword #' + number + ' | ' + author + ' | Three Pins'
    description = 'Crossword #' + number + 'by ' + author + ', first published on ' + \
                  get_date_string(obj) + '.'
    return display_puzzle(request, obj, title, description,
                          'puzzle/puzzle.html')
Ejemplo n.º 2
0
def edit(request, author, number):
    """Edit a saved crossword."""
    obj = get_object_or_404(Puzzle, user__username=author, number=number)
    if request.user != obj.user and not request.user.is_staff:
        raise PermissionDenied
    title = 'Edit Crossword #' + number + ' | ' + author + ' | Three Pins'
    description = 'Edit crossword #' + number + 'by ' + author + ', first published on ' + \
                  get_date_string(obj) + '.'
    return display_puzzle(request, obj, title, description, 'puzzle/edit.html')
Ejemplo n.º 3
0
 def test_get_date_string(self):
     """Check that the date string is in the expected format."""
     test_date = datetime(1980,
                          3,
                          4,
                          1,
                          2,
                          3,
                          tzinfo=timezone.get_default_timezone())
     puz = Puzzle.objects.create(user=get_user(), pub_date=test_date)
     self.assertEqual(get_date_string(puz), '04 Mar 1980')
Ejemplo n.º 4
0
def profile(request):
    """Show a list of puzzles belonging to the logged in user."""
    objs = Puzzle.objects.filter(user=request.user).order_by('-number')
    context = {'published': [], 'unpublished': []}
    now = timezone.now()
    for puz in objs.filter(pub_date__gt=now):
        context['unpublished'].append({'number': puz.number})
    for puz in objs.filter(pub_date__lte=now):
        context['published'].append({
            'number': puz.number,
            'date': get_date_string(puz)
        })
    return render(request, 'puzzle/profile.html', context)
Ejemplo n.º 5
0
def users(request):
    """Show a list of users and their puzzles."""
    context = {'user_list': []}
    for user in User.objects.all().order_by('username'):
        objs = Puzzle.objects.filter(
            user=user, pub_date__lte=timezone.now()).order_by('-number')
        if objs:
            puzzle_list = []
            for puz in objs:
                puzzle_list.append({
                    'number': puz.number,
                    'date': get_date_string(puz)
                })
            context['user_list'].append({
                'name': user.username,
                'puzzles': puzzle_list
            })
    return render(request, 'puzzle/users.html', context)