コード例 #1
0
ファイル: admin.py プロジェクト: logansryche/ferrox
    def ip(self):
        """Shows a list of recently-used IPs."""

        page = int(request.params.get('page', 0))
        c.ips = model.Session.query(model.IPLogEntry)
        c.ips = c.ips.order_by(model.IPLogEntry.end_time.desc())
        number_of_ips = c.ips.count()
        pageno = int(request.params.get('page', 1)) - 1
        perpage = int(request.params.get('perpage', None) or \
                      pylons.config.get('admin.ip_default_perpage', 12))
        c.paging_links = pagination.populate_paging_links(
            pageno=pageno,
            num_pages=int((number_of_ips + 0.5) // perpage),
            perpage=perpage,
            radius=int(pylons.config.get('paging.radius', 3)))
        c.ips = c.ips.limit(perpage).offset(perpage * page)

        return render('/admin/ip.mako')
コード例 #2
0
ファイル: admin.py プロジェクト: NetShepsky/Ferrox
    def ip(self):
        """Shows a list of recently-used IPs."""

        page = int(request.params.get('page', 0))
        c.ips = model.Session.query(model.IPLogEntry)
        c.ips = c.ips.order_by(model.IPLogEntry.end_time.desc())
        number_of_ips = c.ips.count()
        pageno = int(request.params.get('page', 1)) - 1
        perpage = int(request.params.get('perpage', None) or \
                      pylons.config.get('admin.ip_default_perpage', 12))
        c.paging_links = pagination.populate_paging_links(
            pageno = pageno,
            num_pages = int((number_of_ips + 0.5) // perpage),
            perpage = perpage,
            radius = int(pylons.config.get('paging.radius', 3))
        )
        c.ips = c.ips.limit(perpage).offset(perpage * page)
        
        return render('/admin/ip.mako')
コード例 #3
0
ファイル: journal.py プロジェクト: NetShepsky/Ferrox
    def index(self, username=None, month=None, year=None, day=None, watchstream=False):
        """Journal index for a user."""
        if username:
            user_q = model.Session.query(model.User)
            try:
                c.page_owner = user_q.filter_by(username = username).one()
            except sqlalchemy.exceptions.InvalidRequestError:
                c.error_text = "User %s not found." % h.html_escape(username)
                c.error_title = 'User not found'
                abort(404)
        else:
            c.page_owner = None

        c.page_link_dict = dict(controller='journal', action='index')
        if c.page_owner:
            c.page_link_dict['username'] = c.page_owner.username
        if year and month and day:
            today = earliest = date(int(year), int(month), int(day))
            latest = earliest + timedelta(days=1)
            c.page_link_dict.update({'year':year, 'month':month, 'day':day})
        elif month and year:
            today = earliest = date(int(year), int(month), 1)
            latest = date(earliest.year + (earliest.month / 12), (earliest.month + 1) % 12, 1)
            c.page_link_dict.update({'year':year, 'month':month})
        elif year:
            today = earliest = date(int(year), 1, 1)
            latest = date(earliest.year+1, earliest.month, earliest.day)
            c.page_link_dict.update({'year':year})
        else:
            today = latest = (date.today()+timedelta(days=1))
            earliest = date(1970,1,1)
            
        max_per_page = int(pylons.config.get('journal.default_perpage',20))
        pageno = int(request.params.get('page',1)) - 1
        
        journal_q = model.Session.query(model.JournalEntry) \
                         .filter_by(status = 'normal') \
                         .filter(model.JournalEntry.time >= earliest) \
                         .filter(model.JournalEntry.time < latest)
        if c.page_owner and not watchstream:
            journal_q = journal_q.filter_by(user_id = c.page_owner.id)


        #   ... grab c.page_owner's relationships and add them to the where clause
        if watchstream:
            watchstream_where = []
            for r in c.page_owner.relationships:
                if 'watching_journals' in r.relationship:
                    watchstream_where.append(model.UserSubmission.user_id == r.to_user_id)
            if watchstream_where:
                journal_q = journal_q.filter(or_(*watchstream_where))
            else:
                # This means that c.page_owner isn't watching anyone.
                # We don't even need to bother querying.
                c.error_text = 'No journals found.'
                c.error_title = "No journals found. User '%s' isn't watching anyone."%c.page_owner.display_name
                return render('/error.mako')

        journal_q = journal_q.order_by(model.JournalEntry.time.desc())
        c.journals = journal_q.limit(max_per_page).offset(pageno * max_per_page).all()
        num_journals = journal_q.count()
        
        c.title_only = False
        c.is_mine = c.page_owner and (c.auth_user and (c.page_owner.id == c.auth_user.id))
        
        paging_radius = int(pylons.config.get('paging.radius',3))
        c.paging_links = pagination.populate_paging_links(pageno=pageno, num_pages=int(math.ceil(float(num_journals)/float(max_per_page))), perpage=max_per_page, radius=paging_radius)

        c.form = FormGenerator()
        
        c.by_date_base = dict(controller='journal', action='index')
        if c.page_owner:
            c.by_date_base['username'] = c.page_owner.username
        
        c.next_year = c.by_date_base.copy()
        c.next_year['year'] = today.year + 1
        
        c.last_year = c.by_date_base.copy()
        c.last_year['year'] = today.year - 1
        
        c.next_month = c.by_date_base.copy()
        c.next_month['month'] = today.month + 1
        c.next_month['year'] = today.year
        if c.next_month['month'] > 12:
            c.next_month['month'] -= 12
            c.next_month['year'] += 1
        
        c.last_month = c.by_date_base.copy()
        c.last_month['month'] = today.month - 1
        c.last_month['year'] = today.year
        if c.last_month['month'] < 1:
            c.last_month['month'] += 12
            c.last_month['year'] -= 1
        
        c.tomorrow = c.by_date_base.copy()
        tomorrow = today + timedelta(days=1)
        c.tomorrow['year'] = tomorrow.year
        c.tomorrow['month'] = tomorrow.month
        c.tomorrow['day'] = tomorrow.day
        
        c.yesterday = c.by_date_base.copy()
        yesterday = today - timedelta(days=1)
        c.yesterday['year'] = yesterday.year
        c.yesterday['month'] = yesterday.month
        c.yesterday['day'] = yesterday.day
        
        c.year, c.month, c.day = year, month, day
        c.today = date.today()
        
        if month and year:
            c.days_this_month = max([x for x in calendar.Calendar().itermonthdays(int(year),int(month))])
            
        return render('/journal/index.mako')
コード例 #4
0
    def index(self,
              username=None,
              month=None,
              year=None,
              day=None,
              watchstream=False):
        """Journal index for a user."""
        if username:
            user_q = model.Session.query(model.User)
            try:
                c.page_owner = user_q.filter_by(username=username).one()
            except sqlalchemy.exceptions.InvalidRequestError:
                c.error_text = "User %s not found." % h.html_escape(username)
                c.error_title = 'User not found'
                abort(404)
        else:
            c.page_owner = None

        c.page_link_dict = dict(controller='journal', action='index')
        if c.page_owner:
            c.page_link_dict['username'] = c.page_owner.username
        if year and month and day:
            today = earliest = date(int(year), int(month), int(day))
            latest = earliest + timedelta(days=1)
            c.page_link_dict.update({'year': year, 'month': month, 'day': day})
        elif month and year:
            today = earliest = date(int(year), int(month), 1)
            latest = date(earliest.year + (earliest.month / 12),
                          (earliest.month + 1) % 12, 1)
            c.page_link_dict.update({'year': year, 'month': month})
        elif year:
            today = earliest = date(int(year), 1, 1)
            latest = date(earliest.year + 1, earliest.month, earliest.day)
            c.page_link_dict.update({'year': year})
        else:
            today = latest = (date.today() + timedelta(days=1))
            earliest = date(1970, 1, 1)

        max_per_page = int(pylons.config.get('journal.default_perpage', 20))
        pageno = int(request.params.get('page', 1)) - 1

        journal_q = model.Session.query(model.JournalEntry) \
                         .filter_by(status = 'normal') \
                         .filter(model.JournalEntry.time >= earliest) \
                         .filter(model.JournalEntry.time < latest)
        if c.page_owner and not watchstream:
            journal_q = journal_q.filter_by(user_id=c.page_owner.id)

        #   ... grab c.page_owner's relationships and add them to the where clause
        if watchstream:
            watchstream_where = []
            for r in c.page_owner.relationships:
                if 'watching_journals' in r.relationship:
                    watchstream_where.append(
                        model.UserSubmission.user_id == r.to_user_id)
            if watchstream_where:
                journal_q = journal_q.filter(or_(*watchstream_where))
            else:
                # This means that c.page_owner isn't watching anyone.
                # We don't even need to bother querying.
                c.error_text = 'No journals found.'
                c.error_title = "No journals found. User '%s' isn't watching anyone." % c.page_owner.display_name
                return render('/error.mako')

        journal_q = journal_q.order_by(model.JournalEntry.time.desc())
        c.journals = journal_q.limit(max_per_page).offset(pageno *
                                                          max_per_page).all()
        num_journals = journal_q.count()

        c.title_only = False
        c.is_mine = c.page_owner and (c.auth_user and
                                      (c.page_owner.id == c.auth_user.id))

        paging_radius = int(pylons.config.get('paging.radius', 3))
        c.paging_links = pagination.populate_paging_links(
            pageno=pageno,
            num_pages=int(math.ceil(float(num_journals) /
                                    float(max_per_page))),
            perpage=max_per_page,
            radius=paging_radius)

        c.form = FormGenerator()

        c.by_date_base = dict(controller='journal', action='index')
        if c.page_owner:
            c.by_date_base['username'] = c.page_owner.username

        c.next_year = c.by_date_base.copy()
        c.next_year['year'] = today.year + 1

        c.last_year = c.by_date_base.copy()
        c.last_year['year'] = today.year - 1

        c.next_month = c.by_date_base.copy()
        c.next_month['month'] = today.month + 1
        c.next_month['year'] = today.year
        if c.next_month['month'] > 12:
            c.next_month['month'] -= 12
            c.next_month['year'] += 1

        c.last_month = c.by_date_base.copy()
        c.last_month['month'] = today.month - 1
        c.last_month['year'] = today.year
        if c.last_month['month'] < 1:
            c.last_month['month'] += 12
            c.last_month['year'] -= 1

        c.tomorrow = c.by_date_base.copy()
        tomorrow = today + timedelta(days=1)
        c.tomorrow['year'] = tomorrow.year
        c.tomorrow['month'] = tomorrow.month
        c.tomorrow['day'] = tomorrow.day

        c.yesterday = c.by_date_base.copy()
        yesterday = today - timedelta(days=1)
        c.yesterday['year'] = yesterday.year
        c.yesterday['month'] = yesterday.month
        c.yesterday['day'] = yesterday.day

        c.year, c.month, c.day = year, month, day
        c.today = date.today()

        if month and year:
            c.days_this_month = max([
                x for x in calendar.Calendar().itermonthdays(
                    int(year), int(month))
            ])

        return render('/journal/index.mako')
コード例 #5
0
ファイル: gallery.py プロジェクト: logansryche/ferrox
                page_num=pageno,
                page_size=perpage,
            )
        except NoSuchTagsException, e:
            c.form.errors['tags'] = 'No such tags: ' + ', '.join(e.tags)
            return render('gallery/index.mako')

        # Preliminaries
        c.javascripts.append('gallery')

        # Pagination links
        # XXX sqlite or otherwise no number of pages?
        num_pages = int((submission_ct + 0.5) // perpage)
        paging_radius = int(pylons.config.get('paging.radius', 3))
        c.paging_links = pagination.populate_paging_links(pageno=pageno,
                                                          num_pages=num_pages,
                                                          perpage=perpage,
                                                          radius=paging_radius)

        return render('/gallery/index.mako')

    @check_perm('gallery.view')
    def index(self, username=None):
        """Gallery index, either globally or for one user."""
        if username:
            c.page_owner = model.User.get_by_name(username)
        else:
            c.page_owner = None

        if c.page_owner:
            joined_tables = model.Submission.__table__ \
                            .join(model.UserSubmission.__table__) \
コード例 #6
0
ファイル: gallery.py プロジェクト: NetShepsky/Ferrox
                page_size=perpage,
            )
        except NoSuchTagsException, e:
            c.form.errors['tags'] = 'No such tags: ' + ', '.join(e.tags)
            return render('gallery/index.mako')

        # Preliminaries
        c.javascripts.append('gallery')

        # Pagination links
        # XXX sqlite or otherwise no number of pages?
        num_pages = int((submission_ct + 0.5) // perpage)
        paging_radius = int(pylons.config.get('paging.radius', 3))
        c.paging_links = pagination.populate_paging_links(pageno=pageno,
                                                          num_pages=num_pages,
                                                          perpage=perpage,
                                                          radius=paging_radius
                                                          )

        return render('/gallery/index.mako')

    @check_perm('gallery.view')
    def index(self, username=None):
        """Gallery index, either globally or for one user."""
        if username:
            c.page_owner = model.User.get_by_name(username)
        else:
            c.page_owner = None

        if c.page_owner:
            joined_tables = model.Submission.__table__ \
コード例 #7
0
class UserController(BaseController):
    def ajax_tooltip(self, username=None):
        """Returns HTML fragment for the user tooltip."""

        c.user = model.User.get_by_name(username)
        if not c.user:
            abort(404)

        # Relationships
        if c.auth_user:
            c.is_friend = c.auth_user.get_relationship(c.user, 'friend_to')
            c.friend_of = c.user.get_relationship(c.auth_user, 'friend_to')

            c.blocking = c.auth_user.get_relationship(c.user, 'blocking')
            c.blocked_by = c.user.get_relationship(c.auth_user, 'blocking')

        return render('user/ajax_tooltip.mako')

    def view(self, username=None, sub_domain=None):
        """Default view for a user; shows eir recent activity and some simple
        stats/info.
        """
        c.user = model.User.get_by_name(username)
        if not c.user:
            abort(404)

        # Recent submissions
        joined_tables = model.Submission.__table__ \
                        .join(model.UserSubmission.__table__) \
                        .join(model.User.__table__)
        where = [model.User.id == c.user.id]
        (c.recent_submissions,
         submission_ct) = find_submissions(joined_tables=joined_tables,
                                           where_clauses=where,
                                           page_size=10)

        c.recent_journals = model.Session.query(model.JournalEntry) \
                            .filter_by(status='normal') \
                            .filter_by(user_id=c.user.id) \
                            .order_by(model.JournalEntry.time.desc()) \
                            .limit(10) \
                            .all()
        return render('user/view.mako')

    def profile(self, username=None, sub_domain=None):
        """View a user's profile in painful detail."""
        c.user = model.User.get_by_name(username)
        if not c.user:
            abort(404)
        return render('user/profile.mako')

    # XXX: friendof?  construct hashes from this instead?
    def relationships(self, username=None, sub_domain=None, other_user=None):
        """Show user's relationships"""
        c.user = model.User.get_by_name(username)
        c.other_user = model.User.get_by_name(other_user)
        fetch_relationships(c.other_user)

        return render('user/relationships.mako')

    def stats(self, username):
        return render('/PLACEHOLDER.mako')

    def commissions(self, username):
        return render('/PLACEHOLDER.mako')

    def f**k(self, username=None, sub_domain=None):
        if username == c.auth_user.username:
            c.error_title = '''You have attempted to f**k yourself.'''
            c.error_text = 'You have either attempted to f**k yourself, or have been given the suggestion to do so. Congratulations. <br/><br/> &hearts; net-cat'
            return render('/error.mako')

        abort(404)

    def memberlist(self, pageno=1):
        validator = model.form.MemberListPagingForm()
        try:
            form_data = validator.to_python(request.params)
        except formencode.Invalid, error:
            return error

        q = model.Session.query(model.User)
        num_users = q.count()

        q = q.order_by(model.User.__table__.c.username)

        pageno = (form_data['page'] if form_data['page'] else 1) - 1
        perpage = form_data['perpage'] if form_data['perpage'] else int(
            pylons.config.get('userlist.default_perpage', 12))
        c.paging_links = pagination.populate_paging_links(
            pageno=pageno,
            num_pages=int(math.ceil(float(num_users) / float(perpage))),
            perpage=perpage,
            radius=int(pylons.config.get('paging.radius', 3)))

        q = q.limit(perpage).offset(perpage * pageno)
        c.users = q.all()

        return render('/user/memberlist.mako')