Пример #1
0
def edit(request, url):
    #Makes sure user is logged in
    username = util.checkLoggedIn(request)
    if not username:
        return HttpResponseRedirect('/')
    error = ""
    if request.method == "POST":
        
        try:
            #Check if user clicked Delete Button
            if request.POST.has_key('Delete'):
                Post.objects.get(pk=url).delete()
                return HttpResponseRedirect('/')
            
            form = blogForms.newPostForm(request.POST)
            #Check if user uploaded image
            if 'image' in request.FILES:
                image = request.FILES['image']
            else:
                image = None
            #saves post, returning an error if failed
            error, post = save(request, form, image, "Post", url)
            
            if not error:
                return HttpResponseRedirect('/')
            else:
                return render_to_response("dashboard/newpost.html", {"form":form, "post":url, "error":error, "username":username, "edit":True, "action":url}, context_instance = RequestContext(request))
        except ObjectDoesNotExist:
            raise Http404
    else:
        #Loads the post into the form, so it can be edited
        try:
            # Makes sure post exists
            post = Post.objects.get(pk=url)
            url = str(url)

            if post:                
                # Gets all categories for post
                categories = Categories.objects.filter(Post__title=post.title)

                # Gets if the post is featured
                featured = Featured.objects.filter(Post__title = post.title)
                if featured:
                    isFeatued = True
                else:
                    isFeatued = False

                # Checks if the image was included in post
                if post.image:
                    imageInPost = True
                else:
                    imageInPost = False

                # Sets initial value
                form = blogForms.newPostForm(initial = {'title':post.title, 'sourceUrl':post.sourceUrl, 'content':post.content, 'categories': categories, 'featured': isFeatued, 'imageInPost': imageInPost})
                return render_to_response("dashboard/newpost.html", {"form":form, "post":url, "error":error, "username":username, "edit":True, "action":url}, context_instance = RequestContext(request))
            else:
                raise Http404
        except ObjectDoesNotExist:
            raise Http404
Пример #2
0
def category(request, category):
    

    
    username = util.checkLoggedIn(request)
    
    template = "base.html"
    page_template = "index.html"
    
    if request.is_ajax():
        template = page_template
    
    
    posts = []
    catList = Categories.objects.filter(category=category).order_by('-id')
    
    for i in catList:
        posts.append(i.Post)
    
    pages = Page.objects.all().order_by("-id")
    

    
    
    return render_to_response(template, {"posts" : posts, "pages":pages, "username": username}, context_instance=RequestContext(request))
Пример #3
0
def newpost(request):
    #Makes sure user is logged in, else redirect to home page
    username = util.checkLoggedIn(request)
    if not username:
        return HttpResponseRedirect('/')
    error = ""
    
    
    if request.method == "POST":
        
        
        form = blogForms.newPostForm(request.POST)
        #Check if there is an image
        if 'image' in request.FILES:
            image = request.FILES['image']
        else:
            image = None
        #saves post, returning an error if failed
        error, post = save(request, form, image, "Post")
        if not error:
            if not settings.DEBUG:
                tweet = post.title + " - " + "http://www.theconnectedwire.com/" + post.link
                twitter.updateTwitter(tweet)
                return HttpResponseRedirect('/' + "?tweet=" + tweet)
            else:
                return HttpResponseRedirect('/')
    
    else:
        form = blogForms.newPostForm()
    return render_to_response("dashboard/newpost.html", {"form":form, "error": error, "username": username, "action":"newpost"}, context_instance = RequestContext(request))
Пример #4
0
def authorize(request):

    user = util.checkLoggedIn(request)

    if user:
        try:
            key = PocketKey.objects.get(User=user)

            return HttpResponse("Already Authorized")

        except ObjectDoesNotExist:

            requestToken = getRequestToken()

            redirectURL = getPath()

            url = (
                "https://getpocket.com/auth/authorize?request_token="
                + requestToken
                + "&redirect_uri="
                + redirectURL
                + "/pocket/approved?request_token="
                + requestToken
            )

            return HttpResponseRedirect(url)
    else:
        return HttpResponseRedirect("/")
Пример #5
0
def addEpisode(request):

    username = util.checkLoggedIn(request)
    if not username:
        return HttpResponseRedirect('/')
    error = ""

    if request.method == "POST":

        form = blogForms.newEpisodeForm(request.POST)

        title = request.POST['title']

        showNotes = request.POST['showNotes']

        episodeURL = '/podcasts/' + request.POST['episode']

        size = request.POST['size']

        audio_length = request.POST['duration']

        if title and showNotes and episodeURL:

            published = datetime.datetime.now()

            if 'image' in request.FILES:

                image = request.FILES['image']

                store = FileSystemStorage(paths.SITE_ROOT + '/images/')

                storedImage = store.save(image.name, image)

                imageURL = '/images/' + storedImage

            else:

                imageURL = None

            episode = Podcast(title = title, 
                              link = episodeURL, 
                              showNotes = showNotes, 
                              length = size, 
                              date = published,
                              imageURL = imageURL,
                              audio_length = audio_length)
            episode.save()

            return HttpResponseRedirect('/podcast')

        else:
            error = 'Something is amiss'


    else:
        form = blogForms.newEpisodeForm()

    # Renders the dashboard html page
    return render_to_response("dashboard/newEpisode.html", {'username':username, 'form':form, 'error':error}, context_instance =RequestContext(request))
