Пример #1
0
def update(request):
    flag = 'month_date_month' in request.GET and 'month_date_year' in request.GET
    if request.method == 'GET' and flag:
        month_date_month = int(request.GET['month_date_month'])
        month_date_year = int(request.GET['month_date_year'])
        if month_date_month and month_date_year:
            record_date = datetime.date(month_date_year, month_date_month, 1) #(YYYY, MM, DD)
            eco_profiles_for_user = EcoProfile.objects.filter(user = request.user)
            try:
                eco_profile = eco_profiles_for_user.get(current_month = record_date)
                form = UserUpdateForm(initial = getInitialDataFor(eco_profile, request.user))
                message = "Step 2: Update your record from " + str(month_date_month) + "/" + str(month_date_year)
                return render(request, 'registration/update.html', {'message': message, 
                                                                    'form': form,
                                                                    'form_method': 'POST',
                                                                    },)
            except exceptions.ObjectDoesNotExist:
                eco_profile = EcoProfile()
                eco_profile.current_month = record_date
                form = UserUpdateForm(initial = getInitialDataFor(eco_profile, request.user))
                message = "Step 2: Create a record for " + str(month_date_month) + "/" + str(month_date_year)
                return render(request, 'registration/update.html', {'message': message, 
                                                                    'form': form,
                                                                    'form_method': 'POST',
                                                                    },)
    elif request.method == 'POST':
        sub_form = UserUpdateForm(request.POST)
        if sub_form.is_valid():
            data = sub_form.cleaned_data
            if recordExistsFor(request.user, sub_form.cleaned_data):
                updateData(request.user, sub_form.cleaned_data, 'update')
            else:
                updateData(request.user, sub_form.cleaned_data, 'new')
            return render(request, 'registration/update.html', {'form': RecordRetrieveForm(),
                                                       'message': 'Submission Recorded Successfully! \
                                                       Choose another month or visit your profile to view more info',
                                                       'form_method': 'GET',
                                                       })
        else:
            return render(request, 'registration/update.html', {'form': RecordRetrieveForm(),
                                                       'message': 'There was an error processing your form.  Please try again',
                                                       'form_method': 'GET',
                                                       })
    return render(request, 'registration/update.html', {'form': RecordRetrieveForm(), 
                                                            'message': "Step 1: Select a month/year combination",
                                                            'form_method': 'GET',
                                                            })
Пример #2
0
def updateData(usr, data, method):
    record_date = data['date_on_bills']
    usp = UserProfile.objects.get(user=usr)
    if method == 'update':
        assert(recordExistsFor(usr, data))
        record = EcoProfile.objects.filter(user = usr).get(current_month = record_date)
    elif method == 'new':
        record = EcoProfile(user = usr)
    record.current_month = record_date
    record.water_this_month = data['water_bill']
    record.gas_this_month = data['gas']
    record.electricity_this_month = data['electric_bill']
    record.pounds_of_trash = data['trash_weight']
    record.natural_gas = data['natural_gas']
    record.heating_oil = data['heating_oil']
    usp.house_square_footage = data['house_sq']
    usp.number_of_people = data['occupants']
    usp.save()
    record.save()
Пример #3
0
    def save(self):
        data = self.cleaned_data
        self.checkUsername(data['username'])
        if data['password'] == data['password_v']:
            user = User.objects.create_user(data['username'], data['email'], data['password'])
        else:
            raise validators.ValidationError('Passwords do not match')
        user.first_name = data['first_name']
        user.last_name = data['last_name']
        user.save()
        
        profile = user.get_profile()
        profile.address = data['address']
        profile.zip_code = data['zip_code']
        profile.house_square_footage = data['house_square_feet']
        profile.number_of_people = data['number_of_residents']
        profile.heating_fuel_type = data['heating_fuel']
        profile.save()
        data['affinity_group'].members.add(user)

        
        eco_profile = EcoProfile(user=user)
        eco_profile.save()
Пример #4
0
    def save(self):
        data = self.cleaned_data
        self.checkUsername(data['username'])
        if data['password'] == data['password_v']:
            user = User.objects.create_user(data['username'], data['email'],
                                            data['password'])
        else:
            raise validators.ValidationError('Passwords do not match')
        user.first_name = data['first_name']
        user.last_name = data['last_name']
        user.save()

        profile = user.get_profile()
        profile.address = data['address']
        profile.zip_code = data['zip_code']
        profile.house_square_footage = data['house_square_feet']
        profile.number_of_people = data['number_of_residents']
        profile.heating_fuel_type = data['heating_fuel']
        profile.save()
        data['affinity_group'].members.add(user)

        eco_profile = EcoProfile(user=user)
        eco_profile.save()
