Open GoogleCodeExporter opened 9 years ago
sure this would be a nice feature.. especially to display how many/which users
are
currently online or something similar :)
but i'm not sure how to correctly implement this.. because generally it's not a
good
idea to create write statements on every request afaik .. on the other hand it
is
only done for logged in users.. i think.. i would create a new model and not
base it
on CommunityUserProfile .. so there are as few entries as possible.. and you
can add
customized indexes ..
the problem with the django ORM is also that you always have to SELECT an entry
before you can update it .. so maybe it would be good to use direct SQL ?
well .. i guess.. for a first version it would be enough to create a custom
model ..
and make it possible to deactivate the feature.. performance can be improved
once it
works :)
Original comment by herbert....@gmail.com
on 30 Dec 2008 at 7:09
attached is the bare minimum implementation.
some ideas:
- create the LastSeen on registration in the middleware do
filter(user=request.user).update(time=datetime.now()) this should get rid of a
SELECT, right?
- it would probably make sense for the activity to be displayed in the profile
page.
i was thinking of connecting to profile_display from the middleware (this way
the
activity would only be displayed if the middleware is enabled).
as always, feedback welcome :-)
Original comment by redduck...@gmail.com
on 30 Dec 2008 at 11:51
Attachments:
this looks quite good already .. a few ideas from me:
- add a db_index = True to the 'time' so we can use it for sorting
- how about using a middleware process_response which would allow views to
store the
location of the user (request.sph_userlocation = currentcategory).. this way you
could say how many users are currently in a given category ? maybe with a
generic
relation: http://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#id1 ? i
guess it slightly slows down the middleware.. but it would be a nice feature ?
- and as you said.. it would be nice to have it displayed in the user profile
as well
as a list of users which are currently online :)
although .. all those 'last seen' probably leads to the next feature request..
to let
users disable this functionality so they are hidden :)
what do you think ?
Original comment by herbert....@gmail.com
on 30 Dec 2008 at 12:46
for the hidden, let's do one thing at the time, when we get the activity right
we can
than play with hidden users.
why is generic relation better/different than a FK field to Category?
any preferences where to have displayed total number of users?
first patch simply removes two lines which are AFAIK unused :-)
second one in addition to simple activity tracking implements single UPDATE
query,
display on the profile page and db indexes.
Original comment by redduck...@gmail.com
on 30 Dec 2008 at 2:27
Attachments:
ad generic relations: it's better because it's generic ;) it could also be used
for
the wiki or by other applications ..
ad currently online users: i would say simply in the same <div> as the
login/register/logout links.. just add another line there..
ad patch: looks promising.. one thing though for creating the LastSeen object..
how
about registering a post_save signal:
http://docs.djangoproject.com/en/dev/topics/signals/#topics-signals - this way
it
should also work if users are created through a 3rd party code..
another thing .. is .objects.filter( .. ).update(..) returning the number of
updated
rows ? maybe we could use it to verify that it really exists..
Original comment by herbert....@gmail.com
on 30 Dec 2008 at 2:51
this patch brings generic relations and the template tag for counting, also
attaching
the communitydraft template patch
i kinda took out the LastSeen creation, since we are using generic relations in
no
longer makes sense :-)
Original comment by redduck...@gmail.com
on 31 Dec 2008 at 12:18
Attachments:
implemented the guest activity as well, implemented an argument to template tag
to
define time span for which to get activity.
notes:
- i have yet to think about some intelligent way to use the info in template
- the tag probably does 3 SELECT's :-/
Original comment by redduck...@gmail.com
on 2 Jan 2009 at 12:52
forgot the attachment
Original comment by redduck...@gmail.com
on 2 Jan 2009 at 12:52
Attachments:
cool, you are even tracking guests (optionally) :) nice
@ LastSeen object: i think we had a misunderstanding for the purpose of the
generic
relation here :) the one i meant would point to view-specific objects.. like the
'Category' or a 'WikiSnip' - so the views could themselves tell you that there
are x
people currently viewing the category 'General' .. or the wiki snip 'Start' ..
but .. i have to admit it makes perfect sense to reference the Group object
hardcoded
.. (maybe additionally to the generic relation)
how exactly can the template tag sph_activity be used ?
as for the 3 SELECT's .. i guess it would make sense to simply cache it for 5
minutes
(something like cache.set('sphene.community.activity', resultcounts, 300) -
although
you have to make sure to store the result not the query objects :) ) .. as far
as i
understand the documentation the 300 is really the timeout, not idletime.. (the
only
bad thing is probably that if you login .. there would still be 0 logged in
users for
another 5 minutes.. )
Original comment by herbert....@gmail.com
on 2 Jan 2009 at 9:14
this should add caching and allow proper use of the template tag (which the last
patch didn't :-))
i choose to push the variables in the context because that is the only way i
know of
that you can delegate the display of array (currently active users) to
template, as
opposed to returning html in the tag.
comments/improvements/feedback welcome
Original comment by redduck...@gmail.com
on 3 Jan 2009 at 10:43
Attachments:
on a second thought the template tag should have probably been the inclusion
tag :D
Original comment by redduck...@gmail.com
on 4 Jan 2009 at 11:32
i'm also wondering if it wouldn't make sense to make a template tag dedicated
for
counting.. and another for the list of users.. i'm not sure if we need both..
and i'm
not sure how the query set affects the cache..
anyway .. i will look deeper into it when i have time.. (and.. i think i will
create
a new branch for these changes so i can check them in and work with you without
affecting the trunk before it is ready :) )
Original comment by herbert....@gmail.com
on 5 Jan 2009 at 8:34
hrm, i'm not sure i understand you, you are suggesting to HAVE two tags or to
NOT
HAVE two tags?
Original comment by redduck...@gmail.com
on 5 Jan 2009 at 11:27
i'm suggesting to HAVE two tags :) because i think the usual usecase would be to
display the number of online users on every page.. with a link to the list of
online
users.. which will only be displayed on that one page .. not every time..
btw. i have created a branch ..
http://yourhell.com/svn/root/django/communitytools/branches/lastseen_139/ (the
same
for 'communitydraft') - but i haven't had time yet to commit your patch (has to
wait
till tomorrow probably) - if you would like write access to the repository mail
me a
username you would like at herbert.poul@gmail.com and i'll create you an
account..
Original comment by herbert....@gmail.com
on 5 Jan 2009 at 11:47
Original issue reported on code.google.com by
redduck...@gmail.com
on 29 Dec 2008 at 10:20Attachments: