Re: track change

2012-05-28 Thread Carsten Jantzen
Thank you

I like this concept and will try to do it this way.

Thanks for the input.

/Carsten

On May 25, 12:05 pm, bruno desthuilliers
<bruno.desthuilli...@gmail.com> wrote:
> On May 24, 11:00 pm, Carsten Jantzen <cars...@jantzens.net> wrote:
>
>
>
> > Not sure what you mean by detecting skill change using properties, I
> > havn't looked into that.
> > Could you point to some documentation about it.
>
> Python has a strong support for computed attributes[1], and offers a
> builtin "property" type for the most common use cases[2]. This let you
> turn a plain attribute into a computed one (using a getter/setter
> pair) without breaking client code. What I had in ming was to turn
> your "skill" fields into computed attributes (using either properties
> or a custom descriptor) to track change.
>
> Now having looked at django-audit implementation (http://
> code.google.com/p/django-audit/), I think their approach using the
> __setattr__ hook[3] would be better here. Here's a very Q and naïve
> implementation example:
>
> import datetime
>
> class SkillChange(models.Model):
>     player = models.ForeignKey(Player)
>     skill = models.CharField()
>     value = models.IntegerField()
>     date = models.DatetimeField()
>
> class Player(models.Model):
>    # your fields definitions here
>    skill_x = models.IntegerField()
>    skill_y = models.IntegerField()
>
>    # which fields we want to track
>    _tracked_fields = ['skill_x', 'skill_y']
>
>    def __init__(self, *args, **kw):
>        super(Player, self).__init__(*args, **kw)
>        self._changed = {}
>
>   def __setattr__(self, attr, value)
>       if attr in self._tracked_fields:
>           old_val = getattr(self, attr, None)
>           if old_val != value:
>              self._changed[attr] = value
>       super(Player, self).__setattr__(attr, value)
>
>   def save(self, *args, **kw):
>       super(Player, self).save(*args, **kw)
>       now = datetime.datetime.now()
>       for skill, value in self._changed.items():
>           SkillChange.objects.create(
>               player=self,
>               skill=skill,
>               value=value,
>               date=now
>               )
>       self._changed = {}
>
> Untested code, of course, it's just meant as a (possible) proof of
> concept. You'll probably have to deal with a few special cases like
> what happens when creating a new Player instance etc
>
> HTH
>
> [1]http://docs.python.org/release/2.6.7/reference/datamodel.html#impleme...
> [2]http://docs.python.org/release/2.6.7/library/functions.html#property
> [3]http://docs.python.org/release/2.6.7/reference/datamodel.html#object

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: track change

2012-05-24 Thread Carsten Jantzen
Hi Bruno

It's only to overview the stats and be able to track it.

I had started looking at binding the skill to the player og detecting
in the skill if it's changed. If its change then create a new one. But
I can see the point in putting it en a seperate class and make it a
skill changed instead.

Not sure what you mean by detecting skill change using properties, I
havn't looked into that.
Could you point to some documentation about it.

Thanks for the input, it has been very helpful.

/Carsten

On 24 Maj, 17:10, bruno desthuilliers <bruno.desthuilli...@gmail.com>
wrote:
> On May 23, 10:45 pm, Carsten Jantzen <cars...@jantzens.net> wrote:
>
> > When I load the player I would like to see his latest stats.
> > If I goto the players page I would like to be able to view when and
> > what skill changed.
>
> > I am looking for a good way to implement it.
> > I was thinking to make the skill it's own object and make a one to
> > many relation on the player.
> > What I am afraid of is that the same skill will show up multiple times
> > when loading the player.
>
> There are many ways to tackle this problem, and the "best" one depends
> on your game's rules. Your above solution would indeed return the
> whole history, and you'd need to filter it out to only get the last
> value for each skill. A PITA to work with and not exactly efficient...
>
> If it's only for stats and you have no other reason to turn skills
> into proper models, the simplest thing would be to add a
> "SkillChanged" model, ie (Q):
>
> class SkillChange(models.Model):
>     player = models.ForeignKey(Player)
>     skill = models.CharField()
>     value = models.IntegerField()
>     date = models.DatetimeField(auto_now_add=True)
>
> then detect skill changes using properties (or explicit getters /
> setters) to access your Player's class skills fields and create a new
> SkillChange for each skill update.
>
> Or use any of the solutions Andre suggested

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: track change

2012-05-24 Thread Carsten Jantzen
Thanks I have looked some into it, but will look some more.
I was afraid that it gave to much information compare to what I
wanted.


On 24 Maj, 06:37, Andre Terra <andrete...@gmail.com> wrote:
> Google for Django Audit Log and/or Audit Trail. While some of the packages
> might not be under active development, they may be able to point you in the
> right direction.
>
> Cheers,
> AT
>
> -- Sent from my phone, please excuse any typos. --
> On May 23, 2012 5:45 PM, "Carsten Jantzen" <cars...@jantzens.net> wrote:
>
>
>
>
>
>
>
> > Hi
>
> > I am looking for a way to track a skill change for a player in a
> > online game.
>
> > model:
> > Player 1
> > skill_x=1
> > skill_y=1
>
> > During next update I get a change
>
> > Player 1
> > skill_x=2
> > skill_y=1
>
> > When I load the player I would like to see his latest stats.
> > If I goto the players page I would like to be able to view when and
> > what skill changed.
>
> > I am looking for a good way to implement it.
> > I was thinking to make the skill it's own object and make a one to
> > many relation on the player.
> > What I am afraid of is that the same skill will show up multiple times
> > when loading the player.
>
> > Hope to get some input.
>
> > /Carsten
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



track change

2012-05-23 Thread Carsten Jantzen
Hi

I am looking for a way to track a skill change for a player in a
online game.

model:
Player 1
skill_x=1
skill_y=1

During next update I get a change

Player 1
skill_x=2
skill_y=1

When I load the player I would like to see his latest stats.
If I goto the players page I would like to be able to view when and
what skill changed.

I am looking for a good way to implement it.
I was thinking to make the skill it's own object and make a one to
many relation on the player.
What I am afraid of is that the same skill will show up multiple times
when loading the player.

Hope to get some input.

/Carsten

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Login based in url for user

2011-08-30 Thread Carsten Jantzen
Hej I am new and trying to make a login for mysite.
I have written a basic login which validates against another site and
is working fine atm.

I would like to make the auth related to the url.
So that user a with permission 1 can access www.test.dk/1/content but
he is not allowed to access www.test.dk/2/content
user 2 with permission 4 can access www.test.dk/4/content but he is
not allowed to access www.test.dk/1/content

It there a good way to solved this?

Is it possible extend the or use the @login_required tag to this solution.

Hope for some input so I can find a solution.

Regards
Carsten

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: about django

2011-07-28 Thread Carsten Jantzen
There is a good tutorial:
https://docs.djangoproject.com/en/1.3/intro/tutorial01/

I would recommend you start with that, I did and it was a good starting point.

/Carsten


2011/7/28 Ghanshyam Pandey :
> Hello,
>
> i want to learn django, but from where to start, I do not know.
>
>
> Would you please help me?
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Form login and get information.

2011-06-19 Thread Carsten Jantzen
Hi

I have started to build a application using django.
I am about to receive input from a form.
Using this input ( login and security code ) and I have to connect to
another site login and retrive player information.

I am kind confused as to where should the code which connect to the
remote site be?

I have made a form class, inside this I could retrive the variables
and make the form connect and return failure to connect or player
information.

Or should the views handle the form and make the connection and get
the information.

Or should the information be passed on to a view which handles the
login and gets the information.

/Carsten

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.