add working karma module to django bot site
This commit is contained in:
parent
154eb9753f
commit
69aa4016bc
@ -8,6 +8,10 @@ class LogEntry(models.Model):
|
|||||||
userhost = models.CharField(max_length=512)
|
userhost = models.CharField(max_length=512)
|
||||||
timestamp = models.DateTimeField(db_column='karmatime')
|
timestamp = models.DateTimeField(db_column='karmatime')
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return "%s given %s by %s on %s" % (self.key, self.delta,
|
||||||
|
self.who, self.timestamp)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
db_table = 'karma_log'
|
db_table = 'karma_log'
|
||||||
ordering = ['timestamp']
|
ordering = ['timestamp']
|
||||||
@ -18,6 +22,13 @@ class User(models.Model):
|
|||||||
pos = models.IntegerField()
|
pos = models.IntegerField()
|
||||||
neg = models.IntegerField()
|
neg = models.IntegerField()
|
||||||
|
|
||||||
|
def _get_total(self):
|
||||||
|
return self.pos + self.neg
|
||||||
|
total = property(_get_total)
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return "Karma User %s (%s/%s)" % (self.who, self,pos, self.neg)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
db_table = 'karma_users'
|
db_table = 'karma_users'
|
||||||
ordering = ['who']
|
ordering = ['who']
|
||||||
@ -27,6 +38,9 @@ class Value(models.Model):
|
|||||||
key = models.CharField(max_length=255, primary_key=True)
|
key = models.CharField(max_length=255, primary_key=True)
|
||||||
value = models.IntegerField()
|
value = models.IntegerField()
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return "Karma Value %s (%s)" % (self.key, self.value)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
db_table = 'karma_values'
|
db_table = 'karma_values'
|
||||||
ordering = ['value']
|
ordering = ['value']
|
||||||
|
7
botweb/karma/urls.py
Executable file
7
botweb/karma/urls.py
Executable file
@ -0,0 +1,7 @@
|
|||||||
|
from django.conf.urls.defaults import *
|
||||||
|
|
||||||
|
urlpatterns = patterns('karma.views',
|
||||||
|
(r'^$', 'index'),
|
||||||
|
(r'^givers/$', 'givers'),
|
||||||
|
(r'^stats/$', 'stats'),
|
||||||
|
)
|
@ -1 +1,16 @@
|
|||||||
# Create your views here.
|
from django.shortcuts import render_to_response
|
||||||
|
from karma.models import Value, User
|
||||||
|
|
||||||
|
def index(request):
|
||||||
|
karma_values = len(Value.objects.all())
|
||||||
|
karma_users = len(User.objects.all())
|
||||||
|
return render_to_response('karma/index.html', {'value_count': karma_values,
|
||||||
|
'user_count': karma_users})
|
||||||
|
|
||||||
|
def stats(request):
|
||||||
|
values = Value.objects.all().order_by('-value')
|
||||||
|
return render_to_response('karma/stats.html', {'values': values})
|
||||||
|
|
||||||
|
def givers(request):
|
||||||
|
users = User.objects.all().order_by('who')
|
||||||
|
return render_to_response('karma/givers.html', {'users': users})
|
||||||
|
@ -83,10 +83,15 @@ MIDDLEWARE_CLASSES = (
|
|||||||
|
|
||||||
ROOT_URLCONF = 'botweb.urls'
|
ROOT_URLCONF = 'botweb.urls'
|
||||||
|
|
||||||
|
TEMPLATE_BASE_LOC = os.path.normpath(
|
||||||
|
os.path.join(os.path.abspath(os.path.dirname(__file__)),
|
||||||
|
'templates'))
|
||||||
|
|
||||||
TEMPLATE_DIRS = (
|
TEMPLATE_DIRS = (
|
||||||
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
|
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
|
||||||
# Always use forward slashes, even on Windows.
|
# Always use forward slashes, even on Windows.
|
||||||
# Don't forget to use absolute paths, not relative paths.
|
# Don't forget to use absolute paths, not relative paths.
|
||||||
|
TEMPLATE_BASE_LOC,
|
||||||
)
|
)
|
||||||
|
|
||||||
INSTALLED_APPS = (
|
INSTALLED_APPS = (
|
||||||
@ -104,3 +109,4 @@ INSTALLED_APPS = (
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print DB_LOCATION
|
print DB_LOCATION
|
||||||
|
print TEMPLATE_DIRS
|
||||||
|
7
botweb/templates/karma/givers.html
Executable file
7
botweb/templates/karma/givers.html
Executable file
@ -0,0 +1,7 @@
|
|||||||
|
<ul>
|
||||||
|
{% for user in users %}
|
||||||
|
<li>
|
||||||
|
{{ user.who }} - {{ user.pos }} positive, {{ user.neg }} negative, {{ user.total }} total
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
4
botweb/templates/karma/index.html
Executable file
4
botweb/templates/karma/index.html
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
<ul>
|
||||||
|
<li><a href="/karma/stats/">Karma Stats</a> ({{ value_count }} karma entries)</li>
|
||||||
|
<li><a href="/karma/givers/">Karma Giver Stats</a> ({{ user_count }} karma givers)</li>
|
||||||
|
</ul>
|
7
botweb/templates/karma/stats.html
Executable file
7
botweb/templates/karma/stats.html
Executable file
@ -0,0 +1,7 @@
|
|||||||
|
<ol>
|
||||||
|
{% for value in values %}
|
||||||
|
<li>
|
||||||
|
{{ value.key }} ({{ value.value }})
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ol>
|
@ -6,9 +6,7 @@ from django.conf.urls.defaults import *
|
|||||||
|
|
||||||
urlpatterns = patterns(
|
urlpatterns = patterns(
|
||||||
'',
|
'',
|
||||||
(r'^karma/$', 'karma.views.index'),
|
(r'^karma/', include('karma.urls')),
|
||||||
(r'^karma/givers/$', 'karma.views.givers'),
|
|
||||||
(r'^karma/stats/$', 'karma.views.stats'),
|
|
||||||
# Example:
|
# Example:
|
||||||
# (r'^botweb/', include('botweb.foo.urls')),
|
# (r'^botweb/', include('botweb.foo.urls')),
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user