Exemple #1
0
def load_news():
	"""
	Restores the news from the old Stigull database
	
	Usage:  load_news()
	Pre:    None
	Post:   The batch of old news have been inserted into the new database
	""" 
	users = scripts.load_objects("auth.user.txt")
	news = scripts.load_objects("news.txt")
	changes = scripts.load_objects("change.txt")
	comments = scripts.load_objects("comments.txt")
	
	print users, news, changes, comments
	
	for pk, entry_dict in news.itervalues():
		#Zero or more news from news have been traversed
		#Each entry has the following fields 
		#   title, titleEn, body, bodyEn, datetimeCreated, author, changes, comments
		#For each entry a new Entry has been created with two 'Content' objects
		user = User.objects.get(username = users[news['author']].username)
		
		body_html = markdown(entry_dict['body'])
		body_en_html = markdown(entry_dict['bodyEn'])
		excerpt = truncatewords_html(body_html, 30)
		
		entry = Entry(publish_date = entry_dict['datetimeCreated'],
						author = user,
						enable_comments = True,
						status = Entry.LIVE_STATUS,
						slug = slugify(entry_dict['title']),
						excerpt = excerpt      
					)
					
		content_is = Content(entry = entry,
								language = 'is',
								title = entry_dict['title'],
								body = entry_dict['body'],
								body_html = body_html)
							
        content_en = Content(entry = entry,
                                language = 'en',
                                title = entry_dict['titleEn'],
                                body = entry_dict['bodyEn'],
                                body_html = body_en_html)
Exemple #2
0
def load_old_users():
    users = load_objects("auth.user.txt")
    groups = load_objects("./auth.group.txt")
    cities = load_objects("userarea.city.txt")
    postalcodes = load_objects("userarea.postalcode.txt")
    userinfo = load_objects("userarea.userinfo.txt")

    STIGULL = Group.objects.get(name=STIGULL_GROUP)
    MATH = Group.objects.get(name=MATH_GROUP)
    PHYSICS = Group.objects.get(name=PHYSICS_GROUP)
    FRESHMEN = Group.objects.get(name=FRESHMEN_GROUP)
    GOVERNMENT = Group.objects.get(name=GOVERNMENT_GROUP)

    for key, userinfo in userinfo.iteritems():
        fields = userinfo["fields"]

        user_dict = users[fields["user"]]["fields"]
        user = User(
            username=user_dict["username"],
            first_name=fields["first_name"],
            last_name=fields["last_name"],
            email="*****@*****.**" % user_dict["username"],
            is_active=user_dict["is_active"],
            is_superuser=user_dict["is_superuser"],
            is_staff=user_dict["is_staff"],
            password=user_dict["password"],
        )
        user.save()

        user_groups = [groups[id] for id in user_dict["groups"]]
        for group in user_groups:
            groupname = group["fields"]["name"]
            if groupname == u"Stigull":
                user.groups.add(STIGULL)
            elif groupname == u"Nýnemar":
                user.groups.add(FRESHMEN)
            elif groupname == u"Stjórn":
                user.groups.add(GOVERNMENT)
                user.is_staff = True

        if fields["department"] == 1:
            user.groups.add(MATH)
        else:
            user.groups.add(PHYSICS)

        profile = user.get_profile()
        profile.kennitala = userinfo["pk"]
        profile.middlenames = fields["middlenames"]
        profile.gender = fields["gender"]
        profile.gsm = fields["gsm"]
        profile.phone = fields["phone"]

        profile.homepages.create(url="http://www.hi.is/~%s" % user_dict["username"], name="Heimasvæði")

        try:
            profile.postalcode = postalcodes[fields["postalcode"]]["fields"]["postalcode"]
            print profile.postalcode
        except KeyError:
            pass
        profile.address = fields["address"]

        profile.save()
        print profile
        print user