We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Suggestions count on stats is wrong
See https://mozilla.locamotion.org/cy/ where it says 1 pending suggestion, but clicking on the link says that there are no results.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pootle/apps/pootle_store/utils.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) Pootle contributors.
4 #
5 # This file is a part of the Pootle project. It is distributed under the GPL3
6 # or later license. See the LICENSE file for a copy of the license and the
7 # AUTHORS file for copyright and authorship information.
8 
9 from collections import OrderedDict
10 
11 from django.conf import settings
12 from django.contrib.auth import get_user_model
13 from django.template import loader
14 from django.utils import timezone
15 
16 from pootle.core.delegate import site
17 from pootle.core.mail import send_mail
18 from pootle.i18n.gettext import ugettext as _
19 from pootle_comment.forms import UnsecuredCommentForm
20 from pootle_statistics.models import (
21     Submission, SubmissionFields, SubmissionTypes)
22 
23 from .constants import FUZZY, TRANSLATED
24 from .models import Suggestion, SuggestionStates
25 
26 
27 User = get_user_model()
28 
29 
30 class SuggestionsReview(object):
31     accept_email_template = 'editor/email/suggestions_accepted_with_comment.txt'
32     accept_email_subject = _(u"Suggestion accepted with comment")
33     reject_email_template = 'editor/email/suggestions_rejected_with_comment.txt'
34     reject_email_subject = _(u"Suggestion rejected with comment")
35 
36     def __init__(self, suggestions=None, reviewer=None):
37         self.suggestions = suggestions
38         self.reviewer = reviewer
39 
40     @property
41     def users_and_suggestions(self):
42         users = {}
43         for suggestion in self.suggestions:
44             users[suggestion.user] = users.get(suggestion.user, [])
45             users[suggestion.user].append(suggestion)
46         return users
47 
48     def add_comments(self, comment):
49         for suggestion in self.suggestions:
50             UnsecuredCommentForm(
51                 suggestion,
52                 dict(comment=comment,
53                      user=self.reviewer)).save()
54 
55     def add(self, unit, translation, user=None, touch=True,
56             similarity=None, mt_similarity=None):
57         """Adds a new suggestion to the unit.
58 
59         :param translation: suggested translation text
60         :param user: user who is making the suggestion. If it's ``None``,
61             the ``system`` user will be used.
62         :param touch: whether to update the unit's timestamp after adding
63             the suggestion or not.
64         :param similarity: human similarity for the new suggestion.
65         :param mt_similarity: MT similarity for the new suggestion.
66 
67         :return: a tuple ``(suggestion, created)`` where ``created`` is a
68             boolean indicating if the suggestion was successfully added.
69             If the suggestion already exists it's returned as well.
70         """
71         dont_add = (
72             not filter(None, translation)
73             or translation == unit.target)
74         if dont_add:
75             return (None, False)
76         user = user or User.objects.get_system_user()
77         try:
78             suggestion = Suggestion.objects.pending().get(
79                 unit=unit,
80                 user=user,
81                 target_f=translation)
82             return (suggestion, False)
83         except Suggestion.DoesNotExist:
84             suggestion = Suggestion.objects.create(
85                 unit=unit,
86                 user=user,
87                 state=SuggestionStates.PENDING,
88                 target=translation,
89                 creation_time=timezone.now())
90             self.create_submission(
91                 suggestion,
92                 SubmissionTypes.SUGG_ADD,
93                 user,
94                 similarity=similarity,
95                 mt_similarity=mt_similarity).save()
96             if touch:
97                 unit.save()
98         return (suggestion, True)
99 
100     def create_submission(self, suggestion, suggestion_type, user, **kwargs):
101         return Submission(
102             creation_time=kwargs.get("creation_time", suggestion.creation_time),
103             translation_project=suggestion.unit.store.translation_project,
104             submitter=user,
105             unit=suggestion.unit,
106             store=suggestion.unit.store,
107             type=suggestion_type,
108             suggestion=suggestion,
109             similarity=kwargs.get("similarity"),
110             mt_similarity=kwargs.get("mt_similarity"))
111 
112     def accept_suggestion(self, suggestion):
113         unit = suggestion.unit
114         translation_project = unit.store.translation_project
115 
116         # Save for later
117         old_state = unit.state
118         old_target = unit.target
119 
120         # Update some basic attributes so we can create submissions. Note
121         # these do not conflict with `ScoreLog`'s interests, so it's safe
122         unit.target = suggestion.target
123         if unit.state == FUZZY:
124             unit.state = TRANSLATED
125 
126         current_time = timezone.now()
127         suggestion.state = SuggestionStates.ACCEPTED
128         suggestion.reviewer = self.reviewer
129         suggestion.review_time = current_time
130         suggestion.save()
131         create_subs = OrderedDict()
132         if old_state != unit.state:
133             create_subs[SubmissionFields.STATE] = [old_state, unit.state]
134         create_subs[SubmissionFields.TARGET] = [old_target, unit.target]
135         subs_created = []
136         for field in create_subs:
137             kwargs = {
138                 'creation_time': current_time,
139                 'translation_project': translation_project,
140                 'submitter': self.reviewer,
141                 'unit': unit,
142                 'store': unit.store,
143                 'field': field,
144                 'type': SubmissionTypes.SUGG_ACCEPT,
145                 'old_value': create_subs[field][0],
146                 'new_value': create_subs[field][1],
147             }
148             if field == SubmissionFields.TARGET:
149                 kwargs['suggestion'] = suggestion
150 
151             subs_created.append(Submission(**kwargs))
152         if subs_created:
153             unit.submission_set.add(*subs_created, bulk=False)
154 
155         # FIXME: remove such a dependency on `ScoreLog`
156         # Update current unit instance's attributes
157         # important to set these attributes after saving Submission
158         # because in the `ScoreLog` we need to access the unit's certain
159         # attributes before it was saved
160         # THIS NEEDS TO GO ^^
161         unit.submitted_by = suggestion.user
162         unit.submitted_on = current_time
163         unit.reviewed_by = self.reviewer
164         unit.reviewed_on = unit.submitted_on
165         unit._log_user = self.reviewer
166         unit.save()
167 
168     def reject_suggestion(self, suggestion):
169         suggestion.state = SuggestionStates.REJECTED
170         suggestion.review_time = timezone.now()
171         suggestion.reviewer = self.reviewer
172         suggestion.save()
173         self.create_submission(
174             suggestion,
175             SubmissionTypes.SUGG_REJECT,
176             self.reviewer,
177             creation_time=suggestion.review_time).save()
178 
179     def accept_suggestions(self):
180         for suggestion in self.suggestions:
181             self.accept_suggestion(suggestion)
182 
183     def accept(self, comment=""):
184         self.accept_suggestions()
185         if self.should_notify(comment):
186             self.notify_suggesters(rejected=False, comment=comment)
187         if comment:
188             self.add_comments(comment=comment)
189 
190     def build_absolute_uri(self, url):
191         return site.get().build_absolute_uri(url)
192 
193     def get_email_message(self, suggestions, comment, template):
194         for suggestion in suggestions:
195             suggestion.unit_url = (
196                 self.build_absolute_uri(
197                     suggestion.unit.get_translate_url()))
198         return loader.render_to_string(
199             template,
200             context=dict(suggestions=suggestions,
201                          comment=comment))
202 
203     def notify_suggesters(self, rejected=True, comment=""):
204         for suggester, suggestions in self.users_and_suggestions.items():
205             if rejected:
206                 template = self.reject_email_template
207                 subject = self.reject_email_subject
208             else:
209                 template = self.accept_email_template
210                 subject = self.accept_email_subject
211             self.send_mail(template, subject, suggester, suggestions, comment)
212 
213     def reject_suggestions(self):
214         for suggestion in self.suggestions:
215             self.reject_suggestion(suggestion)
216 
217     def reject(self, comment=""):
218         self.reject_suggestions()
219         if self.should_notify(comment):
220             self.notify_suggesters(rejected=True, comment=comment)
221         if comment:
222             self.add_comments(comment)
223 
224     def send_mail(self, template, subject, suggester, suggestions, comment):
225         send_mail(
226             subject,
227             self.get_email_message(
228                 suggestions,
229                 comment,
230                 template),
231             from_email=None,
232             recipient_list=[suggester.email],
233             fail_silently=True)
234 
235     def should_notify(self, comment):
236         return (
237             comment
238             and settings.POOTLE_EMAIL_FEEDBACK_ENABLED)
239
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pootle/apps/pootle_store/utils.py b/pootle/apps/pootle_store/utils.py
--- a/pootle/apps/pootle_store/utils.py
+++ b/pootle/apps/pootle_store/utils.py
@@ -15,6 +15,7 @@
 
 from pootle.core.delegate import site
 from pootle.core.mail import send_mail
