-import os, tarfile, datetime, logging
+import os, tarfile, datetime, logging, re
from django.core.cache import cache
from django.utils.translation import ugettext as _
tag.text = content
return tag
-def ET_Element_add_tag(el, name, content = None, **attrs):
- tag = ET.SubElement(el, name)
+def ET_Element_add_tag(el, tag_name, content = None, **attrs):
+ tag = ET.SubElement(el, tag_name)
if content:
tag.text = unicode(content)
return tag
-def make_extra(el, extra):
- if not extra:
+GOOD_TAG_NAME = re.compile("^\w+$")
+
+def make_extra(el, v):
+ if v is None:
return
- if isinstance(extra, dict):
- for k, v in extra.items():
- make_extra(el.add(k), v)
+
+ if isinstance(v, (int, long, str, float, bool, dict, list, tuple)):
+ if isinstance(v, tuple):
+ t = 'list'
+ else:
+ t = v.__class__.__name__
else:
- el.text = unicode(extra)
+ t = 'unknown'
+
+ value = el.add('value', type=t)
+
+ if isinstance(v, (list, tuple)):
+ for i in v:
+ item = value.add('item')
+ make_extra(item, i)
+
+ elif isinstance(v, dict):
+ for k, i in v.items():
+ item = value.add('item', key=k)
+ make_extra(item, i)
+ else:
+ value.text = unicode(v)
def write_to_file(root, tmp, filename):
tree = ET.ElementTree(root)
def decorated(ping, lock, anon_data):
root = ET.Element(root_tag_name)
- for item in qs(lock).select_related():
+ for item in qs(lock).order_by('id').select_related():
el = root.add(el_tag_name)
fn(item, el, anon_data)
ping()
def export_users(u, el, anon_data):
el.add('id', u.id)
el.add('username', u.username)
+ el.add('password', u.password)
el.add('email', u.email, validated=u.email_isvalid and 'true' or 'false')
+ el.add('reputation', u.reputation)
el.add('joindate', u.date_joined)
el.add('firstname', u.first_name)
if u.is_staff:
roles.add('role', 'moderator')
- el.add('reputation', u.reputation)
+ auth = el.add('authKeys')
+ for a in u.auth_keys.all():
+ key = auth.add('key')
+ key.add('provider', a.provider)
+ key.add('key', a.key)
+
+
+ ss = u.subscription_settings
+
+ notify = el.add('notifications', enabled=ss.enable_notifications and 'true' or 'false')
+
+ notify.add('notify', **dict([(t, ss.__dict__.get(t, 'n') == 'i' and 'true' or 'false') for t in ['member_joins', 'new_question', 'new_question_watched_tags', 'subscribed_questions']]))
+
+ notify.add('autoSubscribe', **dict([(t, ss.__dict__.get(t, False) and 'true' or 'false') for t in [
+ 'all_questions', 'all_questions_watched_tags', 'questions_asked', 'questions_answered', 'questions_commented', 'questions_viewed']]))
+
+ notify.add('notifyOnSubscribed', **dict([(t, ss.__dict__.get("notify_%s" % t, False) and 'true' or 'false') for t in [
+ 'answers', 'reply_to_comments', 'comments_own_post', 'comments', 'accepted']]))
+
+ notify.add('digest', ss.send_digest and 'on' or 'off')
+
+ watched = el.add('watchedTags')
+ rejected = el.add('rejectedTags')
+
+ for m in u.tag_selections.all():
+ if m.reason == 'good':
+ watched.add('tag', m.tag.name)
+ else:
+ rejected.add('tag', m.tag.name)
+
+
@exporter_step(Node.objects.all(), 'nodes', 'node', _('Nodes'), 'added_at')
def export_nodes(n, el, anon_data):
el.add('trigger', a.trigger and a.trigger.id or "")
el.add('action', a.action.id)
+@exporter_step(KeyValue.objects.all(), 'settings', 'setting', _('Settings'))
+def export_settings(s, el, anon_data):
+ el.add('key', s.key)
+ make_extra(el.add('value'), s.value)
+