Example #1
0
def addlandingpage(request):
    service_name = request.POST["service_name"]
    service_id = request.POST["service_id"]
    left_navigation = request.POST["left_navigation"]
    meta_keywords = request.POST["meta_keywords"]
    meta_description = request.POST["meta_description"]
    subtitle = request.POST["subtitle"]
    tutorial_message = request.POST["tutorial_message"]
    what_is_new = request.POST["what_is_new"]
    tutorial_count = int(request.POST["tutorial_count"])
    titles = []
    orders = []
    links = []
    for i in range(1, tutorial_count+1):
        try:
            title = request.POST["tutorial_title"+str(i)]
            order = request.POST["tutorial_order"+str(i)]
            link = request.POST["tutorial_link"+str(i)]
            titles.append(title)
            orders.append(int(order))
            links.append(link)
        except:
            continue
    service = Service(service_name=service_name, service_id=service_id)
    service.save()
    navigationJson = navigationParse(left_navigation, service_name, service_id)
    landingpage = Landing_page(service=service, ms_service=service_id, navigationJson=navigationJson, subtitle=subtitle, tutorial_message=tutorial_message, update_search_link=what_is_new)
    landingpage.save()
    meta_data = Meta_data(service=service, meta_keywords=meta_keywords, meta_description=meta_description)
    meta_data.save()
    #print(titles)
    for i in range(0, len(titles)):
        tutorial = Tutorial_option(landing_page=landingpage, title=titles[i], order=orders[i], link=links[i])
        tutorial.save()
    return redirect("/landingpage/"+service.service_id)
