예제 #1
0
def subs_contribs(sr_name='betateam'):
    """Convert all subscribers of a given subreddit to
       contributors. Useful for forming opt-in beta teams"""
    from r2.models import Subreddit, SRMember

    sr = Subreddit._by_name(sr_name)
    q = SRMember._query(SRMember.c._thing1_id == sr._id)

    for rel in rels:
        if rel._name == 'subscriber':
            sr.add_contributor(rel._thing2)
예제 #2
0
파일: cmd_utils.py 프로젝트: 1900/reddit
def subs_contribs(sr_name = 'betateam'):
    """Convert all subscribers of a given subreddit to
       contributors. Useful for forming opt-in beta teams"""
    from r2.models import Subreddit, SRMember

    sr = Subreddit._by_name(sr_name)
    q = SRMember._query(SRMember.c._thing1_id == sr._id)

    for rel in rels:
        if rel._name == 'subscriber':
            sr.add_contributor(rel._thing2)
예제 #3
0
    def get_reports(cls, wrapped, max_user_reasons=20):
        """Get two lists of mod and user reports on the item."""
        if (wrapped.reported > 0 and
                (wrapped.can_ban or
                 getattr(wrapped, "promoted", None) and c.user_is_sponsor)):
            from r2.models import SRMember

            reports = cls.for_thing(wrapped.lookups[0])

            q = SRMember._simple_query(
                ["_thing2_id", "_date"],
                SRMember.c._thing1_id == wrapped.sr_id,
                SRMember.c._name == "moderator",
            )
            mod_dates = {rel._thing2_id: rel._date for rel in q}

            if g.automoderator_account:
                automoderator = Account._by_name(g.automoderator_account)
            else:
                automoderator = None

            mod_reports = []
            user_reports = []

            for report in reports:
                # always include AutoModerator reports
                if automoderator and report._thing1_id == automoderator._id:
                    mod_reports.append(report)
                # include in mod reports if made after the user became a mod
                elif (report._thing1_id in mod_dates and
                        report._date >= mod_dates[report._thing1_id]):
                    mod_reports.append(report)
                else:
                    user_reports.append(report)

            # mod reports return as tuples with (reason, name)
            mods = Account._byID([report._thing1_id
                                  for report in mod_reports],
                                 data=True, return_dict=True)
            mod_reports = [(getattr(report, "reason", None),
                            mods[report._thing1_id].name)
                            for report in mod_reports]

            # user reports return as tuples with (reason, count)
            user_reports = Counter([getattr(report, "reason", None)
                                    for report in user_reports])
            user_reports = user_reports.most_common(max_user_reasons)

            return mod_reports, user_reports
        else:
            return [], []
예제 #4
0
파일: report.py 프로젝트: annerajb/reddit
    def get_reports(cls, wrapped, max_user_reasons=20):
        """Get two lists of mod and user reports on the item."""
        if wrapped.can_ban and wrapped.reported > 0:
            from r2.models import SRMember

            reports = cls.for_thing(wrapped.lookups[0])

            query = SRMember._query(SRMember.c._thing1_id == wrapped.sr_id,
                                    SRMember.c._name == "moderator")
            mod_dates = {rel._thing2_id: rel._date for rel in query}

            mod_reports = []
            user_reports = []

            for report in reports:
                # include in mod reports if made after the user became a mod
                if (report._thing1_id in mod_dates and
                        report._date >= mod_dates[report._thing1_id]):
                    mod_reports.append(report)
                else:
                    user_reports.append(report)

            # mod reports return as tuples with (reason, name)
            mods = Account._byID([report._thing1_id
                                  for report in mod_reports],
                                 data=True, return_dict=True)
            mod_reports = [(getattr(report, "reason", None),
                            mods[report._thing1_id].name)
                            for report in mod_reports]

            # user reports return as tuples with (reason, count)
            user_reports = Counter([getattr(report, "reason", None)
                                    for report in user_reports])
            user_reports = user_reports.most_common(max_user_reasons)

            return mod_reports, user_reports
        else:
            return [], []