Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
synnefo
Commits
29985fb5
Commit
29985fb5
authored
Feb 28, 2013
by
Giorgos Korfiatis
Browse files
Remove unused code
parent
7d25480c
Changes
1
Hide whitespace changes
Inline
Side-by-side
snf-astakos-app/astakos/im/models.py
View file @
29985fb5
...
...
@@ -1303,118 +1303,6 @@ class UserSetting(models.Model):
### PROJECTS ###
################
def
synced_model_metaclass
(
class_name
,
class_parents
,
class_attributes
):
new_attributes
=
{}
sync_attributes
=
{}
for
name
,
value
in
class_attributes
.
iteritems
():
sync
,
underscore
,
rest
=
name
.
partition
(
'_'
)
if
sync
==
'sync'
and
underscore
==
'_'
:
sync_attributes
[
rest
]
=
value
else
:
new_attributes
[
name
]
=
value
if
'prefix'
not
in
sync_attributes
:
m
=
(
"you did not specify a 'sync_prefix' attribute "
"in class '%s'"
%
(
class_name
,))
raise
ValueError
(
m
)
prefix
=
sync_attributes
.
pop
(
'prefix'
)
class_name
=
sync_attributes
.
pop
(
'classname'
,
prefix
+
'_model'
)
for
name
,
value
in
sync_attributes
.
iteritems
():
newname
=
prefix
+
'_'
+
name
if
newname
in
new_attributes
:
m
=
(
"class '%s' was specified with prefix '%s' "
"but it already has an attribute named '%s'"
%
(
class_name
,
prefix
,
newname
))
raise
ValueError
(
m
)
new_attributes
[
newname
]
=
value
newclass
=
type
(
class_name
,
class_parents
,
new_attributes
)
return
newclass
def
make_synced
(
prefix
=
'sync'
,
name
=
'SyncedState'
):
the_name
=
name
the_prefix
=
prefix
class
SyncedState
(
models
.
Model
):
sync_classname
=
the_name
sync_prefix
=
the_prefix
__metaclass__
=
synced_model_metaclass
sync_new_state
=
models
.
BigIntegerField
(
null
=
True
)
sync_synced_state
=
models
.
BigIntegerField
(
null
=
True
)
STATUS_SYNCED
=
0
STATUS_PENDING
=
1
sync_status
=
models
.
IntegerField
(
db_index
=
True
)
class
Meta
:
abstract
=
True
class
NotSynced
(
Exception
):
pass
def
sync_init_state
(
self
,
state
):
self
.
sync_synced_state
=
state
self
.
sync_new_state
=
state
self
.
sync_status
=
self
.
STATUS_SYNCED
def
sync_get_status
(
self
):
return
self
.
sync_status
def
sync_set_status
(
self
):
if
self
.
sync_new_state
!=
self
.
sync_synced_state
:
self
.
sync_status
=
self
.
STATUS_PENDING
else
:
self
.
sync_status
=
self
.
STATUS_SYNCED
def
sync_set_synced
(
self
):
self
.
sync_synced_state
=
self
.
sync_new_state
self
.
sync_status
=
self
.
STATUS_SYNCED
def
sync_get_synced_state
(
self
):
return
self
.
sync_synced_state
def
sync_set_new_state
(
self
,
new_state
):
self
.
sync_new_state
=
new_state
self
.
sync_set_status
()
def
sync_get_new_state
(
self
):
return
self
.
sync_new_state
def
sync_set_synced_state
(
self
,
synced_state
):
self
.
sync_synced_state
=
synced_state
self
.
sync_set_status
()
def
sync_get_pending_objects
(
self
):
kw
=
dict
((
the_prefix
+
'_status'
,
self
.
STATUS_PENDING
))
return
self
.
objects
.
filter
(
**
kw
)
def
sync_get_synced_objects
(
self
):
kw
=
dict
((
the_prefix
+
'_status'
,
self
.
STATUS_SYNCED
))
return
self
.
objects
.
filter
(
**
kw
)
def
sync_verify_get_synced_state
(
self
):
status
=
self
.
sync_get_status
()
state
=
self
.
sync_get_synced_state
()
verified
=
(
status
==
self
.
STATUS_SYNCED
)
return
state
,
verified
def
sync_is_synced
(
self
):
state
,
verified
=
self
.
sync_verify_get_synced_state
()
return
verified
return
SyncedState
SyncedState
=
make_synced
(
prefix
=
'sync'
,
name
=
'SyncedState'
)
class
ChainManager
(
ForUpdateManager
):
def
search_by_name
(
self
,
*
search_strings
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment