Added hooks to provide initial data for some Models
This commit is contained in:
parent
b82053d797
commit
b06995f893
|
@ -10,6 +10,8 @@ from django.contrib.auth.models import User, Group
|
||||||
from piston.utils import rc
|
from piston.utils import rc
|
||||||
from main.models import Plugin, PluginPermission
|
from main.models import Plugin, PluginPermission
|
||||||
|
|
||||||
|
from settings import PLUGIN_GROUP_ID
|
||||||
|
|
||||||
def manglePluginPerms(apiFunc):
|
def manglePluginPerms(apiFunc):
|
||||||
""" Changes to a given user when the authenticated user is an plugin.
|
""" Changes to a given user when the authenticated user is an plugin.
|
||||||
|
|
||||||
|
@ -81,7 +83,7 @@ def requirePlugin(apiFunc):
|
||||||
def wrapper(self, request, *args, **kwargs):
|
def wrapper(self, request, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
if request.user:
|
if request.user:
|
||||||
group = request.user.groups.get(name="Plugin")
|
group = request.user.groups.get(pk=PLUGIN_GROUP_ID)
|
||||||
# no exception, exec apiFunc!
|
# no exception, exec apiFunc!
|
||||||
request.plugin = Plugin.objects.get(user=request.user)
|
request.plugin = Plugin.objects.get(user=request.user)
|
||||||
return apiFunc(self, request, *args, **kwargs)
|
return apiFunc(self, request, *args, **kwargs)
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"pk": 1,
|
||||||
|
"model": "buyable.buyabletype",
|
||||||
|
"fields": {
|
||||||
|
"name": "Snack"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pk": 2,
|
||||||
|
"model": "buyable.buyabletype",
|
||||||
|
"fields": {
|
||||||
|
"name": "Getr\u00e4nk"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
|
@ -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)
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"pk": 1,
|
||||||
|
"model": "auth.group",
|
||||||
|
"fields":
|
||||||
|
{
|
||||||
|
"name": "Plugin",
|
||||||
|
"permissions": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -16,15 +16,15 @@ from django.template import RequestContext
|
||||||
from buyable.models import Purchase, Buyable, BuyableType
|
from buyable.models import Purchase, Buyable, BuyableType
|
||||||
from main.helper import getUserFromAuthblob
|
from main.helper import getUserFromAuthblob
|
||||||
from main.models import Plugin, PluginPermission
|
from main.models import Plugin, PluginPermission
|
||||||
|
from settings import SNACK_TYPE_ID, DRINK_TYPE_ID
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def startpage(request):
|
def startpage(request):
|
||||||
''' Diese Funktion wird wahrscheinlich viel Last erzeugen, da
|
''' Diese Funktion wird wahrscheinlich viel Last erzeugen, da
|
||||||
sie ueber mehrere Tabellen joined,filtered und wieder reduced.
|
sie ueber mehrere Tabellen joined,filtered und wieder reduced.
|
||||||
'''
|
'''
|
||||||
drinks = BuyableType.objects.get(name="Getränk").buyable_set.all()
|
drinks = BuyableType.objects.get(pk=DRINK_TYPE_ID).buyable_set.all()
|
||||||
snacks = BuyableType.objects.get(name="Snack").buyable_set.all()
|
snacks = BuyableType.objects.get(pk=SNACK_TYPE_ID).buyable_set.all()
|
||||||
|
|
||||||
context = {}
|
context = {}
|
||||||
|
|
||||||
|
@ -163,7 +163,6 @@ def pluginAuthblob(request, pluginId):
|
||||||
if p.plugin.uniqueAuthblob:
|
if p.plugin.uniqueAuthblob:
|
||||||
print authblob.split("\n")
|
print authblob.split("\n")
|
||||||
for line in authblob.split("\n"):
|
for line in authblob.split("\n"):
|
||||||
print "'%s'" % (line,), " <-- "
|
|
||||||
usr = getUserFromAuthblob(line, plugin)
|
usr = getUserFromAuthblob(line, plugin)
|
||||||
if usr:
|
if usr:
|
||||||
if usr == request.user:
|
if usr == request.user:
|
||||||
|
|
|
@ -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:
|
# Local time zone for this installation. Choices can be found here:
|
||||||
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
|
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
|
||||||
# although not all choices may be available on all operating systems.
|
# although not all choices may be available on all operating systems.
|
||||||
|
|
Loading…
Reference in New Issue