Permalink
Browse files

service jid option

  • Loading branch information...
1 parent 8c6f71f commit 36db5d77f5e8f9676fc611512463d8188bad603d Sergey committed Apr 8, 2012
Showing with 53 additions and 12 deletions.
  1. +3 −1 bnw_core/bnw_objects.py
  2. +43 −9 bnw_handlers/command_settings.py
  3. +1 −0 bnw_xmpp/handlers.py
  4. +6 −2 config.py.example
View
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from bnw_mongo import get_db
from bnw_xmpp.base import send_plain
-from base import notifiers
+from base import notifiers,config
#from bnw_xmpp import deliver_formatters
from twisted.internet import defer
import txmongo,time
@@ -179,6 +179,8 @@ class User(MongoObject):
)
def send_plain(self,message,sfrom=None):
+ if not sfrom:
+ sfrom = self.get('settings',{}).get('servicejid',None)
if self['jid']:
send_plain(self['jid'],sfrom,message)
@@ -2,30 +2,64 @@
#from twisted.words.xish import domish
from base import *
+from bnw_core.base import config
import random
import bnw_core.bnw_objects as objs
-optionnames = [ 'usercss', 'password' ]
+class SimpleSetting(object):
+ def __init__(self,default=None):
+ self.default=None
+ pass
+
+ def get(self,request,name):
+ setts = request.user.get('settings',{})
+ return setts.get(name,self.default)
+
+ @defer.inlineCallbacks
+ def write(self,request,name,value):
+ if len(value)>2048:
+ defer.returnValue((False,('%s value is too long.' % (name,))))
+ _ = yield objs.User.mupdate({'name':request.user['name']},
+ {'$set':{'settings.'+name:value}},safe=True)
+ defer.returnValue((True,))
+
+class ServiceJidSetting(SimpleSetting):
+ def get(self,request,name):
+ setts = request.user.get('settings',{})
+ return setts.get(name,config.srvc_name)
+ def write(self,request,name,value):
+ return SimpleSetting.write(self,request,name,request.to)
+
+optionnames = { 'usercss': SimpleSetting(''),
+ 'password': SimpleSetting(None),
+ 'servicejid': ServiceJidSetting(),
+ }
+
@require_auth
@defer.inlineCallbacks
def cmd_set(request,**kwargs):
""" Настройки """
if not kwargs:
- current = request.user.get('settings',{})
+ current = {}
+ for n,v in optionnames.iteritems():
+ current[n]=v.get(request,n)
defer.returnValue(
dict(ok=True,format='settings',settings=current)
)
else:
- for n in optionnames:
- if n in kwargs:
- v = kwargs[n]
- if len(v)>2048:
+ for n,v in kwargs.iteritems():
+ on = optionnames.get(n,None)
+ if not on:
+ defer.returnValue(
+ dict(ok=False,desc='Unknown setting: %s' % (n,))
+ )
+ else:
+ res = yield on.write(request,n,v)
+ if not res[0]:
defer.returnValue(
- dict(ok=False,desc='%s is too long.' % (n,))
+ dict(ok=False,desc=res[1])
)
- _ = yield objs.User.mupdate({'name':request.user['name']},
- {'$set':{'settings.'+n:v}},safe=True)
defer.returnValue(
dict(ok=True,desc='Settings updated.')
)
View
@@ -130,6 +130,7 @@
(
("c", "usercss", True, u"User CSS."),
("p", "password", True, u"Password."),
+ ("s", "servicejid", False, u"Set service jid."),
),
command_settings.cmd_set,
),
View
@@ -48,12 +48,16 @@ webui_base = 'http://bnw.blasux.ru/'
webuiws_base = 'ws://bnw.blasux.ru/'
-
webui_static = 'http://bnw.blasux.ru/static/'
+## База данных
+
+database = 'bnw_test'
+database_fs = 'bnw_fs'
+
## Fuck
-fuck_enabled = True
+fuck_enabled = False
## Fuck-fuck-fuck

0 comments on commit 36db5d7

Please sign in to comment.