index.py 4.1 KB
Newer Older
1
2
3
4
# -*- coding: utf-8 -*-
#
#   index.py — index controller
#
Arno Töll's avatar
Arno Töll committed
5
#   This file is part of debexpo - https://alioth.debian.org/projects/debexpo/
6
#
Jonny Lamb's avatar
Jonny Lamb committed
7
#   Copyright © 2008 Jonny Lamb <jonny@debian.org>
8
#   Copyright © 2010 Jan Dittberner <jandd@debian.org>
9
#               2012 Baptiste Mouterde <baptiste.mouterde@gmail.com>
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#   Permission is hereby granted, free of charge, to any person
#   obtaining a copy of this software and associated documentation
#   files (the "Software"), to deal in the Software without
#   restriction, including without limitation the rights to use,
#   copy, modify, merge, publish, distribute, sublicense, and/or sell
#   copies of the Software, and to permit persons to whom the
#   Software is furnished to do so, subject to the following
#   conditions:
#
#   The above copyright notice and this permission notice shall be
#   included in all copies or substantial portions of the Software.
#
#   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
#   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
#   OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
#   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
#   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
#   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
#   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
#   OTHER DEALINGS IN THE SOFTWARE.

"""
Holds the IndexController.
"""

__author__ = 'Jonny Lamb'
36
__copyright__ = 'Copyright © 2008 Jonny Lamb, Copyright © 2010 Jan Dittberner'
37
38
39
40
__license__ = 'MIT'

import logging

41
42
43
from sqlalchemy.sql.expression import desc
from debexpo.controllers.comments import CommentsController
from debexpo.model.package_comments import PackageComment
44
from debexpo.lib.base import BaseController, c, config, render, session
45
from debexpo.lib import constants
Arno Töll's avatar
Arno Töll committed
46
from debexpo.controllers.packages import PackagesController, PackageGroups
47
from webhelpers.html import literal
Arno Töll's avatar
Arno Töll committed
48
49
from datetime import datetime, timedelta
from debexpo.model.package_versions import PackageVersion
50
from debexpo.model.packages import Package
51
52
53
from debexpo.model.users import User

from debexpo.model import meta
54
55
56
57
58
59
60
61

log = logging.getLogger(__name__)

class IndexController(BaseController):
    def index(self):
        pkg_controller = PackagesController()

        c.config = config
62
        # getting comments stuff
63
64
        try:
            c.best_comment = CommentsController.build_comment_render(filter(lambda x: isinstance(x.score, int),
65
            meta.session.query(PackageComment).order_by(PackageComment.score).all())[-1])
66

67
68
69
        except AttributeError:
            # this mean that there is no comments rated
            c.best_comment=None
70
71
        except IndexError :
            c.best_comment=None
72
73
74
75
76
77
        try:
            c.last_comment = CommentsController.build_comment_render(
            meta.session.query(PackageComment).order_by(desc(PackageComment.time)).first())
        except AttributeError:
            #same as upper
            c.last_comment=None
Arno Töll's avatar
Arno Töll committed
78
        c.packages = pkg_controller._get_packages(
79
80
81
            package_version_filter=(PackageVersion.uploaded >= (datetime.today() - timedelta(days=30))),
            package_filter=(Package.needs_sponsor == 1)
        )
82
        c.deltas = pkg_controller._get_timedeltas(c.packages)
Arno Töll's avatar
Arno Töll committed
83
        c.deltas.pop()
84
        return render('/index/index.mako')
85
86
87
88

    def contact(self):
        c.config = config
        return render('/index/contact.mako')
89

90
91
92
93
    def qa(self):
        c.config = config
        return render('/index/qa.mako')

Arno Töll's avatar
Arno Töll committed
94
95
96
97
    def intro_reviewers(self):
        c.config = config
        return render('/index/reviewers.mako')

98
    def intro_maintainers(self):
99
100
        """Return an introduction page for package maintainers"""

101
102
103
104
105
106
107
108
109
        # The template will need to look at the user details.
        if 'user_id' in session:
            log.debug('Getting user object for user_id = "%s"' % session['user_id'])
            self.user = meta.session.query(User).get(session['user_id'])
            c.user = self.user
            c.logged_in = True
        else:
            c.logged_in = False

110
        return render('/index/intro-maintainers.mako')
111