示例#1
0
文件: views.py 项目: vicever/OMS
def repo_version_add(request,
                     template_name='repository/repo_version_add.html'):
    form = VersionForm(request.POST or None)
    username = request.session['username']
    if form.is_valid():
        project_name = form.cleaned_data['repository'].repo_tag
        print project_name
        archive_path = os.path.join(form.cleaned_data['archive_path'],
                                    project_name)
        version = get_version(archive_path)
        if not version:
            return HttpResponse(
                "Your configuration specifies to merge with the ref 'master' from the remote, "
                "but no such ref was fetched.")
        if Version.objects.filter(version=version[0]):
            return HttpResponse("already exist.")
        else:
            version_object = Version(project=project_name,
                                     version=version[0],
                                     timestamp=version[1],
                                     author=version[2],
                                     content=version[3],
                                     vernier=u'0')
            version_object.save()

        return redirect('repo_version_list')

    return render(
        request, template_name, {
            'form': form,
            'var6': 'active',
            'username': username,
            'highlight2': 'active',
        })
示例#2
0
def init_db():

    brand = Brand(name='Ford', brand_id=1, country='US').save()
    Brand(name='Ford2', brand_id=2, country='US').save()
    brand.save()

    fiesta = Car(brand=brand, name='Fiesta', car_id=1)
    edge = Car(brand=brand, name='Edge', car_id=2)
    ecosport = Car(brand=brand, name='Ecosport', car_id=3)
    ka = Car(brand=brand, name='Ka', car_id=4)

    flex_counter = 0
    gas_counter = 0

    for car in [fiesta, edge, ecosport, ka]:

        flex_counter += 1
        gas_counter += 1

        car.save()

        flex_version = Version(price=random.randrange(0, 50000),
                               model=car,
                               name='{name} {fuel} - {year}'.format(
                                   name=car.name,
                                   fuel='Flex',
                                   year=2011,
                                   version_id=flex_counter))
        gasoline_version = Version(price=random.randrange(0, 50000),
                                   model=car,
                                   name='{name} {fuel} - {year}'.format(
                                       name=car.name,
                                       fuel='Gasolina',
                                       year=2011,
                                       version_id=gas_counter))

        flex_version.save()
        gasoline_version.save()
示例#3
0
def test_setup(**kwargs):
    from django.contrib.auth.models import User
    from random import choice
    from desktopsite.apps.snapboard import chomsky
    from desktopsite.apps.repository.categories import REPOSITORY_CATEGORIES
    from models import Package, Rating, Version
    import datetime
    if not settings.DEBUG:
        return 

    if Package.objects.all().count() > 0:
        # return, since there seem to already be threads in the database.
        return
    
    # ask for permission to create the test
    msg = """
    You've installed Repository with DEBUG=True, do you want to populate
    the board with random users/packages/ratings to test-drive the application?
    (yes/no):
    """
    populate = raw_input(msg).strip()
    while not (populate == "yes" or populate == "no"):
        populate = raw_input("\nPlease type 'yes' or 'no': ").strip()
    if populate == "no":
        return

    # create 10 random users

    users = ('john', 'sally', 'susan', 'amanda', 'bob', 'tully', 'fran'
             'rick', 'alice', 'mary', 'steve', 'chris', 'becca', 'rob'
             'peter', 'amy', 'bill', 'nick', 'dustin', 'alex', 'jesus')
    for u in users:
        user, created = User.objects.get_or_create(username=u)
        user.email = "%s@%s.com" % (u, u)
        user.set_password(u)
        user.save()
        # user.is_staff = True

    # create up to 30 posts
    tc = range(1, 20)
    words = chomsky.objects.split(' ')
    for i in range(0, 20):
        print 'package ', i, 'created'
        subj = words[i]+" "+words[i-4]+" "+words[i+2]+" "+words[i-3]
        package = Package(
                        name=subj,
                        sysname=subj.replace(" ", "_").replace(".", "").replace("(", "").replace(")", "").replace("\n", ""),
                        category=choice(REPOSITORY_CATEGORIES)[0],
                        description = '\n\n'.join([chomsky.chomsky() for x in range(0, choice(range(2, 5)))]),
                        maintainer=choice(User.objects.all()),
                        url="http://www.foo.com/",
                       )
        package.save()
        
        for j in range(0, choice(range(1, 10))):
            text = '\n\n'.join([chomsky.chomsky() for x in range(0, choice(range(2, 5)))])
            v=Version(
              name="%s.%s.%s" % (choice(range(1, 5)), choice(range(1, 50)), choice(range(1, 170))),
              package=package,
              changelog=text,
              #package_url="http://www.foo.com/bar.lucid.zip",
              checksum= "".join([choice("abcdef0123456789") for x in range(1, 50)]),
              verified_safe=choice((True, False)),
            )
            v.save()
            
            for adf in range(0, choice(tc)):
                rating = Rating(
                              user=User.objects.get(pk=adf+1),
                              version= v,
                              score=choice((1,2,3,4,5)),
                )
                rating.save()