示例#1
0
文件: dashboard.py 项目: poszu/gedgo
def dashboard(request):
    if not request.user.is_superuser:
        raise Http404

    form = None
    if request.POST and request.GET.get('reset_tracking'):
        _reset_tracking()
        return redirect('/gedgo/dashboard/')
    elif request.POST:
        form = UpdateForm(request.POST, request.FILES)
        _handle_upload(request, form)
        return redirect('/gedgo/dashboard/')

    if form is None:
        form = UpdateForm()

    # Collect tracking stats from redis storage
    tracking_start, user_views, total = _page_view_stats()

    # Render list page with the documents and the form
    return render(
        request, 'dashboard.html', {
            'form': form,
            'tracking_start': tracking_start,
            'users': User.objects.filter(email__contains='@').iterator(),
            'user_views': user_views,
            'total': total,
            'gedcoms': Gedcom.objects.iterator()
        })
示例#2
0
def _people(request):
    g = Gedcom.objects.first()
    context = {
        'people': Person.objects.none(),
        'gedcom': g,
        'posts': BlogPost.objects.none()
    }

    if 'q' in request.GET and request.GET['q']:
        q = request.GET['q']

        # Throw away non-word characters.
        terms = TERMS_RE.findall(q)

        people = Person.objects.all()
        for term in terms:
            people &= Person.objects.filter(
                Q(last_name__icontains=term) | Q(first_name__icontains=term)
                | Q(suffix__icontains=term))
            people = people.order_by('-pointer')

        # If there's only a single person, just go directly to the details view
        if people.count() == 1:
            person = people.first()
            return redirect('/gedgo/%d/%s' %
                            (person.gedcom.id, person.pointer))

        context['people'] = people
        context['query'] = q
    return render(request, 'search_results.html', context)
示例#3
0
def blog(request, year, month):
    "Blog front page - listing posts by creation date."
    posts = BlogPost.objects.all().order_by("-created")

    if year:
        posts = posts.filter(created__year=year)
    if month:
        posts = posts.filter(created__month=month)

    paginator = Paginator(posts, 2)

    try:
        page = int(request.GET.get("page", '1'))
    except ValueError:
        page = 1

    try:
        posts = paginator.page(page)
    except (InvalidPage, EmptyPage):
        posts = paginator.page(paginator.num_pages)

    months = set(
        (d.year, d.month, datetime(2012, d.month, 1).strftime('%B'))
        for d in BlogPost.objects.values_list('created', flat=True))

    return render(
        request,
        "blogpost_list.html",
        {'posts': posts, 'months': months},
    )
示例#4
0
文件: dashboard.py 项目: gthole/gedgo
def dashboard(request):
    if not request.user.is_superuser:
        raise Http404

    form = None
    if request.POST and request.GET.get('reset_tracking'):
        _reset_tracking()
        return redirect('/gedgo/dashboard/')
    elif request.POST:
        form = UpdateForm(request.POST, request.FILES)
        _handle_upload(request, form)
        return redirect('/gedgo/dashboard/')

    if form is None:
        form = UpdateForm()

    # Collect tracking stats from redis storage
    tracking_start, user_views, total = _page_view_stats()

    # Render list page with the documents and the form
    return render(
        request,
        'dashboard.html',
        {
            'form': form,
            'tracking_start': tracking_start,
            'users': User.objects.filter(email__contains='@').iterator(),
            'user_views': user_views,
            'total': total,
            'gedcoms': Gedcom.objects.iterator()
        }
    )
示例#5
0
def documentary_by_id(request, title):
    documentary = get_object_or_404(Documentary, title=title)

    return render(
        request, "documentary_by_id.html", {
            'documentary': documentary,
            'can_video': documentary.location.lower().endswith('m4v')
        })
示例#6
0
def document(request, doc_id):
    doc = get_object_or_404(Document, id=doc_id)
    context = {
        'doc': doc,
        'file': process_file('', doc.docfile.name, False)
    }

    return render(request, 'document_preview.html', context)
示例#7
0
def documentaries(request):
    documentaries = Documentary.objects.all().order_by('-last_updated')

    return render(
        request,
        "documentaries.html",
        {'documentaries': documentaries}
    )
示例#8
0
def documentary_by_id(request, title):
    documentary = get_object_or_404(Documentary, title=title)

    return render(
        request,
        "documentary_by_id.html",
        {
            'documentary': documentary,
            'can_video': documentary.location.lower().endswith('m4v')
        }
    )
示例#9
0
def _files(request):
    _, files = research_storage.search(request.GET.get('q', ''))
    files = [
        process_file(os.path.dirname(f), os.path.basename(f), False)
        for f in files
    ]
    levels = [('Search: ' + request.GET.get('q', '') + ' ', '')]
    return render(request, 'research.html', {
        'directories': [],
        'files': files,
        'levels': levels
    })
