예제 #1
0
 def _recent_threads_cache_rebuild(self):
     begin_date, end_date = self.get_recent_dates()
     cache_key = "MailingList:%s:recent_threads" % self.name
     cache.delete(cache_key)
     cache.delete("%s_count" % cache_key)
     # don't warm up the cache in batch mode (mass import)
     if not getattr(settings, "HYPERKITTY_BATCH_MODE", False):
         thread_ids = list(self.get_threads_between(
             begin_date, end_date).values_list("id", flat=True))
         cache.set(cache_key, thread_ids, 3600 * 12)  # 12 hours
         cache.set("%s_count" % cache_key, len(thread_ids), 3600 * 12)
예제 #2
0
 def test_overview_cleaned_cache(self):
     # Test the overview page with a clean cache (different code path for
     # MailingList.recent_threads)
     cache.delete("MailingList:[email protected]:recent_threads")
     response = self.client.get(
         reverse('hk_list_overview', args=["*****@*****.**"]))
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.context["view_name"], "overview")
     self.assertEqual(len(response.context["top_threads"]), 1)
     self.assertEqual(len(response.context["most_active_threads"]), 1)
     self.assertEqual(len(response.context["pop_threads"]), 0)
예제 #3
0
 def _refresh_count_cache(self):
     cache.delete("Thread:%s:emails_count" % self.thread_id)
     cache.delete("Thread:%s:participants_count" % self.thread_id)
     cache.delete("MailingList:%s:recent_participants_count" %
                  self.mailinglist_id)
     cache.delete(
         make_template_fragment_key("thread_participants",
                                    [self.thread_id]))
     cache.delete("MailingList:%s:p_count_for:%s:%s" %
                  (self.mailinglist_id, self.date.year, self.date.month))
     # don't warm up the cache in batch mode (mass import)
     if not getattr(settings, "HYPERKITTY_BATCH_MODE", False):
         try:
             self.thread.emails_count
             self.thread.participants_count
             self.mailinglist.recent_participants_count
             self.mailinglist.get_participants_count_for_month(
                 self.date.year, self.date.month)
         except (Thread.DoesNotExist, MailingList.DoesNotExist):
             pass  # it's post_delete, those may have been deleted too
예제 #4
0
def subscribe(list_address, user, email=None, display_name=None):
    if email is None:
        email = user.email
    if display_name is None:
        display_name = "%s %s" % (user.first_name, user.last_name)
    client = get_mailman_client()
    rest_list = client.get_list(list_address)
    subscription_policy = rest_list.settings.get("subscription_policy",
                                                 "moderate")
    # Add a flag to return that would tell the user they have been subscribed
    # to the current list.
    subscribed_now = False
    try:
        member = rest_list.get_member(email)
    except ValueError:
        # We don't want to bypass moderation, don't subscribe. Instead
        # raise an error so that it can be caught to show the user
        if subscription_policy in ("moderate", "confirm_then_moderate"):
            raise ModeratedListException(
                "This list is moderated, please subscribe"
                " to it before posting.")

        # not subscribed yet, subscribe the user without email delivery
        member = rest_list.subscribe(email,
                                     display_name,
                                     pre_verified=True,
                                     pre_confirmed=True)
        # The result can be a Member object or a dict if the subscription can't
        # be done directly, or if it's pending, or something else.
        # Broken API :-(
        if isinstance(member, dict):
            logger.info("Subscription for %s to %s is pending", email,
                        list_address)
            return subscribed_now
        member.preferences["delivery_status"] = "by_user"
        member.preferences.save()
        subscribed_now = True
        cache.delete("User:%s:subscriptions" % user.id, version=2)
        logger.info("Subscribing %s to %s on first post", email, list_address)

    return subscribed_now
예제 #5
0
 def execute(self):
     for mlist in MailingList.objects.all():
         cache.delete("MailingList:%s:top_posters" % mlist.name)
         mlist.top_posters
예제 #6
0
 def _clean_cache(self):
     """Delete cached vote values for Email and Thread instance"""
     cache.delete("Thread:%s:votes" % self.email.thread_id)
     # re-populate the cache?
     cache.delete("Email:%s:votes" % self.email_id)
예제 #7
0
 def execute(self):
     for mlist in MailingList.objects.all():
         cache_key = "MailingList:%s:recent_threads" % mlist.name
         cache.delete(cache_key)
         mlist.recent_threads