allura
修訂 | bb1a48e4668569ba5832e041dba0118d8cb42dff (tree) |
---|---|
時間 | 2012-07-02 07:25:53 |
作者 | Yuriy <yuriyarhipovua@yand...> |
Commiter | Yuriy |
[#4449] ticket:94 Subscribe another user to an artifact
pep8
@@ -22,12 +22,13 @@ from urlparse import urlparse | ||
22 | 22 | from urllib2 import urlopen |
23 | 23 | |
24 | 24 | |
25 | - | |
26 | 25 | log = logging.getLogger(__name__) |
27 | 26 | |
27 | + | |
28 | 28 | class F(object): |
29 | 29 | add_subscriber_form = AddSubscribtionToUser() |
30 | 30 | |
31 | + | |
31 | 32 | class SiteAdminController(object): |
32 | 33 | |
33 | 34 | def _check_security(self): |
@@ -108,7 +109,9 @@ class SiteAdminController(object): | ||
108 | 109 | elif request.method == 'GET': |
109 | 110 | data = {'expires': datetime.utcnow() + timedelta(days=2)} |
110 | 111 | |
111 | - data['token_list'] = M.ApiTicket.query.find().sort('mod_date', pymongo.DESCENDING).all() | |
112 | + data['token_list'] = M.ApiTicket.query.find().sort( | |
113 | + 'mod_date', | |
114 | + pymongo.DESCENDING).all() | |
112 | 115 | log.info(data['token_list']) |
113 | 116 | return data |
114 | 117 |
@@ -117,27 +120,30 @@ class SiteAdminController(object): | ||
117 | 120 | c.form = F.add_subscriber_form |
118 | 121 | if request.method == 'POST': |
119 | 122 | url = data['artifact_url'] |
120 | - try : | |
123 | + try: | |
121 | 124 | user_id = M.User.by_username(data['for_user'])._id |
122 | - except : | |
125 | + except: | |
123 | 126 | flash("Invalid login") |
124 | 127 | return data |
125 | 128 | |
126 | 129 | artifact_url = urlparse(url).path |
127 | - try : | |
130 | + try: | |
128 | 131 | urlopen(url + "subscribe?subscribe=True") |
129 | - except : | |
132 | + except: | |
130 | 133 | flash("Invalid URL") |
131 | 134 | return data |
132 | 135 | |
133 | - already_subscribed = M.Mailbox.query.get(user_id = user_id,artifact_url = artifact_url,type = "direct") | |
136 | + already_subscribed = M.Mailbox.query.get( | |
137 | + user_id=user_id, | |
138 | + artifact_url=artifact_url, | |
139 | + type="direct") | |
134 | 140 | if not already_subscribed: |
135 | - subscribe = M.Mailbox.query.find({"user_id":None,"artifact_url":artifact_url,"type" :"direct",}).first() | |
141 | + subscribe = M.Mailbox.query.find({ | |
142 | + "user_id": None, | |
143 | + "artifact_url": artifact_url, | |
144 | + "type": "direct", }).first() | |
136 | 145 | if subscribe: |
137 | - subscribe.user_id=user_id | |
146 | + subscribe.user_id = user_id | |
138 | 147 | redirect("/nf/admin/") |
139 | 148 | |
140 | 149 | return data |
141 | - | |
142 | - | |
143 | - |
@@ -50,15 +50,11 @@ class SubscribeForm(ew.SimpleForm): | ||
50 | 50 | def from_python(self, value, state): |
51 | 51 | return value |
52 | 52 | |
53 | + | |
53 | 54 | class AddSubscribtionToUser(ForgeForm): |
54 | - submit_text='Save' | |
55 | - style='wide' | |
55 | + submit_text = 'Save' | |
56 | + style = 'wide' | |
57 | + | |
56 | 58 | class fields(ew_core.NameList): |
57 | 59 | for_user = ew.TextField(label='Username') |
58 | 60 | artifact_url = ew.TextField(label='Url') |
59 | - | |
60 | - | |
61 | - | |
62 | - | |
63 | - | |
64 | - |
@@ -1,7 +1,8 @@ | ||
1 | 1 | from allura.tests import TestController |
2 | 2 | |
3 | + | |
3 | 4 | class TestSubscriber(TestController): |
4 | 5 | |
5 | 6 | def test_add_subscriber(self): |
6 | 7 | response = self.app.get('/nf/admin/add_subscribers') |
7 | - assert "<h1>Add Subscribers</h1>" in response | |
\ No newline at end of file | ||
8 | + assert "<h1>Add Subscribers</h1>" in response |