Example #1
0
def create_template(**kwargs):
    """
    Delete all existing templates, create a new one and return the instance.
    """
    Template.objects.all().delete()

    template = Template(**kwargs)
    template.save()
    return template
Example #2
0
    def _convert_template_style(self, user_map, table_name):
        """
        move the templates and styles
        Note: Both tables structures are identical.
        """
        print "_"*80
        print "Move %s..." % table_name
        print
        table_keys = (
            "id", "name", "lastupdateby", "description", "content",
            "lastupdatetime", "createtime"
        )
        items = self.__get_all(table_keys, table_name)

        item_map = {}
        for item in items:
#            self.__fix_datetimes(item, ["createtime", "lastupdatetime"])
            try:
                item["lastupdateby"] = user_map[item["lastupdateby"]]
            except KeyError:
                item["lastupdateby"] = None

            print item

            # With the old version there is no "createby"
            item["createby"] = item["lastupdateby"]

            old_id = item.pop("id")

            if table_name == "templates":
                new_entry = Template(**item)
            elif table_name == "styles":
                new_entry = Style(**item)
            else:
                raise # Should never happen.

            new_entry.save()

            item_map[old_id] = new_entry

        return item_map