def add_software(request): """ Show the software form, and capture the information """ if not request.user.is_authenticated(): return HttpResponseRedirect('/accounts/login?next=%s' % request.path) original_id = request.GET.get('oid', None) if request.method == 'POST': new_data = request.POST.copy() new_data.update(request.FILES) form = SoftwareForm(new_data) if form.is_valid(): new_software = Software(user=request.user, title=form.cleaned_data['title']) if original_id: new_software.original_id = original_id new_software.save() try: new_revision = Revision( software=new_software, version=form.cleaned_data['version'], authors=form.cleaned_data['authors'], contact=form.cleaned_data['contact'], short_description=form.cleaned_data['short_description'], description=form.cleaned_data['description'], changes='Initial Announcement on mloss.org.', project_url=form.cleaned_data['project_url'], tags=form.cleaned_data['tags'], language=form.cleaned_data['language'], operating_systems=form.cleaned_data['operating_systems'], dataformats=form.cleaned_data['dataformats'], os_license=form.cleaned_data['os_license'], paper_bib=form.cleaned_data['paper_bib'], download_url=form.cleaned_data['download_url'], tarball=form.cleaned_data['tarball'], thumbnail=form.cleaned_data['thumbnail'], screenshot=form.cleaned_data['screenshot'], ) if original_id: new_revision.original_id = original_id save_tarball(request, new_revision) save_images(request, new_revision, old_revision=None) new_revision.save() return HttpResponseRedirect(new_revision.get_absolute_url()) except: new_software.delete() else: form = SoftwareForm(initial={ 'user': request.user, 'changes': 'Initial Announcement on mloss.org.' }) return render_to_response('software/software_add.html', {'form': form}, context_instance=RequestContext(request))
def add_software(request): """ Show the software form, and capture the information """ if not request.user.is_authenticated(): return HttpResponseRedirect('/accounts/login?next=%s' % request.path) original_id = request.GET.get('oid', None) if request.method == 'POST': new_data = request.POST.copy() new_data.update(request.FILES) form = SoftwareForm(new_data) if form.is_valid(): new_software = Software(user=request.user, title=form.cleaned_data['title']) if original_id: new_software.original_id = original_id new_software.save() try: new_revision = Revision(software=new_software, version=form.cleaned_data['version'], authors=form.cleaned_data['authors'], contact=form.cleaned_data['contact'], short_description=form.cleaned_data['short_description'], description=form.cleaned_data['description'], changes='Initial Announcement on mloss.org.', project_url=form.cleaned_data['project_url'], tags=form.cleaned_data['tags'], language=form.cleaned_data['language'], operating_systems = form.cleaned_data['operating_systems'], dataformats = form.cleaned_data['dataformats'], os_license=form.cleaned_data['os_license'], paper_bib = form.cleaned_data['paper_bib'], download_url=form.cleaned_data['download_url'], tarball=form.cleaned_data['tarball'], thumbnail=form.cleaned_data['thumbnail'], screenshot=form.cleaned_data['screenshot'], ) if original_id: new_revision.original_id = original_id save_tarball(request, new_revision) save_images(request, new_revision, old_revision = None) new_revision.save() return HttpResponseRedirect(new_revision.get_absolute_url()) except: new_software.delete() else: form = SoftwareForm(initial={'user':request.user, 'changes':'Initial Announcement on mloss.org.'}) return render_to_response('software/software_add.html', { 'form': form }, context_instance=RequestContext(request))
def edit_software(request, software_id, revision_id=0): """ Show the software form, and capture the information """ if not request.user.is_authenticated(): return HttpResponseRedirect('/accounts/login?next=%s' % request.path) original_id = request.GET.get('oid', None) if request.user.is_superuser: software = get_object_or_404(Software, pk=software_id) else: software = get_object_or_404(Software, pk=software_id, user__pk=request.user.id) if revision_id: revision = get_object_or_404(Revision, pk=revision_id, software = software) form_class = RevisionForm else: revision = software.get_latest_revision() form_class = UpdateSoftwareForm form=form_class(revision) if request.method == 'POST': new_data = request.POST.copy() new_data.update(request.FILES) form = form_class(new_data) if form.is_valid(): if form.cleaned_data['title'] != software.title or ( revision_id and form.cleaned_data['version'] != revision.version ): return HttpResponseForbidden() new_revision = Revision(software=software, version=form.cleaned_data['version'], authors=form.cleaned_data['authors'], contact=form.cleaned_data['contact'], short_description=form.cleaned_data['short_description'], description=form.cleaned_data['description'], changes=form.cleaned_data['changes'], project_url=form.cleaned_data['project_url'], tags=form.cleaned_data['tags'], language=form.cleaned_data['language'], operating_systems = form.cleaned_data['operating_systems'], dataformats = form.cleaned_data['dataformats'], os_license=form.cleaned_data['os_license'], paper_bib = form.cleaned_data['paper_bib'], download_url=form.cleaned_data['download_url'], tarball=form.cleaned_data['tarball'], thumbnail=form.cleaned_data['thumbnail'], screenshot=form.cleaned_data['screenshot'], ) if original_id: new_revision.original_id = original_id if new_revision.version != revision.version: for field in editables: if not field in dontupdateifempty or form.cleaned_data[field]: setattr(new_revision, field, form.cleaned_data[field]) new_revision.jmlr_mloss_url = revision.jmlr_mloss_url if form.cleaned_data['download_url'] and len(form.cleaned_data['download_url'])>0: new_revision.tarball = None else: save_tarball(request, new_revision) save_images(request, new_revision, old_revision=revision) software.increment_revisions() new_revision.save() return HttpResponseRedirect(new_revision.get_absolute_url()) else: for field in editables: if not field in dontupdateifempty or form.cleaned_data[field]: setattr(revision, field, form.cleaned_data[field]) if form.cleaned_data['download_url'] and len(form.cleaned_data['download_url'])>0: revision.tarball = None else: save_tarball(request, revision) save_images(request, revision, old_revision = revision) revision.save(silent_update=True) return HttpResponseRedirect(revision.get_absolute_url()) else: form = form_class(revision) return render(request, 'software/software_add.html', { 'form': form })
def edit_software(request, software_id, revision_id=0): """ Show the software form, and capture the information """ if not request.user.is_authenticated(): return HttpResponseRedirect('/accounts/login?next=%s' % request.path) original_id = request.GET.get('oid', None) if request.user.is_superuser: software = get_object_or_404(Software, pk=software_id) else: software = get_object_or_404(Software, pk=software_id, user__pk=request.user.id) if revision_id: revision = get_object_or_404(Revision, pk=revision_id, software=software) form_class = RevisionForm else: revision = software.get_latest_revision() form_class = UpdateSoftwareForm if request.method == 'POST': new_data = request.POST.copy() new_data.update(request.FILES) form = form_class(new_data) if form.is_valid(): if form.cleaned_data['title'] != software.title or ( revision_id and form.cleaned_data['version'] != revision.version): return HttpResponseForbidden() new_revision = Revision( software=software, version=form.cleaned_data['version'], authors=form.cleaned_data['authors'], contact=form.cleaned_data['contact'], short_description=form.cleaned_data['short_description'], description=form.cleaned_data['description'], changes=form.cleaned_data['changes'], project_url=form.cleaned_data['project_url'], tags=form.cleaned_data['tags'], language=form.cleaned_data['language'], operating_systems=form.cleaned_data['operating_systems'], dataformats=form.cleaned_data['dataformats'], os_license=form.cleaned_data['os_license'], paper_bib=form.cleaned_data['paper_bib'], download_url=form.cleaned_data['download_url'], tarball=form.cleaned_data['tarball'], thumbnail=form.cleaned_data['thumbnail'], screenshot=form.cleaned_data['screenshot'], ) if original_id: new_revision.original_id = original_id if new_revision.version != revision.version: for field in editables: if not field in dontupdateifempty or form.cleaned_data[ field]: setattr(new_revision, field, form.cleaned_data[field]) new_revision.jmlr_mloss_url = revision.jmlr_mloss_url if form.cleaned_data['download_url'] and len( form.cleaned_data['download_url']) > 0: new_revision.tarball = None else: save_tarball(request, new_revision) save_images(request, new_revision, old_revision=revision) software.increment_revisions() new_revision.save() return HttpResponseRedirect(new_revision.get_absolute_url()) else: for field in editables: if not field in dontupdateifempty or form.cleaned_data[ field]: setattr(revision, field, form.cleaned_data[field]) if form.cleaned_data['download_url'] and len( form.cleaned_data['download_url']) > 0: revision.tarball = None else: save_tarball(request, revision) save_images(request, revision, old_revision=revision) revision.save(silent_update=True) return HttpResponseRedirect(revision.get_absolute_url()) else: form = form_class(revision) return render_to_response('software/software_add.html', {'form': form}, context_instance=RequestContext(request))