Пример #1
0
def update_info(request, update_id):

    if request.method == "POST":

        if not request.user.is_authenticated():
            return HttpResponse("error: must be logged in to edit")

        try:
            update = Update.objects.get(id=update_id)
            if (not request.user.is_staff) and update.author != request.user:
                return HttpResponse("error: no edit permissions, must be author or staff") 
            
        except:
            update = Update(type="blog",
                    author=request.user)

        update.title = request.POST.get("title")
        update.content = request.POST.get("content")

        project_id = request.POST.get("project", "")
        if project_id:
            try:
                if update.project:
                    update.project.remove_update(update)
                project = Project.objects.get(id=project_id)
                update.project = project
                update.type="dev log"
            except:
                update.project = None

        update.save()

        if request.FILES.get("thumbnail"):
            if not update.thumbnail: 
                thumbnail = Image()
            else:
                thumbnail = update.thumbnail

            thumbnail.data = request.FILES.get("thumbnail")
            thumbnail.save() 

            update.thumbnail = thumbnail
            update.save()

            logging.info("$$$ saved update thumbnail: %s" % update.thumbnail.id)
        else:
            logging.info("$$$ no request.FILES.get('thumbnail') :(")
            for f in request.FILES:
                logging.info("$$$$$ %s" % f)

        logging.info("$$$ saved update: %s" % update.id)

        return HttpResponseRedirect("/blurb/%s/" % update.id)

    update = get_object_or_404(Update, id=update_id) 

    if update.type == "new project" or update.type == "pitch":

        # updates about a new project don't have their own content,
        # but rather link straight to the project in question
        return HttpResponseRedirect("/project/%s/" % update.project.id)

    is_edit = request.GET.get("edit")

    if request.is_ajax(): 
        if is_edit:
            return render_to_response("new_blog.html", locals(), context_instance=RequestContext(request))

        return render_to_response("update.html", locals())

    else:
        url = '/blurb/%s/' % update_id
        if is_edit:
            url = "%s?edit=t" % url
        request.session['info_ajax_url'] = url

        return HttpResponseRedirect("/") 
Пример #2
0
def project_info(request, project_id=None):

    statuses = STATUS_OPTIONS

    if request.method == "POST": 
        # TODO: check user is authenticated
        # TODO: check edit permissions

        # ajax save of new project info, create updates if relevant
        project_id = request.POST.get("project", None)
        if project_id:
            project = Project.objects.get(id=project_id)
        else:
            project = Project()

        project.title = request.POST.get("title")
        project.status = request.POST.get("status")
        project.pitch = request.POST.get("pitch")

        new_videos = []
        for key in request.POST:

            if key.startswith('development_video_url'):
                if request.POST.get(key):
                    num = key.split('_')[-1]
                    vid = Video(url=request.POST.get(key),
                            title=request.POST.get("development_video_description_%s" % num, "Development video"))
                    vid.save()
                    new_videos.append(vid)
                    project.development_video_ids.append(vid.id)
                    project.save()

            elif key.startswith('launch_video_url'):
                if request.POST.get(key):
                    logging.info("got a lunch video")
                    num = key.split('_')[-1]
                    vid = Video(url=request.POST.get(key),
                            title=request.POST.get("launch_video_description_%s" % num, "Development video"))
                    vid.save()
                    new_videos.append(vid)
                    logging.info("made a vid: %s" % vid.id)
                    project.launch_video_ids.append(vid.id)
                    project.save()

        thumb_data = request.FILES.get("thumbnail")
        if thumb_data:
            thumbnail = project.thumbnail
            if not thumbnail: 
                thumbnail = Image()
            thumbnail.data = thumb_data
            thumbnail.save() 

            project.thumbnail = thumbnail
            project.save()
            
        logging.info("__*__ bout to check request.files: %s" % request.FILES)
        new_images = []
        for f in request.FILES:
            logging.info("___*___ File: %s" % f)

            if f.startswith("development_media"):
                image = Image(data=request.FILES.get(f))
                image.save()
                project.development_screenshot_ids.append(image.id)
                new_images.append(image)
            elif f.startswith("launch_media"):
                image = Image(data=request.FILES.get(f))
                image.save()
                project.launch_screenshot_ids.append(image.id)
                new_images.append(image)


        project.save()
        if project.id not in request.user.get_profile().owned_project_ids:
            request.user.get_profile().owned_project_ids.append(project.id)
            request.user.get_profile().save()

        if not project_id:
            # create a 'new project' update
            update = Update(type="new project",
                    title="Introducing %s" % project.title,
                    author=request.user,
                    project=project,
                    content=project.pitch[:140],
                    is_published=False)
            update.save()

        if new_images:

            gallery_markdown = ""

            for new_image in new_images:
                gallery_markdown = """%s
<img src='%s' />""" % ( gallery_markdown, new_image.url())

            update = Update(type="screenshots",
                    title="New screenshots",
                    author=request.user,
                    project=project,
                    content=gallery_markdown,
                    is_published=False,
                    order=1)
            update.save()

        if new_videos:
            content = "" 
            i = 0
            for video in new_videos:
                content = "%s<p>%s <a href='%s'>youtube</a></p>" % (content, video.title, video.url)
                i += 1
            update = Update(type="video",
                    title="New video",
                    author=request.user,
                    project=project,
                    content=content,
                    is_published=False,
                    order=2)
            update.save() 

        return HttpResponseRedirect("/project/%s/" % project.id)


    # TODO: check user's edit permissions
    is_edit = request.GET.get("edit", False)
    if not project_id or project_id == "new": 
        is_edit = True

    if request.is_ajax(): 
        project = None
        if project_id:
            project = get_object_or_404(Project, id=project_id) 
        if is_edit:
            return render_to_response("project_edit.html", locals(), context_instance=RequestContext(request))
        else:
            return render_to_response("project.html", locals())

    else:
        proj = project_id
        if not project_id:
            proj = "new"
        url = '/project/%s/' % proj
        if is_edit:
            url = "%s?edit=t" % url
        request.session['info_ajax_url'] = url

        return HttpResponseRedirect("/")