def submit(request, object_id): cycle = get_object_or_404(Cycle, pk=object_id) user = request.user proposal_form = ProposalForm(initial={'author': request.user}) today = datetime.datetime.now() if request.method == 'POST': proposal_form = ProposalForm(request.POST, request.FILES or None, initial={'author': request.user}) if proposal_form.is_valid(): user.first_name = request.POST['first_name'] user.last_name = request.POST['last_name'] user.save() proposal = proposal_form.save(commit=False) proposal.cycle = cycle proposal.author = user proposal.email = user.email proposal.username = user.get_full_name() if proposal.cycle.is_tumblr_commission: proposal.is_public = False proposal.allow_comments = False proposal.save() # verification of artist accounts for m2m is handled via the form cleaned_user_list = proposal_form.cleaned_data[ 'other_artists_users'] if cleaned_user_list: for user in cleaned_user_list: proposal.artists.add(user) proposal.save() if proposal.image: # create_thumbnails uses saved image proposal.thumbnail = create_thumbnail(proposal.image) if request.POST['status'] == 'preview': proposal.save() return redirect('commissions_proposal_preview', proposal_id=proposal.id) elif request.POST['status'] == 'save': proposal.save() return HttpResponseRedirect( '%s?save=True' % reverse('commissions_proposal_edit', args=[proposal.id])) elif request.POST['status'] == 'publish': proposal.submitted = 1 proposal.save() proposal.send_published_proposal_notification_email() return HttpResponseRedirect( '%s?thanks=True' % reverse('commissions_proposal_detail', args=[proposal.id])) else: proposal_form = ProposalForm(request.POST, request.FILES or None, initial={'author': request.user}) if today > cycle.submission_start_date and today < cycle.submission_end_date: return render_to_response('commissions/submit.html', { 'proposal_form': proposal_form, 'cycle': cycle, }, RequestContext(request)) else: return redirect('commissions_index')
def edit(request, type, id): context = RequestContext(request) username = request.user.get_profile() #CHECK THE TYPE, GRAB OBJECT OR CATCH MISSING INFO if type == 'opportunities': announcement = get_object_or_404(Opportunity, id=id, is_spam=False) announcement_form = OpportunityForm( request.POST or None, request.FILES or None, instance=announcement, initial={'username':username} ) elif type == 'jobs': announcement = get_object_or_404(Job, id=id, is_spam=False) announcement_form = JobForm( request.POST or None, request.FILES or None, instance=announcement, initial={'username':username} ) elif type == 'events': announcement = get_object_or_404(Event, id=id, is_spam=False) announcement_form = EventForm( request.POST or None, request.FILES or None, instance=announcement, initial={'username':username} ) else: raise Http404 if not announcement.can_edit(): # can only edit if announcement less than 2 wks old... return HttpResponseRedirect(reverse('announce_index')) else: # MAKE SURE THE USER OWNS THE ANNOUNCEMENT if request.user != announcement.user: return HttpResponseRedirect(reverse('announce_index')) else: # HANDLE THE POST if request.method == 'POST': if request.POST.get("form-type") == "opportunity-form": announcement_form = OpportunityForm( request.POST, request.FILES or None, instance=announcement, initial={'username':username} ) if request.POST.get("form-type") == "job-form": announcement_form = JobForm( request.POST, request.FILES or None, instance=announcement, initial={'username':username} ) if request.POST.get("form-type") == "event-form": announcement_form = EventForm( request.POST, request.FILES or None, instance=announcement, initial={'username':username} ) if announcement_form.is_valid(): announcement = announcement_form.save(commit=False) announcement.user_id = request.user.id announcement.ip_address = request.META["REMOTE_ADDR"] if request.POST.get("delete_image"): if announcement.image: import os if os.path.exists(announcement.image.path): os.remove(announcement.image.path) announcement.image = None #save now so can create thumbanail with id in title announcement.save() if announcement.image and not announcement.thumbnail: announcement.thumbnail = create_thumbnail(announcement.image) announcement.save() #### # if announcement is not yet published #### if request.POST.get("status") == "preview": announcement.status = False announcement.save() return HttpResponseRedirect(reverse(preview, kwargs={'type':type, 'id':announcement.id})) if request.POST.get("status") == "publish": if type == 'jobs' and not announcement.is_paid() and not request.user.get_profile().is_member(): return HttpResponseRedirect(reverse(job_payment)) if not moderator.process(announcement, request): announcement.status = True announcement.save() send_to_announce_mailing_list(announcement.__class__, announcement, created=True) return HttpResponseRedirect(reverse(thanks, kwargs={'type':type,'id':announcement.id})) #### # if announcement is published #### if request.POST.get("status") == "unpublish": announcement.status = False announcement.save() #return HttpResponseRedirect('/announce/%s/%s/preview/' % (type, announcement.id)) return HttpResponseRedirect(reverse(edit,kwargs={'type':type,'id':announcement.id})) if request.POST.get("status") == "update": moderator.process(announcement, request) #return HttpResponseRedirect('/announce/%s/%s/preview/' % (type, announcement.id)) return HttpResponseRedirect(reverse(thanks,kwargs={'type':type,'id':announcement.id})) else: if type == 'opportunities': announcement_form = OpportunityForm(request.POST) if type == 'jobs': announcement_form = JobForm(request.POST) if type == 'events': announcement_form = EventForm(request.POST) return render_to_response( "announce/submit.html", {"announcement_form":announcement_form, "type": type }, context )
def proposal_edit(request, proposal_id): proposal = get_object_or_404(Proposal, pk=proposal_id) user = request.user proposal_form = ProposalForm(initial={'author': request.user}) other_artists_list = None today = datetime.datetime.now() if proposal.get_artists(): other_artists_list = ', '.join( ['%s' % artist.email for artist in proposal.get_artists()]) proposal_form = ProposalForm(request.POST or None, request.FILES or None, \ instance=proposal.id and Proposal.objects.get(id=proposal.id ), \ initial={'other_artists_users':other_artists_list }) if request.method == 'POST': proposal_form = ProposalForm(request.POST or None, request.FILES or None, \ instance=proposal.id and Proposal.objects.get(id=proposal.id ), \ initial={'other_artists_users':str(other_artists_list) }) if proposal_form.is_valid(): user.first_name = request.POST['first_name'] user.last_name = request.POST['last_name'] user.save() proposal = proposal_form.save(commit=False) if request.POST['status'] == 'delete': proposal.delete() return HttpResponseRedirect('%s?deleted=True' % reverse('commissions_index')) proposal.author = user proposal.email = user.email proposal.username = user.get_full_name() # verification of artist accounts for m2m is handled via the form cleaned_user_list = proposal_form.cleaned_data[ 'other_artists_users'] if cleaned_user_list: for user in cleaned_user_list: proposal.artists.add(user) proposal.save() if proposal.image: # create_thumbnails uses saved image proposal.thumbnail = create_thumbnail(proposal.image) if request.POST['status'] == 'preview': proposal.save() return redirect('commissions_proposal_preview', proposal_id=proposal.id) elif request.POST['status'] == 'save': proposal.save() return HttpResponseRedirect( '%s?save=True' % reverse('commissions_proposal_edit', args=[proposal.id])) elif request.POST['status'] == 'publish': proposal.submitted = 1 proposal.save() proposal.send_published_proposal_notification_email() return HttpResponseRedirect( '%s?thanks=True' % reverse('commissions_proposal_detail', args=[proposal.id])) else: proposal_form = ProposalForm(request.POST, request.FILES or None, initial={'author': request.user}) if request.user == proposal.author \ and today > proposal.cycle.submission_start_date \ and today < proposal.cycle.submission_end_date: return render_to_response('commissions/submit.html', { 'proposal_form': proposal_form, 'cycle': proposal.cycle }, RequestContext(request)) else: return redirect('commissions_index')
def submit(request, type = None): context = RequestContext(request) if type == 'opportunities': announcement_form = OpportunityForm() if type == 'jobs': announcement_form = JobForm() if type == 'events': announcement_form = EventForm() if type == None: type = "opportunities" announcement_form = OpportunityForm() if request.method == 'POST': if request.POST.get("form-type") == "opportunity-form": announcement_form = OpportunityForm(request.POST, request.FILES or None) if request.POST.get("form-type") == "job-form": announcement_form = JobForm(request.POST, request.FILES or None) if request.POST.get("form-type") == "event-form": announcement_form = EventForm(request.POST, request.FILES or None) if announcement_form.is_valid(): announcement = announcement_form.save(commit=False) announcement.user_id = request.user.id announcement.username = strip_tags(request.user.get_profile()) announcement.title = strip_tags(announcement.title) announcement.url = strip_tags(announcement.url) announcement.description = strip_tags(announcement.description) announcement.subtype = strip_tags(announcement.subtype) announcement.ip_address = request.META["REMOTE_ADDR"] announcement.status = False #save now so can create thumbanail with id in title announcement.save() if announcement.image: #create_thumbnails uses saved image announcement.thumbnail = create_thumbnail(announcement.image) announcement.save()#save again after creating thumbnail if request.POST.get("status") == "preview": #return HttpResponseRedirect('/announce/%s/%s/preview/' % (type, announcement.id)) return HttpResponseRedirect(reverse(preview,kwargs={'type':type,'id':announcement.id})) elif request.POST.get("status") == "publish": if type == 'jobs' and not announcement.is_paid() and not request.user.get_profile().is_member(): return HttpResponseRedirect(reverse(job_payment)) if not moderator.process(announcement, request): announcement.status = True announcement.save() send_to_announce_mailing_list(announcement.__class__, announcement, created=True) return HttpResponseRedirect(reverse(thanks, kwargs={'type':type,'id':announcement.id})) return render_to_response( "announce/submit.html", {"announcement_form":announcement_form, "type":type}, context )
def submit(request, object_id): cycle = get_object_or_404(Cycle, pk=object_id) user = request.user proposal_form = ProposalForm(initial={'author':request.user}) today = datetime.datetime.now() if request.method == 'POST': proposal_form = ProposalForm(request.POST, request.FILES or None, initial={'author':request.user}) if proposal_form.is_valid(): user.first_name = request.POST['first_name'] user.last_name = request.POST['last_name'] user.save() proposal = proposal_form.save(commit=False) proposal.cycle = cycle proposal.author = user proposal.email = user.email proposal.username = user.get_full_name() if proposal.cycle.is_tumblr_commission: proposal.is_public = False proposal.allow_comments = False proposal.save() # verification of artist accounts for m2m is handled via the form cleaned_user_list = proposal_form.cleaned_data['other_artists_users'] if cleaned_user_list: for user in cleaned_user_list: proposal.artists.add(user) proposal.save() if proposal.image: # create_thumbnails uses saved image proposal.thumbnail = create_thumbnail(proposal.image) if request.POST['status'] == 'preview': proposal.save() return redirect('commissions_proposal_preview', proposal_id=proposal.id) elif request.POST['status'] == 'save': proposal.save() return HttpResponseRedirect('%s?save=True' % reverse('commissions_proposal_edit', args=[proposal.id])) elif request.POST['status'] == 'publish': proposal.submitted = 1 proposal.save() proposal.send_published_proposal_notification_email() return HttpResponseRedirect('%s?thanks=True' % reverse('commissions_proposal_detail', args=[proposal.id])) else: proposal_form = ProposalForm(request.POST,request.FILES or None, initial={'author':request.user}) if today > cycle.submission_start_date and today < cycle.submission_end_date: return render_to_response( 'commissions/submit.html', { 'proposal_form': proposal_form, 'cycle': cycle, }, RequestContext(request) ) else: return redirect('commissions_index')
def proposal_edit(request, proposal_id): proposal = get_object_or_404(Proposal, pk=proposal_id) user = request.user proposal_form = ProposalForm(initial={'author':request.user}) other_artists_list = None today = datetime.datetime.now() if proposal.get_artists(): other_artists_list = ', '.join(['%s' % artist.email for artist in proposal.get_artists()]) proposal_form = ProposalForm(request.POST or None, request.FILES or None, \ instance=proposal.id and Proposal.objects.get(id=proposal.id ), \ initial={'other_artists_users':other_artists_list }) if request.method == 'POST': proposal_form = ProposalForm(request.POST or None, request.FILES or None, \ instance=proposal.id and Proposal.objects.get(id=proposal.id ), \ initial={'other_artists_users':str(other_artists_list) }) if proposal_form.is_valid(): user.first_name = request.POST['first_name'] user.last_name = request.POST['last_name'] user.save() proposal = proposal_form.save(commit=False) if request.POST['status'] == 'delete': proposal.delete() return HttpResponseRedirect('%s?deleted=True' % reverse('commissions_index')) proposal.author = user proposal.email = user.email proposal.username = user.get_full_name() # verification of artist accounts for m2m is handled via the form cleaned_user_list = proposal_form.cleaned_data['other_artists_users'] if cleaned_user_list: for user in cleaned_user_list: proposal.artists.add(user) proposal.save() if proposal.image: # create_thumbnails uses saved image proposal.thumbnail = create_thumbnail(proposal.image) if request.POST['status'] == 'preview': proposal.save() return redirect('commissions_proposal_preview', proposal_id=proposal.id) elif request.POST['status'] == 'save': proposal.save() return HttpResponseRedirect('%s?save=True' % reverse('commissions_proposal_edit', args=[proposal.id])) elif request.POST['status'] == 'publish': proposal.submitted = 1 proposal.save() proposal.send_published_proposal_notification_email() return HttpResponseRedirect('%s?thanks=True' % reverse('commissions_proposal_detail', args=[proposal.id])) else: proposal_form = ProposalForm(request.POST,request.FILES or None, initial={'author':request.user}) if request.user == proposal.author \ and today > proposal.cycle.submission_start_date \ and today < proposal.cycle.submission_end_date: return render_to_response('commissions/submit.html', {'proposal_form':proposal_form, 'cycle':proposal.cycle}, RequestContext(request)) else: return redirect('commissions_index')
def edit(request, type, id): context = RequestContext(request) username = request.user.get_profile() #CHECK THE TYPE, GRAB OBJECT OR CATCH MISSING INFO if type == 'opportunities': announcement = get_object_or_404(Opportunity, id=id, is_spam=False) announcement_form = OpportunityForm(request.POST or None, request.FILES or None, instance=announcement, initial={'username': username}) elif type == 'jobs': announcement = get_object_or_404(Job, id=id, is_spam=False) announcement_form = JobForm(request.POST or None, request.FILES or None, instance=announcement, initial={'username': username}) elif type == 'events': announcement = get_object_or_404(Event, id=id, is_spam=False) announcement_form = EventForm(request.POST or None, request.FILES or None, instance=announcement, initial={'username': username}) else: raise Http404 if not announcement.can_edit(): # can only edit if announcement less than 2 wks old... return HttpResponseRedirect(reverse('announce_index')) else: # MAKE SURE THE USER OWNS THE ANNOUNCEMENT if request.user != announcement.user: return HttpResponseRedirect(reverse('announce_index')) else: # HANDLE THE POST if request.method == 'POST': if request.POST.get("form-type") == "opportunity-form": announcement_form = OpportunityForm( request.POST, request.FILES or None, instance=announcement, initial={'username': username}) if request.POST.get("form-type") == "job-form": announcement_form = JobForm(request.POST, request.FILES or None, instance=announcement, initial={'username': username}) if request.POST.get("form-type") == "event-form": announcement_form = EventForm( request.POST, request.FILES or None, instance=announcement, initial={'username': username}) if announcement_form.is_valid(): announcement = announcement_form.save(commit=False) announcement.user_id = request.user.id announcement.ip_address = request.META["REMOTE_ADDR"] if request.POST.get("delete_image"): if announcement.image: import os if os.path.exists(announcement.image.path): os.remove(announcement.image.path) announcement.image = None #save now so can create thumbanail with id in title announcement.save() if announcement.image and not announcement.thumbnail: announcement.thumbnail = create_thumbnail( announcement.image) announcement.save() #### # if announcement is not yet published #### if request.POST.get("status") == "preview": announcement.status = False announcement.save() return HttpResponseRedirect( reverse(preview, kwargs={ 'type': type, 'id': announcement.id })) if request.POST.get("status") == "publish": if type == 'jobs' and not announcement.is_paid( ) and not request.user.get_profile().is_member(): return HttpResponseRedirect(reverse(job_payment)) if not moderator.process(announcement, request): announcement.status = True announcement.save() send_to_announce_mailing_list( announcement.__class__, announcement, created=True) return HttpResponseRedirect( reverse(thanks, kwargs={ 'type': type, 'id': announcement.id })) #### # if announcement is published #### if request.POST.get("status") == "unpublish": announcement.status = False announcement.save() #return HttpResponseRedirect('/announce/%s/%s/preview/' % (type, announcement.id)) return HttpResponseRedirect( reverse(edit, kwargs={ 'type': type, 'id': announcement.id })) if request.POST.get("status") == "update": moderator.process(announcement, request) #return HttpResponseRedirect('/announce/%s/%s/preview/' % (type, announcement.id)) return HttpResponseRedirect( reverse(thanks, kwargs={ 'type': type, 'id': announcement.id })) else: if type == 'opportunities': announcement_form = OpportunityForm(request.POST) if type == 'jobs': announcement_form = JobForm(request.POST) if type == 'events': announcement_form = EventForm(request.POST) return render_to_response("announce/submit.html", { "announcement_form": announcement_form, "type": type }, context)
def submit(request, type=None): context = RequestContext(request) if type == 'opportunities': announcement_form = OpportunityForm() if type == 'jobs': announcement_form = JobForm() if type == 'events': announcement_form = EventForm() if type == None: type = "opportunities" announcement_form = OpportunityForm() if request.method == 'POST': if request.POST.get("form-type") == "opportunity-form": announcement_form = OpportunityForm(request.POST, request.FILES or None) if request.POST.get("form-type") == "job-form": announcement_form = JobForm(request.POST, request.FILES or None) if request.POST.get("form-type") == "event-form": announcement_form = EventForm(request.POST, request.FILES or None) if announcement_form.is_valid(): announcement = announcement_form.save(commit=False) announcement.user_id = request.user.id announcement.username = strip_tags(request.user.get_profile()) announcement.title = strip_tags(announcement.title) announcement.url = strip_tags(announcement.url) announcement.description = strip_tags(announcement.description) announcement.subtype = strip_tags(announcement.subtype) announcement.ip_address = request.META["REMOTE_ADDR"] announcement.status = False #save now so can create thumbanail with id in title announcement.save() if announcement.image: #create_thumbnails uses saved image announcement.thumbnail = create_thumbnail(announcement.image) announcement.save() #save again after creating thumbnail if request.POST.get("status") == "preview": #return HttpResponseRedirect('/announce/%s/%s/preview/' % (type, announcement.id)) return HttpResponseRedirect( reverse(preview, kwargs={ 'type': type, 'id': announcement.id })) elif request.POST.get("status") == "publish": if type == 'jobs' and not announcement.is_paid( ) and not request.user.get_profile().is_member(): return HttpResponseRedirect(reverse(job_payment)) if not moderator.process(announcement, request): announcement.status = True announcement.save() send_to_announce_mailing_list(announcement.__class__, announcement, created=True) return HttpResponseRedirect( reverse(thanks, kwargs={ 'type': type, 'id': announcement.id })) return render_to_response("announce/submit.html", { "announcement_form": announcement_form, "type": type }, context)