# Buggy code
def add_vote(self, translation, request, positive):
    """
    Adds (or updates) vote for a suggestion.
    """
    vote, created = Vote.objects.get_or_create(
        suggestion=self, user=request.user, defaults={"positive": positive}
    )
    if not created or vote.positive != positive:
        vote.positive = positive
        vote.save()

    # Automatic accepting
    required_votes = translation.subproject.suggestion_autoaccept
    if required_votes and self.get_num_votes() >= required_votes:
        self.accept(translation, request)


# Traceback (TypeError)
Internal Server Error: /translate/sites/xxx/it/
Traceback (most recent call last):
File "/app/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 132, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/app/local/lib/python2.7/site-packages/weblate/trans/views/edit.py", line 529, in translate
translation, request, this_unit_url, next_unit_url,
File "/app/local/lib/python2.7/site-packages/weblate/trans/views/edit.py", line 458, in handle_suggestions
suggestion.add_vote(translation, request, True)
File "/app/local/lib/python2.7/site-packages/weblate/trans/models/unitdata.py", line 160, in add_vote
user=request.user
File "/app/local/lib/python2.7/site-packages/django/db/models/manager.py", line 127, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/app/local/lib/python2.7/site-packages/django/db/models/query.py", line 405, in get_or_create
return self.get(**lookup), False
File "/app/local/lib/python2.7/site-packages/django/db/models/query.py", line 325, in get
clone = self.filter(*args, **kwargs)
File "/app/local/lib/python2.7/site-packages/django/db/models/query.py", line 679, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "/app/local/lib/python2.7/site-packages/django/db/models/query.py", line 697, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "/app/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1309, in add_q
clause, require_inner = self._add_q(where_part, self.used_aliases)
File "/app/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1337, in _add_q
allow_joins=allow_joins, split_subq=split_subq,
File "/app/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1199, in build_filter
lookups, value)
File "/app/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 1756, in get_lookup_constraint
lookup_class(target.get_col(alias, source), val), AND)
File "/app/local/lib/python2.7/site-packages/django/db/models/lookups.py", line 101, in __init__
self.rhs = self.get_prep_lookup()
File "/app/local/lib/python2.7/site-packages/django/db/models/lookups.py", line 139, in get_prep_lookup
return self.lhs.output_field.get_prep_lookup(self.lookup_name, self.rhs)
File "/app/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 727, in get_prep_lookup
return self.get_prep_value(value)
File "/app/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 985, in get_prep_value
return int(value)
TypeError: int() argument must be a string or a number, not 'SimpleLazyObject'


Request repr():
<WSGIRequest
path:/translate/sites/xxx/it/,
GET:<QueryDict: {u'offset': [u'0'], u'sid': [u'5696fda0-c99b-11e5-8e25-0242ac110004']}>,
POST:<QueryDict: {u'upvote': [u'49'], u'csrfmiddlewaretoken': [u'myGUYj1SNPUa6nxDC2lnZpAlyRq4zaAR']}>,

...

'WEBLATE_VERSION:Django': '1.8.3',
'WEBLATE_VERSION:Git': u'2.1.4',
'WEBLATE_VERSION:Mercurial': u'3.1.2',
'WEBLATE_VERSION:Pillow (PIL)': '1.1.7',
'WEBLATE_VERSION:Python': '2.7.9',
'WEBLATE_VERSION:Translate Toolkit': '1.13.0',
'WEBLATE_VERSION:Weblate': '2.5-dev',
'WEBLATE_VERSION:Whoosh': '2.7.0',
'WEBLATE_VERSION:compressor': '1.5',
'WEBLATE_VERSION:dateutil': '2.4.2',
'WEBLATE_VERSION:django-crispy-forms': '1.5.2',
'WEBLATE_VERSION:lxml': u'3.4.0',
'WEBLATE_VERSION:pyLibravatar': u'N/A',
'WEBLATE_VERSION:python-social-auth': '0.2.12',
'WEBLATE_VERSION:pyuca': u'N/A',
'WEBLATE_VERSION:six': '1.8.0',
'wsgi.errors': <open file '<stderr>', mode 'w' at 0x7f7200a6d1e0>,
'wsgi.file_wrapper': <class wsgiref.util.FileWrapper at 0x7f71f9ac4a78>,
'wsgi.input': <socket._fileobject object at 0x7f71f2d79f50>,
'wsgi.multiprocess': False,
'wsgi.multithread': True,
'wsgi.run_once': False,
'wsgi.url_scheme': 'http',
'wsgi.version': (1, 0)}>

# Fixed code
def add_vote(self, translation, request, positive):
    """
    Adds (or updates) vote for a suggestion.
    """
    if not request.user.is_authenticated():
        return

    vote, created = Vote.objects.get_or_create(
        suggestion=self, user=request.user, defaults={"positive": positive}
    )
    if not created or vote.positive != positive:
        vote.positive = positive
        vote.save()

    # Automatic accepting
    required_votes = translation.subproject.suggestion_autoaccept
    if required_votes and self.get_num_votes() >= required_votes:
        self.accept(translation, request)