return self.backend.db.fetch_one(stmt)
+ def get_sources_by_domain(self, name):
+ """
+ Returns all sources that list the given domain
+ """
+ stmt = (
+ sqlmodel
+ .select(
+ sources.Source,
+ )
+ .select_from(
+ domains.Domain,
+ )
+ .join(
+ sources.Source,
+ sources.Source.id == domains.Domain.source_id,
+ )
+ .where(
+ # The domain must be on this list
+ domains.Domain.list == self,
+
+ # The name must match
+ domains.Domain.name == name,
+
+ # The domain cannot be removed
+ domains.Domain.removed_at == None,
+
+ # The domain must come from a source
+ domains.Domain.source_id != None,
+ )
+ )
+
+ return self.backend.db.fetch_as_set(stmt)
+
# Total Domains
total_domains : int = 0
# Close!
- def close(self, closed_by=None, accept=True):
+ def close(self, closed_by=None, accept=True, update_stats=True):
"""
Called when a moderator has made a decision
"""
# Log action
log.info("Report %s has been closed by %s" % (self, self.closed_by))
+
+ # Update list stats
+ if update_stats:
+ # Update stats for all sources that list this domain
+ for source in self.list.get_sources_by_domain(self.name):
+ source.update_stats()
+
+ # Update the list's stats
+ self.list.update_stats()