Example #1
0
def edit_entry(request, entry_id):
    """Entry edit page"""
    initial = {"query": "search"}
    form = SearchForm(initial=initial)
    e = get_object_or_404(Entry, id=entry_id)
    if request.user.id == e.author.id:
        i = get_object_or_404(Item, id=e.belong.id)
        if request.POST:
            entryform = EntryForm(request.POST)
            if entryform.is_valid():
                e = entryform.saveAs(request, e)
                entryform = EntryForm()
                ctx = {
                    "item": i,
                    "entries": i.entries.all(),
                    "hot_items": hot_items(),
                    "entryform": entryform,
                    "form": form,
                }
                return render_to_response("user.html", ctx, RequestContext(request))
        else:
            entryform = EntryForm({"content": e.content})
            ctx = {"entry": e, "hot_items": hot_items(), "entryform": entryform, "form": form}
            return render_to_response("edit_entry.html", ctx, RequestContext(request))
    else:
        ctx = {
            "hot_items": hot_items(),
            "error_name": "You can not edit this entry, you are not the author of this. If it is necessary, please contact with the admin on gmail@grgizem ",
            "form": form,
        }
        return render_to_response("error_log.html", ctx, RequestContext(request))
Example #2
0
def add_entry(request, item_id):
    """Add entry page"""
    initial = {"query": "search"}
    form = SearchForm(initial=initial)
    item = get_object_or_404(Item, id=item_id)
    if request.POST:
        entryform = EntryForm(request.POST)
        if entryform.is_valid():
            entryform.save(request, item)
    else:
        entryform = EntryForm()
    ctx = {"item": item, "entries": item.entries.all(), "hot_items": hot_items(), "entryform": entryform, "form": form}
    return render_to_response("user.html", ctx, RequestContext(request))