Esempio n. 1
0
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))
Esempio n. 2
0
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))
Esempio n. 3
0
    def insert_into_database(self):
        """
        For a given CRANPackage construct Software object and insert it into database
        """
        try:
            me = User.objects.get(username=settings.R_CRAN_BOT)
        except User.DoesNotExist:
            import string
            from random import Random
            newpasswd = ''.join( Random().sample(string.letters+string.digits, 32) ) 

            user = User.objects.create_user(settings.R_CRAN_BOT, settings.R_CRAN_BOT + '@mloss.org', newpasswd)
            user.save()
            me = User.objects.get(username=settings.R_CRAN_BOT)


        #don't insert crappy items having future date
        if self.date<datetime.datetime.now():
            # check whether the package exists (without prefix)
            dbpkg = Software.objects.filter(title=self.name)
            if dbpkg.count() > 0:
                return

            # check whether the package exists (without prefix)
            dbpkg = Software.objects.filter(user=me, title=self.prefix+self.name)
            if dbpkg.count() == 0:
                # if not create a new Software project
                spkg = Software(user=me, title=self.prefix+self.name)
                spkg.save(silent_update=True)
                try:
                    srev = Revision(software=spkg, version=self.version, short_description=self.short_description,
                                    description=self.description, os_license=self.os_license,
                                    language='R', operating_systems='agnostic',
                                    download_url=self.url, project_url=self.url, tags='r-cran',
                                    pub_date=self.date, updated_date=self.date, authors=self.author,
                                    changes="Initial Announcement on mloss.org by r-cran-robot")
                    srev.save(silent_update=True)
                except:
                    spkg.delete()
            else:
                #print 'Package ' + self.name + ' found, UPDATING...'
                assert(dbpkg.count() == 1)
                spkg = dbpkg[0]

                try:
                    srev = Revision.objects.get(software=spkg, revision=0)
                    # Don't mess around with manual entries.
                    if srev.tags != 'r-cran':
                        return
                except ObjectDoesNotExist:
                    srev = None

                if srev and srev.version == self.version:
                    srev.short_description=self.short_description
                    srev.description=self.description
                    srev.os_license=self.os_license
                    srev.download_url=self.url
                    srev.project_url=self.url
                    srev.updated_date=self.date
                    srev.authors=self.author
                    srev.changes="Fetched by r-cran-robot on %s" % str(datetime.datetime.now())
                else:
                    srev = Revision(software=spkg, version=self.version, short_description=self.short_description,
                                    description=self.description, os_license=self.os_license,
                                    language='R', operating_systems='agnostic',
                                    download_url=self.url, project_url=self.url, tags='r-cran',
                                    pub_date=self.date, updated_date=self.date, authors=self.author,
                                    changes="Fetched by r-cran-robot on %s" % str(datetime.datetime.now()))
                    spkg.increment_revisions()
                srev.save(silent_update=True)