Beispiel #1
0
def index_view(request):
    session = request.session

    if request.method == 'POST':  # If the form has been submitted...
        form = IndexForm(request.POST)  # A form bound to the POST data
        if form.is_valid():
            c_d = form.cleaned_data
            if session.test_cookie_worked():
                session.delete_test_cookie()
                session['access_key_id'] = c_d.get('access_key_id')
                session['secret_access_key'] = c_d.get('secret_access_key')
                session['owner_id'] = c_d.get('owner_id')
                session['date_time'] = datetime.now()
                # Redirect after POST
                return HttpResponseRedirect(reverse('aws_clusters', args=[]))
            else:
                form.errors['non_field_errors'] = \
                    "Please enable cookies and try again"
    else:
        form = IndexForm()

    session.set_test_cookie()
    return render_to_response('aws_index.html', {
        'form': form,
    },
                              context_instance=RequestContext(request))
    def post(self, request):
        form = IndexForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            year_num = int(cd.get('year'))

        week_num = 0
        last_completed_week_num = 0
        last_inprogress_week_num = 0
        yearlist = get_yearlist()
        if year_num in yearlist:
            week_num = 0
            weeklist = get_weeklist(year_num, only_unlocked_picks=True)
            if len(weeklist) > 0:
                week_num = weeklist[-1]
            else:
                year_num = 0
            if year_num:
                db = Database()
                try:
                    for w in weeklist:
                        cr = CalculateResults(db.load_week_data(year_num, w))
                        week_state = cr.get_summary_state_of_all_games()
                        if week_state == FINAL:
                            last_completed_week_num = w
                        elif week_state == IN_PROGRESS:
                            last_inprogress_week_num = w
                except:
                    pass
        profile = get_profile_by_user(user=request.user)
        player_name, player_over_under_list = calc_weekly_points(year_num, request.user.username, overunder=True)
        compare_name, compare_over_under_list = calc_weekly_points(year_num, None, overunder=True)
        context = {
                'year_num': year_num,
                'week_num': week_num,
                'last_completed_week_num': last_completed_week_num,
                'last_inprogress_week_num': last_inprogress_week_num,
                'week_range': range(1, week_num + 1),
                'profile': profile,
                'player_name': player_name,
                'player_over_under_list': player_over_under_list,
                'player_color': '#009999',
                'compare_name': compare_name,
                'compare_over_under_list': compare_over_under_list,
                'compare_color': '#cc0099',
                'form': form,
                }

        return render(request,"pick10/index.html", context)
Beispiel #3
0
def create_index(request):
    account = request.user.get_profile().account
    if request.method == 'GET':
        index_qty = len(account.indexes.all())
        default_name = ''  #'Index_' + str(index_qty + 1)

        form = IndexForm(initial={'name': default_name})
        context = {
            'form': form,
            'account': request.user.get_profile().account,
            'navigation_pos': 'dashboard',
        }
        return render('new-index.html', request, context_dict=context)
    else:
        form = IndexForm(data=request.POST)
        if form.is_valid():
            try:
                client = ApiClient(account.get_private_apiurl())
                client.create_index(form.cleaned_data['name'])
                messages.success(request, 'New index created successfully.')
            except IndexAlreadyExists:
                context = {
                    'form': form,
                    'account': request.user.get_profile().account,
                    'navigation_pos': 'dashboard',
                }
                messages.error(request,
                               'You already have an Index with that name.')
                return render('new-index.html', request, context_dict=context)
            except TooManyIndexes:
                context = {
                    'form': form,
                    'account': request.user.get_profile().account,
                    'navigation_pos': 'dashboard',
                }
                messages.error(
                    request,
                    'You already have the maximum number of indexes allowed for your account. If you need more, please contact support.'
                )
                return render('new-index.html', request, context_dict=context)
            except Exception, e:
                print e
                messages.error(
                    request,
                    'Unexpected error creating the index. Try again in a few minutes'
                )
            return HttpResponseRedirect(reverse('dashboard'))
        else:
def create_index(request):
    account = request.user.get_profile().account
    if request.method == 'GET':
        index_qty = len(account.indexes.all())
        default_name = '' #'Index_' + str(index_qty + 1)
        
        form = IndexForm(initial={'name': default_name}) 
        context = {
          'form': form,
          'account': request.user.get_profile().account,
          'navigation_pos': 'dashboard',
        }
        return render('new-index.html', request, context_dict=context)
    else:
        form = IndexForm(data=request.POST)
        if form.is_valid():
            try:
                client = ApiClient(account.get_private_apiurl())
                client.create_index(form.cleaned_data['name'])
                messages.success(request, 'New index created successfully.')
            except IndexAlreadyExists:
                context = {
                  'form': form,
                  'account': request.user.get_profile().account,
                  'navigation_pos': 'dashboard',
                }
                messages.error(request, 'You already have an Index with that name.')
                return render('new-index.html', request, context_dict=context)
            except TooManyIndexes:
                context = {
                  'form': form,
                  'account': request.user.get_profile().account,
                  'navigation_pos': 'dashboard',
                }
                messages.error(request, 'You already have the maximum number of indexes allowed for your account. If you need more, please contact support.')
                return render('new-index.html', request, context_dict=context)
            except Exception, e:
                print e
                messages.error(request, 'Unexpected error creating the index. Try again in a few minutes')
            return HttpResponseRedirect(reverse('dashboard'))     
        else: