Skip to content
This repository
Browse code

service jid option

  • Loading branch information...
commit 36db5d77f5e8f9676fc611512463d8188bad603d 1 parent 8c6f71f
authored April 09, 2012
4  bnw_core/bnw_objects.py
... ...
@@ -1,7 +1,7 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 from bnw_mongo import get_db
3 3
 from bnw_xmpp.base import send_plain
4  
-from base import notifiers
  4
+from base import notifiers,config
5 5
 #from bnw_xmpp import deliver_formatters
6 6
 from twisted.internet import defer
7 7
 import txmongo,time
@@ -179,6 +179,8 @@ class User(MongoObject):
179 179
     )
180 180
     
181 181
     def send_plain(self,message,sfrom=None):
  182
+        if not sfrom:
  183
+            sfrom = self.get('settings',{}).get('servicejid',None)
182 184
         if self['jid']:
183 185
             send_plain(self['jid'],sfrom,message)
184 186
 
52  bnw_handlers/command_settings.py
@@ -2,30 +2,64 @@
2 2
 #from twisted.words.xish import domish
3 3
 
4 4
 from base import *
  5
+from bnw_core.base import config
5 6
 import random
6 7
 
7 8
 import bnw_core.bnw_objects as objs
8 9
 
9  
-optionnames = [ 'usercss', 'password' ]
  10
+class SimpleSetting(object):
  11
+    def __init__(self,default=None):
  12
+        self.default=None
  13
+        pass
  14
+
  15
+    def get(self,request,name):
  16
+        setts = request.user.get('settings',{})
  17
+        return setts.get(name,self.default)
  18
+
  19
+    @defer.inlineCallbacks
  20
+    def write(self,request,name,value):
  21
+        if len(value)>2048:
  22
+            defer.returnValue((False,('%s value is too long.' % (name,))))
  23
+        _ = yield objs.User.mupdate({'name':request.user['name']},
  24
+                    {'$set':{'settings.'+name:value}},safe=True)
  25
+        defer.returnValue((True,))
  26
+
  27
+class ServiceJidSetting(SimpleSetting):
  28
+    def get(self,request,name):
  29
+        setts = request.user.get('settings',{})
  30
+        return setts.get(name,config.srvc_name)
  31
+    def write(self,request,name,value):
  32
+        return SimpleSetting.write(self,request,name,request.to)
  33
+
  34
+optionnames = { 'usercss': SimpleSetting(''),
  35
+                'password': SimpleSetting(None),
  36
+                'servicejid': ServiceJidSetting(),
  37
+              }
  38
+
10 39
 @require_auth
11 40
 @defer.inlineCallbacks
12 41
 def cmd_set(request,**kwargs):
13 42
     """ Настройки """
14 43
     if not kwargs:
15  
-        current = request.user.get('settings',{})
  44
+        current = {}
  45
+        for n,v in optionnames.iteritems():
  46
+            current[n]=v.get(request,n)
16 47
         defer.returnValue(
17 48
             dict(ok=True,format='settings',settings=current)
18 49
         )
19 50
     else:
20  
-        for n in optionnames:
21  
-            if n in kwargs:
22  
-                v = kwargs[n]
23  
-                if len(v)>2048:
  51
+        for n,v in kwargs.iteritems():
  52
+            on = optionnames.get(n,None)
  53
+            if not on:
  54
+                defer.returnValue(
  55
+                    dict(ok=False,desc='Unknown setting: %s' % (n,))
  56
+                )
  57
+            else:
  58
+                res = yield on.write(request,n,v)
  59
+                if not res[0]:
24 60
                     defer.returnValue(
25  
-                        dict(ok=False,desc='%s is too long.' % (n,))
  61
+                        dict(ok=False,desc=res[1])
26 62
                     )
27  
-                _ = yield objs.User.mupdate({'name':request.user['name']},
28  
-                    {'$set':{'settings.'+n:v}},safe=True)
29 63
         defer.returnValue(
30 64
             dict(ok=True,desc='Settings updated.')
31 65
         )
1  bnw_xmpp/handlers.py
@@ -130,6 +130,7 @@
130 130
             (
131 131
                 ("c", "usercss", True, u"User CSS."),
132 132
                 ("p", "password", True, u"Password."),
  133
+                ("s", "servicejid", False, u"Set service jid."),
133 134
             ),
134 135
             command_settings.cmd_set,
135 136
         ),
8  config.py.example
@@ -48,12 +48,16 @@ webui_base = 'http://bnw.blasux.ru/'
48 48
 
49 49
 webuiws_base = 'ws://bnw.blasux.ru/'
50 50
 
51  
-
52 51
 webui_static = 'http://bnw.blasux.ru/static/'
53 52
 
  53
+## База данных
  54
+
  55
+database = 'bnw_test'
  56
+database_fs = 'bnw_fs'
  57
+
54 58
 ## Fuck
55 59
 
56  
-fuck_enabled = True
  60
+fuck_enabled = False
57 61
 
58 62
 ## Fuck-fuck-fuck
59 63
 

0 notes on commit 36db5d7

Please sign in to comment.
Something went wrong with that request. Please try again.