示例#10
0
def gedcom(request, gedcom_id):
    g = get_object_or_404(Gedcom, id=gedcom_id)
    post = BlogPost.objects.all().order_by("-created").first()

    form, redirect = process_comments(request)
    if redirect is not None:
        return redirect

    return render(request, 'gedcom.html', {
        'gedcom': g,
        'post': post,
        'form': form,
        'comment_noun': str(g)
    })
示例#11
0
文件: research.py 项目: gthole/gedgo
def research(request, pathname):
    if storage is None:
        raise Http404

    dirname = pathname.strip('/')
    basename = request.GET.get('fn')

    directories, files = get_dir_contents(dirname, request.GET.get('rq'))
    levels = build_levels(dirname)

    context = {
        'rq': request.GET.get('rq', ''),
        'can_search': hasattr(storage, 'search'),
        'levels': levels,
        'dirname': dirname
    }

    if request.GET.get('fn'):
        try:
            index = [f[len(dirname):] for f in files].index(basename)
        except Exception:
            raise Http404
        next_file = files[(index + 1) % len(files)]
        prev_file = files[(index - 1) % len(files)]

        context['file'] = process_file(dirname, basename, False)
        context['next_file'] = process_file(dirname, next_file, False)
        context['prev_file'] = process_file(dirname, prev_file, False)

        return render(request, 'research_preview.html', context)
    else:
        directories = [process_file(dirname, d, True) for d in directories]
        files = [process_file(dirname, f, False) for f in files]
        context['directories'] = directories
        context['files'] = files

        return render(request, 'research.html', context)
示例#12
0
def research(request, pathname):
    if storage is None:
        raise Http404

    dirname = pathname.strip('/')
    basename = request.GET.get('fn')

    directories, files = get_dir_contents(dirname, request.GET.get('rq'))
    levels = build_levels(dirname)

    context = {
        'rq': request.GET.get('rq', ''),
        'can_search': hasattr(storage, 'search'),
        'levels': levels,
        'dirname': dirname
    }

    if request.GET.get('fn'):
        try:
            index = [f[len(dirname):] for f in files].index(basename)
        except Exception:
            raise Http404
        next_file = files[(index + 1) % len(files)]
        prev_file = files[(index - 1) % len(files)]

        context['file'] = process_file(dirname, basename, False)
        context['next_file'] = process_file(dirname, next_file, False)
        context['prev_file'] = process_file(dirname, prev_file, False)

        return render(request, 'research_preview.html', context)
    else:
        directories = [process_file(dirname, d, True) for d in directories]
        files = [process_file(dirname, f, False) for f in files]
        context['directories'] = directories
        context['files'] = files

        return render(request, 'research.html', context)
示例#13
0
文件: search.py 项目: gthole/gedgo
def _files(request):
    _, files = research_storage.search(request.GET.get('q', ''))
    files = [
        process_file(os.path.dirname(f), os.path.basename(f), False)
        for f in files
    ]
    levels = [('Search: ' + request.GET.get('q', '') + ' ', '')]
    return render(
        request,
        'research.html',
        {
            'directories': [],
            'files': files,
            'levels': levels
        }
    )
示例#14
0
文件: dashboard.py 项目: poszu/gedgo
def user_tracking(request, user_id):
    if not request.user.is_superuser:
        raise Http404

    user = get_object_or_404(User, id=user_id)
    count = redis.keys('gedgo_user_%d_page_view_count' % user.id)
    if not count:
        raise Http404

    views = redis.lrange('gedgo_user_%d_page_views' % user.id, 0, -1)
    views = [_load_page_view(v) for v in views]

    return render(request, 'user_tracking.html', {
        'user': user,
        'count': count,
        'views': views
    })
示例#15
0
def gedcom(request, gedcom_id):
    g = get_object_or_404(Gedcom, id=gedcom_id)
    post = BlogPost.objects.all().order_by("-created").first()

    form, redirect = process_comments(request)
    if redirect is not None:
        return redirect

    return render(
        request,
        'gedcom.html',
        {
            'gedcom': g,
            'post': post,
            'form': form,
            'comment_noun': str(g)
        }
    )
示例#16
0
def person(request, gedcom_id, person_id):
    g = get_object_or_404(Gedcom, id=gedcom_id)
    p = get_object_or_404(Person, gedcom=g, pointer=person_id)

    noun = "%s (%s)" % (p.full_name, p.pointer)
    form, redirect = process_comments(request, noun)
    if redirect is not None:
        return redirect

    context = {
        'person': p,
        'posts': BlogPost.objects.filter(tagged_people=p),
        'gedcom': g,
        'form': form,
        'comment_noun': noun
    }

    return render(request, 'person.html', context)