Пример #6
0
def showEpisodes(request):

    username = util.checkLoggedIn(request)

    podcasts = Podcast.objects.all().order_by('-date')

    pages = Page.objects.all().order_by('id')

    return render_to_response("podcasts.html", {"podcasts": podcasts, "pages": pages, "username":username})
Пример #7
0
def page(request, page):
    username = util.checkLoggedIn(request)
    try:
        page = Page.objects.get(title=page)
    except ObjectDoesNotExist:
        raise Http404
    
    if page:
        pages = Page.objects.all().order_by("id")
        return render_to_response("page.html", {"page":page, "pages":pages, "username":username})
    else:
        raise Http404
Пример #8
0
def checkAuthorized(request):
    user = util.checkLoggedIn(request)

    if user:
        try:
            key = PocketKey.objects.get(User=user)

            return HttpResponse("True")

        except ObjectDoesNotExist:

            return HttpResponse("False")

    else:
        return HttpResponseRedirect("/")
Пример #9
0
def permalink(request, url):
    
    
    
    username = util.checkLoggedIn(request)
    post = Post.objects.filter(link=url)
    
    if post:
        pages = Page.objects.all().order_by("id")
    
        return render_to_response("permalink.html", {"posts": post, "pages":pages, "username":username})

    else:
        #If post doesn't exist, show a 404 page
        raise Http404
Пример #10
0
def deleteEpisode(request, id):

    username = util.checkLoggedIn(request)

    if not username:
        return HttpResponseRedirect('/')

    episode = Podcast.objects.get(pk=id)

    try:
        os.remove(paths.SITE_ROOT + episode.imageURL)
    except OSError:
        pass

    episode.delete()

    return HttpResponseRedirect('/podcast')
Пример #11
0
def approved(request):

    user = util.checkLoggedIn(request)

    if user:

        requestToken = request.GET.get("request_token")

        access_token = getAuthorization(requestToken)

        key = PocketKey(User=user, key=access_token)
        key.save()

        return HttpResponseRedirect("/dashboard")

    else:

        return HttpResponseRedirect("/")
Пример #12
0
def dash(request):

	# Gets the logged in user, or redirects
	username = util.checkLoggedIn(request)
	if not username:
		return HttpResponseRedirect('/login?next=dashboard')

	# Gets total wordcount
	wordCountInt, wordCountString = stats.getWordCount()

	# Gets total number of posts
	postCount = stats.getPostCount()

	average = int(int(wordCountInt) / int(postCount));

	# Days since last post
	daysSince = stats.daysSince()

	# Makes sure the grammar is correct
	if not daysSince == 1:
		day = "days"
	else:
		day = 'day'

	# Gets the top story title and link from techmeme
	suggestionTitle, suggestionLink = stats.suggestion()

	todo = Todo.objects.all().order_by('-id')

	# Renders the dashboard html page
	return render_to_response("dashboard/main.html", {'username':username,
														'wordCountString': wordCountString,
														'average': average,
														'postCount': postCount,
														'daysSince':daysSince,
														'day': day,
														'suggestionTitle':suggestionTitle,
														'suggestionLink':suggestionLink,
														'todo': todo}, context_instance =RequestContext(request))
Пример #13
0
def pageEdit(request, url):
    username = util.checkLoggedIn(request)
    if not username:
        return HttpResponseRedirect('/')
    error = ""
    if request.method == "POST":
        
        #Check if user clicked Delete Button
        if request.POST.has_key('Delete'):
            Page.objects.get(title=url).delete()
            return HttpResponseRedirect('/')
        
        form = blogForms.newPageForm(request.POST)
        #Check if user uploaded image
        if 'image' in request.FILES:
            image = request.FILES['image']
        else:
            image = None
        #saves page, returning an error if failed
        error = save(request, form, image, "Page", url)
        
        if not error:
            return HttpResponseRedirect('/')
        else:
            return render_to_response("dashboard/newpage.html", {"form":form, "post":url, "error":error, "username":username, "edit":True, "action":url}, context_instance = RequestContext(request))
    
    else:
        #Loads the page into the form, so it can be edited
        try:
            page = Page.objects.get(title=url)
            url = str(url)
            if page:

                form = blogForms.newPageForm(initial = {'title':page.title, 'content':page.content})
                return render_to_response("dashboard/newpage.html", {"form":form, "error":error, "username":username, "edit":True, "action":url}, context_instance = RequestContext(request))
            else:
                raise Http404
        except ObjectDoesNotExist:
            raise Http404
