mirror of https://github.com/zulip/zulip.git
Move update_user_activity to actions.py.
(imported from commit a81669d01e699fbf809a02f91e6007b7f61e5518)
This commit is contained in:
parent
030fbbccad
commit
6a2bf7c4f3
|
@ -7,6 +7,7 @@ from django.db import transaction, IntegrityError
|
|||
from django.conf import settings
|
||||
import simplejson
|
||||
from zephyr.lib.cache import cache_with_key
|
||||
from zephyr.lib.actions import update_user_activity
|
||||
|
||||
from functools import wraps
|
||||
|
||||
|
@ -29,24 +30,6 @@ def asynchronous(method):
|
|||
# I like the all-lowercase name better
|
||||
require_post = require_POST
|
||||
|
||||
@transaction.commit_on_success
|
||||
def update_user_activity(request, user_profile, client):
|
||||
current_time = now()
|
||||
try:
|
||||
(activity, created) = UserActivity.objects.get_or_create(
|
||||
user_profile = user_profile,
|
||||
client = client,
|
||||
query = request.META["PATH_INFO"],
|
||||
defaults={'last_visit': current_time, 'count': 0})
|
||||
except IntegrityError:
|
||||
transaction.commit()
|
||||
activity = UserActivity.objects.get(user_profile = user_profile,
|
||||
client = client,
|
||||
query = request.META["PATH_INFO"])
|
||||
activity.count += 1
|
||||
activity.last_visit = current_time
|
||||
activity.save()
|
||||
|
||||
@cache_with_key(lambda user_profile_id: 'tornado_user_profile:%d' % (user_profile_id,))
|
||||
def get_tornado_user_profile(user_id):
|
||||
return UserProfile.objects.select_related().get(user_id=user_id)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from zephyr.lib.context_managers import lockfile
|
||||
from zephyr.models import Realm, Stream, UserProfile, \
|
||||
from zephyr.models import Realm, Stream, UserProfile, UserActivity, \
|
||||
Subscription, Recipient, Message, UserMessage, \
|
||||
DefaultStream, \
|
||||
MAX_MESSAGE_LENGTH, get_client
|
||||
|
@ -295,3 +295,21 @@ def set_default_streams(realm, stream_names):
|
|||
def add_default_subs(user_profile):
|
||||
for default in DefaultStream.objects.filter(realm=user_profile.realm):
|
||||
do_add_subscription(user_profile, default.stream)
|
||||
|
||||
@transaction.commit_on_success
|
||||
def update_user_activity(request, user_profile, client):
|
||||
current_time = timezone.now()
|
||||
try:
|
||||
(activity, created) = UserActivity.objects.get_or_create(
|
||||
user_profile = user_profile,
|
||||
client = client,
|
||||
query = request.META["PATH_INFO"],
|
||||
defaults={'last_visit': current_time, 'count': 0})
|
||||
except IntegrityError:
|
||||
transaction.commit()
|
||||
activity = UserActivity.objects.get(user_profile = user_profile,
|
||||
client = client,
|
||||
query = request.META["PATH_INFO"])
|
||||
activity.count += 1
|
||||
activity.last_visit = current_time
|
||||
activity.save()
|
||||
|
|
Loading…
Reference in New Issue