示例#17
0
def person(request, gedcom_id, person_id):
    g = get_object_or_404(Gedcom, id=gedcom_id)
    p = get_object_or_404(Person, gedcom=g, pointer=person_id)

    form, redirect = process_comments(request)
    if redirect is not None:
        return redirect

    context = {
        'person': p,
        'posts': BlogPost.objects.filter(tagged_people=p),
        'photos': [photo for photo in p.photos
                   if not photo.id == p.key_photo.id],
        'gedcom': g,
        'form': form,
        'comment_noun': str(p)
    }

    return render(request, 'person.html', context)
示例#18
0
def blogpost(request, post_id):
    "Single post."

    noun = "blog post"
    form, redirect = process_comments(request, noun)
    if redirect is not None:
        return redirect

    context = {
        'post': get_object_or_404(BlogPost, id=post_id),
        'form': form,
        'comment_noun': noun
    }

    return render(
        request,
        "blogpost.html",
        context
    )
示例#19
0
def person(request, gedcom_id, person_id):
    g = get_object_or_404(Gedcom, id=gedcom_id)
    p = get_object_or_404(Person, gedcom=g, pointer=person_id)

    form, redirect = process_comments(request)
    if redirect is not None:
        return redirect

    context = {
        'person': p,
        'posts': BlogPost.objects.filter(tagged_people=p),
        'photos':
        [photo for photo in p.photos if not photo.id == p.key_photo.id],
        'gedcom': g,
        'form': form,
        'comment_noun': str(p)
    }

    return render(request, 'person.html', context)
示例#20
0
def search(request):
    g = Gedcom.objects.first()
    context = {
        'people': Person.objects.none(),
        'gedcom': g,
        'posts': BlogPost.objects.none()
    }

    if 'q' in request.GET and request.GET['q']:
        q = request.GET['q']

        # Throw away non-word characters.
        terms = TERMS_RE.findall(q)

        people = Person.objects.all()
        posts = BlogPost.objects.all()
        for term in terms:
            people &= Person.objects.filter(
                Q(last_name__icontains=term) |
                Q(first_name__icontains=term) |
                Q(suffix__icontains=term)
            )
            posts &= BlogPost.objects.filter(
                Q(title__icontains=term) |
                Q(body__icontains=term)
            )
        people = people.order_by('-pointer')

        # If there's only a single person, just go directly to the details view
        if people.count() == 1 and not posts.exists():
            person = people.first()
            return redirect(
                '/gedgo/%d/%s' % (person.gedcom.id, person.pointer)
            )

        context['people'] = people
        context['posts'] = posts
        context['query'] = q
    return render(
        request,
        'search_results.html',
        context
    )
示例#21
0
文件: dashboard.py 项目: gthole/gedgo
def user_tracking(request, user_id):
    if not request.user.is_superuser:
        raise Http404

    user = get_object_or_404(User, id=user_id)
    count = redis.keys('gedgo_user_%d_page_view_count' % user.id)
    if not count:
        raise Http404

    views = redis.lrange('gedgo_user_%d_page_views' % user.id, 0, -1)
    views = [_load_page_view(v) for v in views]

    return render(
        request,
        'user_tracking.html',
        {
            'user': user,
            'count': count,
            'views': views
        }
    )
示例#22
0
def research(request, pathname):
    if storage is None:
        raise Http404

    name = pathname.strip('/')

    # Serve the content through xsendfile or directly.
    try:
        if '.' in name:
            return serve_content(storage, name)
        else:
            directories, files = storage.listdir(name)
            directories = [__process(name, d, True) for d in directories]
            files = [__process(name, f, False) for f in files]

            # Build a depth tree of the directories above this one for
            # navigation
            levels = [('Research Files', '')]
            if name:
                lp = ''
                for l in name.split('/'):
                    lp = '%s/%s' % (lp, l)
                    levels.append((l, lp))

            return render(
                request,
                'research.html',
                {
                    'directories': directories,
                    'files': files,
                    'levels': levels
                }
            )
    except Exception as e:
        raise e
        raise Http404
示例#23
0
def documentaries(request):
    documentaries = Documentary.objects.all().order_by('-last_updated')

    return render(request, "documentaries.html",
                  {'documentaries': documentaries})
示例#24
0
def document(request, doc_id):
    doc = get_object_or_404(Document, id=doc_id)
    context = {'doc': doc, 'file': process_file('', doc.docfile.name, False)}

    return render(request, 'document_preview.html', context)