Пример #5
0
 def save(self, usr):
     data = self.cleaned_data
     ecp = EcoProfile()
     ecp.user = usr
     ecp.water_this_month = data['water_bill']
     ecp.gas_this_month = int(data['gas'])
     ecp.heating_oil = data['heating_oil']
     ecp.natural_gas = int(data['natural_gas'])
     ecp.pounds_of_trash = data['trash_weight']
     ecp.current_month = data['date_on_bills']
     ecp.electricity_this_month = data['electric_bill']
     ecp.save()
     
     profile = UserProfile.objects.get(user = usr)
     profile.house_square_footage = data['house_sq']
     profile.number_of_people = data['occupants']
     profile.save()
     return ecp
Пример #6
0
    def save(self, usr):
        data = self.cleaned_data
        ecp = EcoProfile()
        ecp.user = usr
        ecp.water_this_month = data['water_bill']
        ecp.gas_this_month = int(data['gas'])
        ecp.heating_oil = data['heating_oil']
        ecp.natural_gas = int(data['natural_gas'])
        ecp.pounds_of_trash = data['trash_weight']
        ecp.current_month = data['date_on_bills']
        ecp.electricity_this_month = data['electric_bill']
        ecp.save()

        profile = UserProfile.objects.get(user=usr)
        profile.house_square_footage = data['house_sq']
        profile.number_of_people = data['occupants']
        profile.save()
        return ecp
Пример #7
0
def updateData(usr, data, method):
    record_date = data['date_on_bills']
    usp = UserProfile.objects.get(user=usr)
    if method == 'update':
        assert (recordExistsFor(usr, data))
        record = EcoProfile.objects.filter(user=usr).get(
            current_month=record_date)
    elif method == 'new':
        record = EcoProfile(user=usr)
    record.current_month = record_date
    record.water_this_month = data['water_bill']
    record.gas_this_month = data['gas']
    record.electricity_this_month = data['electric_bill']
    record.pounds_of_trash = data['trash_weight']
    record.natural_gas = data['natural_gas']
    record.heating_oil = data['heating_oil']
    usp.house_square_footage = data['house_sq']
    usp.number_of_people = data['occupants']
    usp.save()
    record.save()
Пример #8
0
def update(request):
    flag = 'month_date_month' in request.GET and 'month_date_year' in request.GET
    if request.method == 'GET' and flag:
        month_date_month = int(request.GET['month_date_month'])
        month_date_year = int(request.GET['month_date_year'])
        if month_date_month and month_date_year:
            record_date = datetime.date(month_date_year, month_date_month,
                                        1)  #(YYYY, MM, DD)
            eco_profiles_for_user = EcoProfile.objects.filter(
                user=request.user)
            try:
                eco_profile = eco_profiles_for_user.get(
                    current_month=record_date)
                form = UserUpdateForm(
                    initial=getInitialDataFor(eco_profile, request.user))
                message = "Step 2: Update your record from " + str(
                    month_date_month) + "/" + str(month_date_year)
                return render(
                    request,
                    'registration/update.html',
                    {
                        'message': message,
                        'form': form,
                        'form_method': 'POST',
                    },
                )
            except exceptions.ObjectDoesNotExist:
                eco_profile = EcoProfile()
                eco_profile.current_month = record_date
                form = UserUpdateForm(
                    initial=getInitialDataFor(eco_profile, request.user))
                message = "Step 2: Create a record for " + str(
                    month_date_month) + "/" + str(month_date_year)
                return render(
                    request,
                    'registration/update.html',
                    {
                        'message': message,
                        'form': form,
                        'form_method': 'POST',
                    },
                )
    elif request.method == 'POST':
        sub_form = UserUpdateForm(request.POST)
        if sub_form.is_valid():
            data = sub_form.cleaned_data
            if recordExistsFor(request.user, sub_form.cleaned_data):
                updateData(request.user, sub_form.cleaned_data, 'update')
            else:
                updateData(request.user, sub_form.cleaned_data, 'new')
            return render(
                request, 'registration/update.html', {
                    'form': RecordRetrieveForm(),
                    'message': 'Submission Recorded Successfully! \
                                                       Choose another month or visit your profile to view more info',
                    'form_method': 'GET',
                })
        else:
            return render(
                request, 'registration/update.html', {
                    'form': RecordRetrieveForm(),
                    'message':
                    'There was an error processing your form.  Please try again',
                    'form_method': 'GET',
                })
    return render(
        request, 'registration/update.html', {
            'form': RecordRetrieveForm(),
            'message': "Step 1: Select a month/year combination",
            'form_method': 'GET',
        })