예제 #1
0
def site_create(request):
    if not request.user.has_perm('tracker.add_site'):
        messages.error(request, 'Unfortunately, you do not have access to create a new site.')
        return redirect('sites')

    new_user = not Visit.objects.filter(site_user__site__users=request.user).exists()

    if request.method == 'POST':
        form = SiteForm(request.POST)

        if form.is_valid():
            site = form.save()

            site.identifier = Site.generate_identifier()
            site.secret_key = Site.generate_identifier()
            site.users.add(request.user)
            site.save()

            if new_user:
                return redirect(reverse('site', args=[site.identifier]))

            messages.info(request, "'%s' was created." % (site.name))
            return redirect('sites')
    else:
        form = SiteForm()

    return {
        'TEMPLATE': 'www/site_update.html',
        'form': form,
        'new_user': new_user,
    }
예제 #2
0
    def handle(self, *args, **options):
        user = first(User.objects.filter(username='******')[:1])

        if user:
            user.delete()

        user = User(username='******', email='demo')
        user.set_password('demo')
        user.save()

        site = first(Site.objects.filter(identifier='demo')[:1])

        if site:
            site.delete()

        site = Site(name='Sample demo for Wham', identifier='demo', secret_key='asdf1234', url='http://example.com')
        site.save()
        site.users.add(user)
        site.save()

        for x in range(1, 10):
            email = 'user' + str(x) + '@example.com'
            authenticated_site_user = AuthenticatedSiteUser(user_id=str(x), email=email, username='******' + str(x), number_of_visits=9, number_of_sessions=9)
            authenticated_site_user.save()

            site_user = SiteUser(site=site, authenticated_site_user=authenticated_site_user, sf_user_id=Site.generate_identifier(), number_of_visits=9, number_of_sessions=9)
            site_user.save()

            for y in range(1, 10):
                created_datetime = (timezone.now() - timedelta(minutes=y + randint(1, 9)))

                visit = Visit(created=created_datetime, site_user=site_user, ip_address='127.0.0.1', user_id=str(x), email=email, username='******' + str(x), url='http://example.com/' + str(randint(44, 88)) + '.html', referrer='http://google.com/')
                visit.save()

                if y == 1:
                    site_user.first_visit = visit
                    authenticated_site_user.first_visit = visit

                    session = Session(visit=visit)
                    session.save()
                    site_user.first_session = session
                    authenticated_site_user.first_session = session
                elif y == 9:
                    site_user.last_visit = visit
                    authenticated_site_user.last_visit = visit

                    session = Session(visit=visit)
                    session.save()
                    site_user.last_session = session
                    authenticated_site_user.last_session = session

            site_user.save()
            authenticated_site_user.save()

        self.stdout.write('Demo data is loaded.')