def parse_app_node(self): tag = self.root.find("app") app_name = tag.get('name') try: self.app = Applications.objects.get(name=app_name) except Applications.DoesNotExist: self.app = Applications() self.app.name = app_name self.app.description = tag.get('label') self.app.save()
def post(self, request,id=None, *args, **kwargs): #add a node postData = json.loads(request.body) name = postData.get('name', None) theme = postData.get('theme',None) description = postData.get('description',None) if id is None: app_obj = Applications() else: app_obj = Applications.objects.get(pk=id) app_obj.domain = name if theme != None: app_obj.theme = Themes.objects.get(pk=theme) app_obj.description = description app_obj.save() context_data = { "id":app_obj.pk } return self.render_to_response(context=context_data)
class AppsManager(object): root = None app = None def __init__(self, conf_file): app_config = ET.parse(conf_file) self.root = app_config.getroot() def parse_app_node(self): tag = self.root.find("app") app_name = tag.get('name') try: self.app = Applications.objects.get(name=app_name) except Applications.DoesNotExist: self.app = Applications() self.app.name = app_name self.app.description = tag.get('label') self.app.save() def parse_frontend_url(self): tag = self.root.find('urls') if tag is not None: path = tag.get('path') try: url_object = UrlPatterns.objects.get(path=path,application=self.app,is_frontend=True) except UrlPatterns.DoesNotExist: url_object = UrlPatterns() url_object.path = path url_object.regex = tag.get('regex') url_object.is_frontend = True url_object.application=self.app url_object.save() def parse_admin_section(self): #include the admin url admin_url = self.root.find("admin") if admin_url is not None: print "passa" for url_admin_obj in admin_url.findall("url"): path = url_admin_obj.get("path") print path try: admin_url_object = UrlPatterns.objects.get(path=path,application=self.app,is_admin=True) except UrlPatterns.DoesNotExist: admin_url_object = UrlPatterns() admin_url_object.path = path admin_url_object.regex = url_admin_obj.get("regex") admin_url_object.application = self.app admin_url_object.is_admin = True admin_url_object.save() #include admin menu admin_menu = admin_url.find('menus') if admin_menu is not None: for admin_menu_item in admin_menu.findall('menu'): admin_menu_path = admin_menu_item.get('url') admin_menu_prompt = admin_menu_item.get('prompt') admin_menu_name = admin_menu_item.get('name') admin_menu_parent = admin_menu_item.get('parent',None) admin_menu_icon = admin_menu_item.get('icon',None) try: adm_menu = AdminMenu.objects.get(name=admin_menu_name) except AdminMenu.DoesNotExist: adm_menu = AdminMenu() adm_menu.name = admin_menu_name adm_menu.path = admin_menu_path adm_menu.prompt = admin_menu_prompt adm_menu.icon = admin_menu_icon if admin_menu_parent is not None: try: adm_menu.parent = AdminMenu.objects.get(name=admin_menu_parent) except AdminMenu.DoesNotExist: print "an error occurred, the parent module %s doesn't exist"%admin_menu_parent adm_menu.save() def parse_rest_section(self): url = self.root.find("rest") if url is not None: for rest_url in url.findall("url"): path = rest_url.get("path") try: rest_object = UrlPatterns.objects.get(path=path,application=self.app,is_rest=True) except UrlPatterns.DoesNotExist: rest_object = UrlPatterns() rest_object.path = path rest_object.regex = rest_url.get("regex") rest_object.application = self.app rest_object.is_rest = True rest_object.save() def parse_themes_section(self): themes = self.root.find('themes') if themes is not None: for theme in themes.findall('theme'): theme_folder = theme.get('folder') try: website_theme = Themes.objects.get(folder=theme_folder) except Themes.DoesNotExist: website_theme = Themes() website_theme.folder = theme_folder website_theme.save() def parse_site_section(self): site_root = self.root.find('sites') if site_root is not None: #the module wjat install some websites for site in site_root.findall('site'): #get all site in the sites root domain = site.get('domain') #add the site to the django site framework try: site_object = Domains.objects.get(domain=domain) except Domains.DoesNotExist: site_object = Domains() site_object.domain = domain site_object.save() def parse_widgets_section(self): from widgets.models import InstalledWidgtes widgets = self.root.find("widgets") if widgets is not None: for wid in widgets.findall("widget"): widget_obj = InstalledWidgtes() widget_obj.name = wid.get("name") widget_obj.description = wid.get("description") widget_obj.app = Applications.objects.get(pk=self.app.id) widget_obj.save()