Exemplo n.º 1
0
def uploadimage(request, service_id, count):
    # Handle file upload
    images = [f.name for f in blob_service.list_blobs('img')]
    if request.method == 'POST':
        form = PNGForm(request.POST, request.FILES)
        if form.is_valid():
            docfile=request.FILES['docfile']
            path = default_storage.save(str(docfile), ContentFile(docfile.read()))
            file_name=str(docfile)
            i = 0
            while file_name in images:
                i+=1
                file_name=str(i)+"_"+str(docfile)
            blob_service.create_blob_from_path(
                'img',
                file_name,
                file_name,
                content_settings=ContentSettings(content_type='image/png')
            )
            expire_cache('landingPage.views.landingPageEdit', args=[service_id], HOSTNAME=request.META['HTTP_HOST'])
            # Redirect to the document list after POST
            return redirect("/landingpage/"+service_id+"/edit/")
    else:
        form = PNGForm()  # A empty, unbound form

    return render_to_response(
        'landingPage/uploadImage.html',
        {'images':images,
         'form': form,
         'count': count,
         'service_id': service_id,
         'imgLink': '/static/landingPage/img/'
         }
    )
Exemplo n.º 2
0
def selectArticlesWithText(request):
    try:
        article_list = request.META["HTTP_TEXT"]
    except KeyError:
        return HttpResponseBadRequest()
    articles = list(set([article.strip() for article in article_list.split("%%n%%")]));
    print()
    messages = []
    updated_service_ids = []
    articlesObjects = []
    for article in articles:
        articleObject, service_id = _getArticle(article)
        if articleObject != None:
            articlesObjects.append(articleObject)
        if service_id!=-1:
            updated_service_ids.append(service_id)
    updated_service_ids = list(set(updated_service_ids))
    for service_id in updated_service_ids:
        print(expire_cache("UT.views.updatearticles", args=[service_id], HOSTNAME=request.META['HTTP_HOST']))
    print(len(articlesObjects))
    return render(
            request,
            'UT/selectArticles.html',
            context_instance = RequestContext(request,
            {
                "articles":list(set(articlesObjects)),
            })
        )
Exemplo n.º 3
0
def addArticles(request):
    try:
        article_list = request.POST["article_list"]
    except KeyError:
        return render(
            request,
            'UT/addArticles.html',
            context_instance = RequestContext(request,
            {
            })
        )
    articles = list(set([article.strip() for article in article_list.split("\n")]));
    messages = []
    updated_service_ids = []
    for article in articles:
        message, service_id = _add(article)
        messages.append(message)
        if service_id!=-1:
            updated_service_ids.append(service_id)
    updated_service_ids = list(set(updated_service_ids))
    for service_id in updated_service_ids:
        print(expire_cache("UT.views.updatearticles", args=[service_id], HOSTNAME=request.META['HTTP_HOST']))
    return render(
            request,
            'UT/addArticles.html',
            context_instance = RequestContext(request,
            {
                "logs":messages,
            })
        )
Exemplo n.º 4
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)