+from pootle.core.signals import update_data
 from pootle.i18n.gettext import ugettext as _
 from pootle_comment.forms import UnsecuredCommentForm
 from pootle_statistics.models import (
@@ -166,6 +167,7 @@
         unit.save()
 
     def reject_suggestion(self, suggestion):
+        store = suggestion.unit.store
         suggestion.state = SuggestionStates.REJECTED
         suggestion.review_time = timezone.now()
         suggestion.reviewer = self.reviewer
@@ -176,6 +178,8 @@
             self.reviewer,
             creation_time=suggestion.review_time).save()
 
+        update_data.send(store.__class__, instance=store)
+
     def accept_suggestions(self):
         for suggestion in self.suggestions:
             self.accept_suggestion(suggestion)

{"golden_diff": "diff --git a/pootle/apps/pootle_store/utils.py b/pootle/apps/pootle_store/utils.py\n--- a/pootle/apps/pootle_store/utils.py\n+++ b/pootle/apps/pootle_store/utils.py\n@@ -15,6 +15,7 @@\n \n from pootle.core.delegate import site\n from pootle.core.mail import send_mail\n+from pootle.core.signals import update_data\n from pootle.i18n.gettext import ugettext as _\n from pootle_comment.forms import UnsecuredCommentForm\n from pootle_statistics.models import (\n@@ -166,6 +167,7 @@\n         unit.save()\n \n     def reject_suggestion(self, suggestion):\n+        store = suggestion.unit.store\n         suggestion.state = SuggestionStates.REJECTED\n         suggestion.review_time = timezone.now()\n         suggestion.reviewer = self.reviewer\n@@ -176,6 +178,8 @@\n             self.reviewer,\n             creation_time=suggestion.review_time).save()\n \n+        update_data.send(store.__class__, instance=store)\n+\n     def accept_suggestions(self):\n         for suggestion in self.suggestions:\n             self.accept_suggestion(suggestion)\n", "issue": "Suggestions count on stats is wrong\nSee https://mozilla.locamotion.org/cy/ where it says 1 pending suggestion, but clicking on the link says that there are no results.\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) Pootle contributors.\n#\n# This file is a part of the Pootle project. It is distributed under the GPL3\n# or later license. See the LICENSE file for a copy of the license and the\n# AUTHORS file for copyright and authorship information.\n\nfrom collections import OrderedDict\n\nfrom django.conf import settings\nfrom django.contrib.auth import get_user_model\nfrom django.template import loader\nfrom django.utils import timezone\n\nfrom pootle.core.delegate import site\nfrom pootle.core.mail import send_mail\nfrom pootle.i18n.gettext import ugettext as _\nfrom pootle_comment.forms import UnsecuredCommentForm\nfrom pootle_statistics.models import (\n    Submission, SubmissionFields, SubmissionTypes)\n\nfrom .constants import FUZZY, TRANSLATED\nfrom .models import Suggestion, SuggestionStates\n\n\nUser = get_user_model()\n\n\nclass SuggestionsReview(object):\n    accept_email_template = 'editor/email/suggestions_accepted_with_comment.txt'\n    accept_email_subject = _(u\"Suggestion accepted with comment\")\n    reject_email_template = 'editor/email/suggestions_rejected_with_comment.txt'\n    reject_email_subject = _(u\"Suggestion rejected with comment\")\n\n    def __init__(self, suggestions=None, reviewer=None):\n        self.suggestions = suggestions\n        self.reviewer = reviewer\n\n    @property\n    def users_and_suggestions(self):\n        users = {}\n        for suggestion in self.suggestions:\n            users[suggestion.user] = users.get(suggestion.user, [])\n            users[suggestion.user].append(suggestion)\n        return users\n\n    def add_comments(self, comment):\n        for suggestion in self.suggestions:\n            UnsecuredCommentForm(\n                suggestion,\n                dict(comment=comment,\n                     user=self.reviewer)).save()\n\n    def add(self, unit, translation, user=None, touch=True,\n            similarity=None, mt_similarity=None):\n        \"\"\"Adds a new suggestion to the unit.\n\n        :param translation: suggested translation text\n        :param user: user who is making the suggestion. If it's ``None``,\n            the ``system`` user will be used.\n        :param touch: whether to update the unit's timestamp after adding\n            the suggestion or not.\n        :param similarity: human similarity for the new suggestion.\n        :param mt_similarity: MT similarity for the new suggestion.\n\n        :return: a tuple ``(suggestion, created)`` where ``created`` is a\n            boolean indicating if the suggestion was successfully added.\n            If the suggestion already exists it's returned as well.\n        \"\"\"\n        dont_add = (\n            not filter(None, translation)\n            or translation == unit.target)\n        if dont_add:\n            return (None, False)\n        user = user or User.objects.get_system_user()\n        try:\n            suggestion = Suggestion.objects.pending().get(\n                unit=unit,\n                user=user,\n                target_f=translation)\n            return (suggestion, False)\n        except Suggestion.DoesNotExist:\n            suggestion = Suggestion.objects.create(\n                unit=unit,\n                user=user,\n                state=SuggestionStates.PENDING,\n                target=translation,\n                creation_time=timezone.now())\n            self.create_submission(\n                suggestion,\n                SubmissionTypes.SUGG_ADD,\n                user,\n                similarity=similarity,\n                mt_similarity=mt_similarity).save()\n            if touch:\n                unit.save()\n        return (suggestion, True)\n\n    def create_submission(self, suggestion, suggestion_type, user, **kwargs):\n        return Submission(\n            creation_time=kwargs.get(\"creation_time\", suggestion.creation_time),\n            translation_project=suggestion.unit.store.translation_project,\n            submitter=user,\n            unit=suggestion.unit,\n            store=suggestion.unit.store,\n            type=suggestion_type,\n            suggestion=suggestion,\n            similarity=kwargs.get(\"similarity\"),\n            mt_similarity=kwargs.get(\"mt_similarity\"))\n\n    def accept_suggestion(self, suggestion):\n        unit = suggestion.unit\n        translation_project = unit.store.translation_project\n\n        # Save for later\n        old_state = unit.state\n        old_target = unit.target\n\n        # Update some basic attributes so we can create submissions. Note\n        # these do not conflict with `ScoreLog`'s interests, so it's safe\n        unit.target = suggestion.target\n        if unit.state == FUZZY:\n            unit.state = TRANSLATED\n\n        current_time = timezone.now()\n        suggestion.state = SuggestionStates.ACCEPTED\n        suggestion.reviewer = self.reviewer\n        suggestion.review_time = current_time\n        suggestion.save()\n        create_subs = OrderedDict()\n        if old_state != unit.state:\n            create_subs[SubmissionFields.STATE] = [old_state, unit.state]\n        create_subs[SubmissionFields.TARGET] = [old_target, unit.target]\n        subs_created = []\n        for field in create_subs:\n            kwargs = {\n                'creation_time': current_time,\n                'translation_project': translation_project,\n                'submitter': self.reviewer,\n                'unit': unit,\n                'store': unit.store,\n                'field': field,\n                'type': SubmissionTypes.SUGG_ACCEPT,\n                'old_value': create_subs[field][0],\n                'new_value': create_subs[field][1],\n            }\n            if field == SubmissionFields.TARGET:\n                kwargs['suggestion'] = suggestion\n\n            subs_created.append(Submission(**kwargs))\n        if subs_created:\n            unit.submission_set.add(*subs_created, bulk=False)\n\n        # FIXME: remove such a dependency on `ScoreLog`\n        # Update current unit instance's attributes\n        # important to set these attributes after saving Submission\n        # because in the `ScoreLog` we need to access the unit's certain\n        # attributes before it was saved\n        # THIS NEEDS TO GO ^^\n        unit.submitted_by = suggestion.user\n        unit.submitted_on = current_time\n        unit.reviewed_by = self.reviewer\n        unit.reviewed_on = unit.submitted_on\n        unit._log_user = self.reviewer\n        unit.save()\n\n    def reject_suggestion(self, suggestion):\n        suggestion.state = SuggestionStates.REJECTED\n        suggestion.review_time = timezone.now()\n        suggestion.reviewer = self.reviewer\n        suggestion.save()\n        self.create_submission(\n            suggestion,\n            SubmissionTypes.SUGG_REJECT,\n            self.reviewer,\n            creation_time=suggestion.review_time).save()\n\n    def accept_suggestions(self):\n        for suggestion in self.suggestions:\n            self.accept_suggestion(suggestion)\n\n    def accept(self, comment=\"\"):\n        self.accept_suggestions()\n        if self.should_notify(comment):\n            self.notify_suggesters(rejected=False, comment=comment)\n        if comment:\n            self.add_comments(comment=comment)\n\n    def build_absolute_uri(self, url):\n        return site.get().build_absolute_uri(url)\n\n    def get_email_message(self, suggestions, comment, template):\n        for suggestion in suggestions:\n            suggestion.unit_url = (\n                self.build_absolute_uri(\n                    suggestion.unit.get_translate_url()))\n        return loader.render_to_string(\n            template,\n            context=dict(suggestions=suggestions,\n                         comment=comment))\n\n    def notify_suggesters(self, rejected=True, comment=\"\"):\n        for suggester, suggestions in self.users_and_suggestions.items():\n            if rejected:\n                template = self.reject_email_template\n                subject = self.reject_email_subject\n            else:\n                template = self.accept_email_template\n                subject = self.accept_email_subject\n            self.send_mail(template, subject, suggester, suggestions, comment)\n\n    def reject_suggestions(self):\n        for suggestion in self.suggestions:\n            self.reject_suggestion(suggestion)\n\n    def reject(self, comment=\"\"):\n        self.reject_suggestions()\n        if self.should_notify(comment):\n            self.notify_suggesters(rejected=True, comment=comment)\n        if comment:\n            self.add_comments(comment)\n\n    def send_mail(self, template, subject, suggester, suggestions, comment):\n        send_mail(\n            subject,\n            self.get_email_message(\n                suggestions,\n                comment,\n                template),\n            from_email=None,\n            recipient_list=[suggester.email],\n            fail_silently=True)\n\n    def should_notify(self, comment):\n        return (\n            comment\n            and settings.POOTLE_EMAIL_FEEDBACK_ENABLED)\n", "path": "pootle/apps/pootle_store/utils.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) Pootle contributors.\n#\n# This file is a part of the Pootle project. It is distributed under the GPL3\n# or later license. See the LICENSE file for a copy of the license and the\n# AUTHORS file for copyright and authorship information.\n\nfrom collections import OrderedDict\n\nfrom django.conf import settings\nfrom django.contrib.auth import get_user_model\nfrom django.template import loader\nfrom django.utils import timezone\n\nfrom pootle.core.delegate import site\nfrom pootle.core.mail import send_mail\nfrom pootle.core.signals import update_data\nfrom pootle.i18n.gettext import ugettext as _\nfrom pootle_comment.forms import UnsecuredCommentForm\nfrom pootle_statistics.models import (\n    Submission, SubmissionFields, SubmissionTypes)\n\nfrom .constants import FUZZY, TRANSLATED\nfrom .models import Suggestion, SuggestionStates\n\n\nUser = get_user_model()\n\n\nclass SuggestionsReview(object):\n    accept_email_template = 'editor/email/suggestions_accepted_with_comment.txt'\n    accept_email_subject = _(u\"Suggestion accepted with comment\")\n    reject_email_template = 'editor/email/suggestions_rejected_with_comment.txt'\n    reject_email_subject = _(u\"Suggestion rejected with comment\")\n\n    def __init__(self, suggestions=None, reviewer=None):\n        self.suggestions = suggestions\n        self.reviewer = reviewer\n\n    @property\n    def users_and_suggestions(self):\n        users = {}\n        for suggestion in self.suggestions:\n            users[suggestion.user] = users.get(suggestion.user, [])\n            users[suggestion.user].append(suggestion)\n        return users\n\n    def add_comments(self, comment):\n        for suggestion in self.suggestions:\n            UnsecuredCommentForm(\n                suggestion,\n                dict(comment=comment,\n                     user=self.reviewer)).save()\n\n    def add(self, unit, translation, user=None, touch=True,\n            similarity=None, mt_similarity=None):\n        \"\"\"Adds a new suggestion to the unit.\n\n        :param translation: suggested translation text\n        :param user: user who is making the suggestion. If it's ``None``,\n            the ``system`` user will be used.\n        :param touch: whether to update the unit's timestamp after adding\n            the suggestion or not.\n        :param similarity: human similarity for the new suggestion.\n        :param mt_similarity: MT similarity for the new suggestion.\n\n        :return: a tuple ``(suggestion, created)`` where ``created`` is a\n            boolean indicating if the suggestion was successfully added.\n            If the suggestion already exists it's returned as well.\n        \"\"\"\n        dont_add = (\n            not filter(None, translation)\n            or translation == unit.target)\n        if dont_add:\n            return (None, False)\n        user = user or User.objects.get_system_user()\n        try:\n            suggestion = Suggestion.objects.pending().get(\n                unit=unit,\n                user=user,\n                target_f=translation)\n            return (suggestion, False)\n        except Suggestion.DoesNotExist:\n            suggestion = Suggestion.objects.create(\n                unit=unit,\n                user=user,\n                state=SuggestionStates.PENDING,\n                target=translation,\n                creation_time=timezone.now())\n            self.create_submission(\n                suggestion,\n                SubmissionTypes.SUGG_ADD,\n                user,\n                similarity=similarity,\n                mt_similarity=mt_similarity).save()\n            if touch:\n                unit.save()\n        return (suggestion, True)\n\n    def create_submission(self, suggestion, suggestion_type, user, **kwargs):\n        return Submission(\n            creation_time=kwargs.get(\"creation_time\", suggestion.creation_time),\n            translation_project=suggestion.unit.store.translation_project,\n            submitter=user,\n            unit=suggestion.unit,\n            store=suggestion.unit.store,\n            type=suggestion_type,\n            suggestion=suggestion,\n            similarity=kwargs.get(\"similarity\"),\n            mt_similarity=kwargs.get(\"mt_similarity\"))\n\n    def accept_suggestion(self, suggestion):\n        unit = suggestion.unit\n        translation_project = unit.store.translation_project\n\n        # Save for later\n        old_state = unit.state\n        old_target = unit.target\n\n        # Update some basic attributes so we can create submissions. Note\n        # these do not conflict with `ScoreLog`'s interests, so it's safe\n        unit.target = suggestion.target\n        if unit.state == FUZZY:\n            unit.state = TRANSLATED\n\n        current_time = timezone.now()\n        suggestion.state = SuggestionStates.ACCEPTED\n        suggestion.reviewer = self.reviewer\n        suggestion.review_time = current_time\n        suggestion.save()\n        create_subs = OrderedDict()\n        if old_state != unit.state:\n            create_subs[SubmissionFields.STATE] = [old_state, unit.state]\n        create_subs[SubmissionFields.TARGET] = [old_target, unit.target]\n        subs_created = []\n        for field in create_subs:\n            kwargs = {\n                'creation_time': current_time,\n                'translation_project': translation_project,\n                'submitter': self.reviewer,\n                'unit': unit,\n                'store': unit.store,\n                'field': field,\n                'type': SubmissionTypes.SUGG_ACCEPT,\n                'old_value': create_subs[field][0],\n                'new_value': create_subs[field][1],\n            }\n            if field == SubmissionFields.TARGET:\n                kwargs['suggestion'] = suggestion\n\n            subs_created.append(Submission(**kwargs))\n        if subs_created:\n            unit.submission_set.add(*subs_created, bulk=False)\n\n        # FIXME: remove such a dependency on `ScoreLog`\n        # Update current unit instance's attributes\n        # important to set these attributes after saving Submission\n        # because in the `ScoreLog` we need to access the unit's certain\n        # attributes before it was saved\n        # THIS NEEDS TO GO ^^\n        unit.submitted_by = suggestion.user\n        unit.submitted_on = current_time\n        unit.reviewed_by = self.reviewer\n        unit.reviewed_on = unit.submitted_on\n        unit._log_user = self.reviewer\n        unit.save()\n\n    def reject_suggestion(self, suggestion):\n        store = suggestion.unit.store\n        suggestion.state = SuggestionStates.REJECTED\n        suggestion.review_time = timezone.now()\n        suggestion.reviewer = self.reviewer\n        suggestion.save()\n        self.create_submission(\n            suggestion,\n            SubmissionTypes.SUGG_REJECT,\n            self.reviewer,\n            creation_time=suggestion.review_time).save()\n\n        update_data.send(store.__class__, instance=store)\n\n    def accept_suggestions(self):\n        for suggestion in self.suggestions:\n            self.accept_suggestion(suggestion)\n\n    def accept(self, comment=\"\"):\n        self.accept_suggestions()\n        if self.should_notify(comment):\n            self.notify_suggesters(rejected=False, comment=comment)\n        if comment:\n            self.add_comments(comment=comment)\n\n    def build_absolute_uri(self, url):\n        return site.get().build_absolute_uri(url)\n\n    def get_email_message(self, suggestions, comment, template):\n        for suggestion in suggestions:\n            suggestion.unit_url = (\n                self.build_absolute_uri(\n                    suggestion.unit.get_translate_url()))\n        return loader.render_to_string(\n            template,\n            context=dict(suggestions=suggestions,\n                         comment=comment))\n\n    def notify_suggesters(self, rejected=True, comment=\"\"):\n        for suggester, suggestions in self.users_and_suggestions.items():\n            if rejected:\n                template = self.reject_email_template\n                subject = self.reject_email_subject\n            else:\n                template = self.accept_email_template\n                subject = self.accept_email_subject\n            self.send_mail(template, subject, suggester, suggestions, comment)\n\n    def reject_suggestions(self):\n        for suggestion in self.suggestions:\n            self.reject_suggestion(suggestion)\n\n    def reject(self, comment=\"\"):\n        self.reject_suggestions()\n        if self.should_notify(comment):\n            self.notify_suggesters(rejected=True, comment=comment)\n        if comment:\n            self.add_comments(comment)\n\n    def send_mail(self, template, subject, suggester, suggestions, comment):\n        send_mail(\n            subject,\n            self.get_email_message(\n                suggestions,\n                comment,\n                template),\n            from_email=None,\n            recipient_list=[suggester.email],\n            fail_silently=True)\n\n    def should_notify(self, comment):\n        return (\n            comment\n            and settings.POOTLE_EMAIL_FEEDBACK_ENABLED)\n", "path": "pootle/apps/pootle_store/utils.py"}]}