Browse Source

Merge branch 'master' of git.someserver.de:k4ever into morejson

Sebastian Lohff 9 years ago
parent
commit
5c480e452f

+ 3
- 1
k4ever/api2/decorators.py View File

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

+ 16
- 0
k4ever/buyable/fixtures/buyable_types.json View File

@@ -0,0 +1,16 @@
1
+[
2
+	{
3
+		"pk": 1,
4
+		"model": "buyable.buyabletype",
5
+		"fields": {
6
+			"name": "Snack"
7
+		}
8
+	},
9
+	{
10
+		"pk": 2,
11
+		"model": "buyable.buyabletype",
12
+		"fields": {
13
+			"name": "Getr\u00e4nk"
14
+		}
15
+	}
16
+]

+ 10
- 0
k4ever/buyable/management.py View File

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

+ 12
- 0
k4ever/main/fixtures/group_plugin.json View File

@@ -0,0 +1,12 @@
1
+[
2
+	{
3
+		"pk": 1,
4
+		"model": "auth.group",
5
+		"fields":
6
+			{
7
+				"name": "Plugin",
8
+				"permissions": []
9
+			}
10
+	}
11
+]
12
+

+ 10
- 0
k4ever/main/management.py View File

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

+ 3
- 4
k4ever/main/views.py View File

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

+ 5
- 0
k4ever/settings_default.py View File

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

Loading…
Cancel
Save