Browse Source

Added hooks to provide initial data for some Models

master
Sebastian Lohff 11 years ago
parent
commit
b06995f893
  1. 4
      k4ever/api2/decorators.py
  2. 16
      k4ever/buyable/fixtures/buyable_types.json
  3. 10
      k4ever/buyable/management.py
  4. 12
      k4ever/main/fixtures/group_plugin.json
  5. 10
      k4ever/main/management.py
  6. 7
      k4ever/main/views.py
  7. 5
      k4ever/settings_default.py

4
k4ever/api2/decorators.py

@ -10,6 +10,8 @@ from django.contrib.auth.models import User, Group @@ -10,6 +10,8 @@ from django.contrib.auth.models import User, Group
from piston.utils import rc
from main.models import Plugin, PluginPermission
from settings import PLUGIN_GROUP_ID
def manglePluginPerms(apiFunc):
""" Changes to a given user when the authenticated user is an plugin.
@ -81,7 +83,7 @@ def requirePlugin(apiFunc): @@ -81,7 +83,7 @@ def requirePlugin(apiFunc):
def wrapper(self, request, *args, **kwargs):
try:
if request.user:
group = request.user.groups.get(name="Plugin")
group = request.user.groups.get(pk=PLUGIN_GROUP_ID)
# no exception, exec apiFunc!
request.plugin = Plugin.objects.get(user=request.user)
return apiFunc(self, request, *args, **kwargs)

16
k4ever/buyable/fixtures/buyable_types.json

@ -0,0 +1,16 @@ @@ -0,0 +1,16 @@
[
{
"pk": 1,
"model": "buyable.buyabletype",
"fields": {
"name": "Snack"
}
},
{
"pk": 2,
"model": "buyable.buyabletype",
"fields": {
"name": "Getr\u00e4nk"
}
}
]

10
k4ever/buyable/management.py

@ -0,0 +1,10 @@ @@ -0,0 +1,10 @@
from django.db.models.signals import post_syncdb
from django.core.management import commands, call_command
import buyable.models
def createBuyableTypes(sender, app, created_models, **kwargs):
if buyable.models.BuyableType in created_models:
call_command("loaddata", "buyable_types")
post_syncdb.connect(createBuyableTypes, sender=buyable.models)

12
k4ever/main/fixtures/group_plugin.json

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
[
{
"pk": 1,
"model": "auth.group",
"fields":
{
"name": "Plugin",
"permissions": []
}
}
]

10
k4ever/main/management.py

@ -0,0 +1,10 @@ @@ -0,0 +1,10 @@
from django.db.models.signals import post_syncdb
from django.core.management import commands, call_command
import django.contrib.auth
def createPluginGroup(sender, app, created_models, **kwargs):
if django.contrib.auth.models.Group in created_models:
call_command("loaddata", "group_plugin")
post_syncdb.connect(createPluginGroup, sender=django.contrib.auth.models)

7
k4ever/main/views.py

@ -16,15 +16,15 @@ from django.template import RequestContext @@ -16,15 +16,15 @@ from django.template import RequestContext
from buyable.models import Purchase, Buyable, BuyableType
from main.helper import getUserFromAuthblob
from main.models import Plugin, PluginPermission
from settings import SNACK_TYPE_ID, DRINK_TYPE_ID
@login_required
def startpage(request):
''' Diese Funktion wird wahrscheinlich viel Last erzeugen, da
sie ueber mehrere Tabellen joined,filtered und wieder reduced.
'''
drinks = BuyableType.objects.get(name="Getränk").buyable_set.all()
snacks = BuyableType.objects.get(name="Snack").buyable_set.all()
drinks = BuyableType.objects.get(pk=DRINK_TYPE_ID).buyable_set.all()
snacks = BuyableType.objects.get(pk=SNACK_TYPE_ID).buyable_set.all()
context = {}
@ -163,7 +163,6 @@ def pluginAuthblob(request, pluginId): @@ -163,7 +163,6 @@ def pluginAuthblob(request, pluginId):
if p.plugin.uniqueAuthblob:
print authblob.split("\n")
for line in authblob.split("\n"):
print "'%s'" % (line,), " <-- "
usr = getUserFromAuthblob(line, plugin)
if usr:
if usr == request.user:

5
k4ever/settings_default.py

@ -23,6 +23,11 @@ DATABASES = { @@ -23,6 +23,11 @@ DATABASES = {
}
}
# Default model ids for some purposes
DRINK_TYPE_ID = 2
SNACK_TYPE_ID = 1
PLUGIN_GROUP_ID = 1
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.

Loading…
Cancel
Save