Пример #14
0
def newpage(request):
    #Makes sure user is logged in, else redirect to home page
    username = util.checkLoggedIn(request)
    if not username:
        return HttpResponseRedirect('/')
    error = ""
    
    if request.method == "POST":
        
        
        form = blogForms.newPageForm(request.POST)
        #Check if there is an image
        if 'image' in request.FILES:
            image = request.FILES['image']
        else:
            image = None
        #saves post, returning an error if failed
        error = save(request, form, image, "Page")
        if not error:
            return HttpResponseRedirect('/')
    
    else:
        form = blogForms.newPageForm()
    return render_to_response("dashboard/newpage.html", {"form":form, "error": error, "username": username, "action":"newpage"}, context_instance = RequestContext(request))
Пример #15
0
def archive(request, year):
    
    # Gets logged in user
    username = util.checkLoggedIn(request)
    
    # Gets all of the posts
    posts = Post.objects.filter(published__year=year).order_by('-published')
    
    
    # Gets templates and sets appropriate template
    template = "base.html"
    page_template = "index.html"
    
    if request.is_ajax():
        template = page_template
    
    # Loads all pages
    pages = Page.objects.all().order_by("id")
    
    # Renders the page
    if len(posts) > 0:
        return render_to_response(template, {"posts" : posts, "pages":pages, "username": username}, context_instance=RequestContext(request))
    else:
        raise Http404
Пример #16
0
def getArticles(request):

    user = util.checkLoggedIn(request)

    if user:

        access_token = PocketKey.objects.get(User=user).key

        values = {"consumer_key": CONSUMER_KEY, "access_token": access_token}

        data = urllib.urlencode(values)
        req = urllib2.Request(retrieveUrl, data)

        response = urllib2.urlopen(req)

        data = json.loads(response.read())

        outputlist = []

        for i in data["list"]:
            output = {"output": "", "added": ""}
            k = 0
            inserted = False
            title = data["list"][i]["resolved_title"]
            url = data["list"][i]["resolved_url"]
            excerpt = data["list"][i]["excerpt"]
            output["output"] = (
                '<a class="starredLink" target="_blank" href="'
                + url
                + '"><div class="starredItem">'
                + title
                + '<div class="excerpt"> - '
                + excerpt
                + "</div></div></a>"
            )
            output["added"] = data["list"][i]["time_added"]
            while k < len(outputlist):

                if outputlist[k]["added"] >= output["added"]:
                    k += 1
                else:
                    # print output
                    outputlist.insert(k, output)
                    inserted = True
                    break

            if inserted == False:
                # print output
                outputlist.append(output)

        outputString = ""

        # print outputlist

        for j in outputlist:
            # print j
            outputString += j["output"]

        return HttpResponse(outputString)

    else:

        return "Not Logged In"
Пример #17
0
def index(request):

    # Check if user is on IE 8
    ie = False
    if request.META.has_key('HTTP_USER_AGENT'):
        user_agent = request.META['HTTP_USER_AGENT']
        if user_agent.find('MSIE 8.0') != -1:
            ie = True
    
    # Checks if a user is logged in
    username = util.checkLoggedIn(request)
    
    # Queries the database
    posts = Post.objects.all().order_by("-published")
    
    # Gets the templates
    template = "base.html"
    page_template = "index.html"
    
    # If the request is coming from an ajax request
    # and sets the template accordingly
    if request.is_ajax():
        template = page_template
    

    # Get featured posts
    featured = []
    cats = []
    for i in range(0,4):
        try:
            featured.append(Featured.objects.filter().order_by('-Post__published')[i])
            feature = Featured.objects.filter().order_by('-Post__published')[i]
            categories = Categories.objects.filter(Post__title=feature.Post.title)
            added = False
            for i in categories:
                if not (str(i) == 'News' or str(i) == 'Editorial'):
                    cats.append(i)
                    added = True
                    break
                if added:
                    break
            done = False
            if not added:
                for i in categories:
                    if str(i) == 'Editorial':
                        cats.append('Editorial')
                        done = True

                if not done:
                    cats.append('News')

        except IndexError:
            pass

    # dfs
    
    # Gets all of the pages
    pages = Page.objects.all().order_by("id")
    
    # Renders the page
    
    # If on IE, show message asking user to use another broswer
    if not ie:
        return render_to_response(template, {"posts" : posts, "pages":pages, "username": username, "featured": featured, "cats":cats}, context_instance=RequestContext(request))
    else:
        return render_to_response('ie.html')
Пример #18
0
def search(request):
    pages = Page.objects.all()
    username = util.checkLoggedIn(request)
    return render_to_response("search.html", {"username": username, "pages": pages})