Skip to content

Commit 0116e1d

Browse files
authored
Merge pull request #15 from Podnapisi-NET/publish-preparations
Publish preparations
2 parents 466c7ef + 00be165 commit 0116e1d

File tree

3 files changed

+88
-7
lines changed

3 files changed

+88
-7
lines changed

README.rst

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,25 @@ fetch\_
100100
Returns a list. If defining your own functions, do not use OFFSET and LIMIT, it will
101101
be appended by the extension.
102102

103+
has\_
104+
+++++
105+
106+
Returns a bool, true or false. Query must return a single value!
107+
108+
Common keyword arguments
109+
------------------------
110+
111+
With all prepared queries, you may use cache (True/False) and cache_ttl arguments to control
112+
result caching. TTL is specified in seconds.
113+
103114
List of functions
104115
-----------------
105116

117+
get_autologin(key)
118+
++++++++++++++++++
119+
120+
Gets autologin information. Used by session integration.
121+
106122
get_session(session_id)
107123
+++++++++++++++++++++++
108124

@@ -120,6 +136,26 @@ Use string named interpolation format (the psycopg one) to specify kwargs of a f
120136
Do not forget to use {TABLE_PREFIX} variable, to add specific table prefix. (First, the
121137
python variables from config get evaluated, and then psycopg variables).
122138

139+
has_membership(user_id, group_id)
140+
+++++++++++++++++++++++++++++++++
141+
142+
Checks if user belongs to a group.
143+
144+
has_membership_resolve(user_id, group_name)
145+
+++++++++++++++++++++++++++++++++++++++++++
146+
147+
Same as has_membership, only it works with group name.
148+
149+
fetch_acl_options()
150+
+++++++++++++++++++
151+
152+
Fetches ACL data. Used by session integration.
153+
154+
get_unread_notifications_count(user_id)
155+
+++++++++++++++++++
156+
157+
Retrieves user's unread notifications count. Used by session integration.
158+
123159
Sessions integration
124160
--------------------
125161

@@ -137,6 +173,13 @@ And you can use session's **is_authenticated** property to test if user is authe
137173
if session.is_authenticated:
138174
print 'User is authenticated!'
139175
176+
Available is also the following API:
177+
* is_member(group) - group may be id of the group or name
178+
* has_privilege(option, forum_id=0) - tests if user has specified privilege
179+
* has_privileges(*options, forum_id=0) - same as has_privilege, but for multiple privileges
180+
* get_link_hash(link) - calculates hash
181+
* num_unread_notifications - number of unread notifications for session user
182+
140183
Caching
141184
-------
142185

flask_phpbb3/extension.py

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,20 +124,42 @@ def _backend(self):
124124

125125
def get_autologin(self, key, cache=False, cache_ttl=None):
126126
# type: (str, bool, typing.Optional[int]) -> typing.Optional[dict]
127-
output = self._backend.execute('get_autologin', key=key)\
128-
# type: typing.Optional[dict]
127+
output = self._backend.execute(
128+
'get_autologin',
129+
key=key,
130+
cache=cache,
131+
cache_ttl=cache_ttl,
132+
) # type: typing.Optional[dict]
129133
return output
130134

131135
def get_session(self, session_id, cache=False, cache_ttl=None):
132136
# type: (str, bool, typing.Optional[int]) -> typing.Optional[dict]
133-
output = self._backend.execute('get_session', session_id=session_id)\
134-
# type: typing.Optional[dict]
137+
output = self._backend.execute(
138+
'get_session',
139+
session_id=session_id,
140+
cache=cache,
141+
cache_ttl=cache_ttl,
142+
) # type: typing.Optional[dict]
135143
return output
136144

137145
def get_user(self, user_id, cache=False, cache_ttl=None):
138146
# type: (int, bool, typing.Optional[int]) -> typing.Optional[dict]
139-
output = self._backend.execute('get_user', user_id=user_id)\
140-
# type: typing.Optional[dict]
147+
output = self._backend.execute(
148+
'get_user',
149+
user_id=user_id,
150+
cache=cache,
151+
cache_ttl=cache_ttl,
152+
) # type: typing.Optional[dict]
153+
return output
154+
155+
def get_user_profile(self, user_id, cache=False, cache_ttl=None):
156+
# type: (int, bool, typing.Optional[int]) -> typing.Optional[dict]
157+
output = self._backend.execute(
158+
'get_user_profile',
159+
user_id=user_id,
160+
cache=cache,
161+
cache_ttl=cache_ttl,
162+
) # type: typing.Optional[dict]
141163
return output
142164

143165
def has_membership(
@@ -210,6 +232,22 @@ def get_user_acl(self, raw_user_permissions):
210232
# type: (str) -> flask_phpbb3.backends.base.UserAcl
211233
return self._backend.get_user_acl(raw_user_permissions)
212234

235+
def execute_custom(
236+
self,
237+
command, # type: str
238+
cache=False, # type: bool
239+
cache_ttl=None, # type: typing.Optional[int]
240+
**kwargs # type: typing.Any
241+
):
242+
# type: (...) -> typing.Any
243+
output = self._backend.execute(
244+
command,
245+
cache=cache,
246+
cache_ttl=cache_ttl,
247+
**kwargs
248+
) # type: typing.Any
249+
return output
250+
213251
def teardown(self, exception):
214252
# type: (typing.Any) -> None
215253
ctx = flask._app_ctx_stack.top

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ classifier =
1818
Topic :: Software Development :: Libraries :: Python Modules
1919

2020
[files]
21-
modules = flask_phpbb3
21+
packages = flask_phpbb3
2222

2323
[wheel]
2424
universal = 1

0 commit comments

Comments
 (0)