Example #2
0
def submitpage(request, service_id):
    sending = json.loads(request.POST["wholeJson"])
    navigationJson = json.dumps(sending["navigation"]).encode('utf-8').decode("unicode-escape")
    #print(navigationJson)
    nav = json.loads(navigationJson)
    translator = Translator(to_lang="en",from_lang="zh")
    for i in range(len(nav["navigation"])):
        group_name = None
        if nav["navigation"][i]["id"][:9] == "new_group":
            try:
                group_name = re.sub("[^a-z|A-Z|0-9]+","-",translator.translate(nav["navigation"][i]["group"]))
            except:
                group_name = nav["navigation"][i]["id"][:9]
            #print(group_name)
            nav["navigation"][i]["id"] = "left_nav_first_level_"+service_id+"_"+group_name
        for j in range(len(nav["navigation"][i]["articles"])):
            if nav["navigation"][i]["articles"][j]["id"][:7] == "newLink":
                if group_name == None:
                    group_name = nav["navigation"][i]["id"].split("_")[5]
                    try:
                        int(group_name)
                        group_name = re.sub("[^a-z|A-Z|0-9]+","-",translator.translate(nav["navigation"][i]["group"]))
                    except:
                        print("")
                try:
                    article_name = re.sub("[^a-z|A-Z|0-9]+","-",translator.translate(nav["navigation"][i]["articles"][j]["title"]))
                except:
                    article_name = nav["navigation"][i]["articles"][j]["id"]
                #print(group_name)
                #print(article_name)
                nav["navigation"][i]["articles"][j]["id"] = "left_nav_second_level_"+service_id+"_"+group_name+"_"+article_name
    #for i in range(len(nav["navigation"])):
    #        nav["navigation"][i]["id"] = "left_nav_first_level_"+service_id+"_"+str(i)
    #        for j in range(len(nav["navigation"][i]["articles"])):
    #            nav["navigation"][i]["articles"][j]["id"] = "left_nav_second_level_"+service_id+"_"+str(i)+"_"+str(j)
    navigationJson = json.dumps(nav).encode('utf-8').decode("unicode-escape")

    content = sending["content"]
    recentUpdates = sending["recentUpdate"]
    meta = sending["meta"]
    options = sending["tutorialOptions"]
    videoLinks = sending["videoLink"]
    service = Service.objects.get(service_id=service_id)
    landing_page = service.landing_page_set.all()[0]
    landing_page.navigationJson = navigationJson
    landing_page.subtitle=content["subtitle"]
    landing_page.tutorial_message=content["tutorial_message"]
    landing_page.update_search_link=content["update_search_links"]
    landing_page.newLinkCount = request.POST["newLinkCount"]
    landing_page.newGroupCount = request.POST["newGroupCount"]
    landing_page.save()
    meta_data = service.meta_data_set.all()[0]
    meta_data.meta_keywords = meta["metat_keywords"]
    meta_data.meta_description=meta["meta_description"]
    meta_data.save()
    old_options = landing_page.tutorial_option_set.order_by("order")
    if(len(old_options)>=len(options)):
        for i in range(len(options),len(old_options)):
            old_options[i].delete()
        for i in range(0, len(options)):
            old_options[i].title=options[i]["title"]
            old_options[i].link=options[i]["link"]
            old_options[i].save()
    else:
        for i in range(0, len(old_options)):
            old_options[i].title=options[i]["title"]
            old_options[i].link=options[i]["link"]
            old_options[i].save()
        if len(old_options) == 0:
            order_count = 0
        else:
            order_count = old_options[len(old_options)-1].order+1
        for i in range(len(old_options),len(options)):
            option = Tutorial_option(landing_page=landing_page, order=order_count, title=options[i]["title"], link=options[i]["link"])
            option.save()
            order_count+=1
    old_videos = landing_page.video_link_set.order_by("order")
    if(len(old_videos)>=len(videoLinks)):
        for i in range(len(videoLinks),len(old_videos)):
            old_videos[i].delete()
        for i in range(0, len(videoLinks)):
            old_videos[i].video_url = videoLinks[i]["VideoUrl"]
            old_videos[i].image_title = videoLinks[i]["ImageUrl"]
            old_videos[i].title = videoLinks[i]["Title"]
            old_videos[i].publish_time = videoLinks[i]["PublishTime"]
            old_videos[i].duration = videoLinks[i]["Duration"]
            old_videos[i].description = videoLinks[i]["Description"]
            old_videos[i].save()
    else:
        for i in range(0, len(old_videos)):
            old_videos[i].video_url = videoLinks[i]["VideoUrl"]
            old_videos[i].image_title = videoLinks[i]["ImageUrl"]
            old_videos[i].title = videoLinks[i]["Title"]
            old_videos[i].publish_time = videoLinks[i]["PublishTime"]
            old_videos[i].duration = videoLinks[i]["Duration"]
            old_videos[i].description = videoLinks[i]["Description"]
            old_videos[i].save()
        if len(old_videos) == 0:
            order_count = 0
        else:
            order_count = old_videos[len(old_videos)-1].order+1
        for i in range(len(old_videos),len(videoLinks)):
            video = Video_link(landing_page=landing_page, order=order_count, video_url=videoLinks[i]["VideoUrl"], title=videoLinks[i]["Title"], publish_time=videoLinks[i]["PublishTime"], duration=videoLinks[i]["Duration"], description=videoLinks[i]["Description"])
            video.save()
            order_count+=1
    old_updates = landing_page.recent_update_set.order_by("order")
    if(len(old_updates)>=len(recentUpdates)):
        for i in range(len(recentUpdates),len(old_updates)):
            old_updates[i].delete()
        recentUpdates = [update for update in reversed(recentUpdates)]
        for i in range(0, len(recentUpdates)):
            old_updates[i].title = recentUpdates[i]["update_title"]
            old_updates[i].date = recentUpdates[i]["update_date"]
            old_updates[i].description = recentUpdates[i]["update_description"]
            old_updates[i].detail = recentUpdates[i]["update_detail"]
            old_updates[i].save()
    else:
        updatedUpdates = [update for update in reversed(recentUpdates[:len(old_updates)])]
        for i in range(0, len(old_updates)):
            old_updates[i].title = updatedUpdates[i]["update_title"]
            old_updates[i].date = updatedUpdates[i]["update_date"]
            old_updates[i].description = updatedUpdates[i]["update_description"]
            old_updates[i].detail = updatedUpdates[i]["update_detail"]
            old_updates[i].order = old_updates[i].order+len(recentUpdates)-len(old_updates)
            old_updates[i].save()
        order_count = len(recentUpdates)-len(old_updates)-1
        for i in range(len(old_updates),len(recentUpdates)):
            update = Recent_update(landing_page=landing_page, order=order_count, title=recentUpdates[i]["update_title"], date=recentUpdates[i]["update_date"], description=recentUpdates[i]["update_description"], detail=recentUpdates[i]["update_detail"])
            update.save()
            order_count-=1
    expire_cache('landingPage.views.landingPage', args=[service_id], HOSTNAME=request.META['HTTP_HOST'])
    expire_cache('landingPage.views.landingPageEdit', args=[service_id], HOSTNAME=request.META['HTTP_HOST'])
    expire_cache('landingPage.views.xmlnavgenerator', args=[service_id], HOSTNAME=request.META['HTTP_HOST'])
    expire_cache('landingPage.views.jsonnavgenerator', args=[service_id], HOSTNAME=request.META['HTTP_HOST'])
    expire_cache('landingPage.views.xmlpagegenerator', args=[service_id], HOSTNAME=request.META['HTTP_HOST'])
    return redirect("/landingpage/"+service_id)