コード例 #1
0
ファイル: tests.py プロジェクト: philmcmahon/benpledge
    def setUp(self):
        # users
        self.phil = User.objects.get(username="******")
        self.test99 = User.objects.get(username="******")

        #client 
        self.c = Client()
        self.c.login(username='******', password='******')

        # measures
        self.loft_insulation = Measure.objects.get(id=1)
        self.solar_panel_1kw = Measure.objects.get(id=13)
        self.cylinder_thermostat = Measure.objects.get(id=21)

        # times
        self.datetime_one_week_today = datetime.now() + timedelta(days=7)
        self.datetime_one_week_ago = datetime.now() + timedelta(days=-7)

        self.date_one_week_today = (datetime.now() + timedelta(days=7)).date()
        self.date_ten_days_time = (datetime.now() + timedelta(days=10)).date()

        self.date2020 = date(2020, 1, 1)



        # pledges
        self.pledge_1 = Pledge(id=1, measure=self.loft_insulation, user=self.phil, deadline=self.date_one_week_today)
        self.pledge_1.save()
        self.pledge_2 = Pledge(id=2, measure=self.solar_panel_1kw, user=self.phil, deadline=self.date_ten_days_time)
        self.pledge_3 = Pledge(id=3, measure=self.loft_insulation, user=self.test99, deadline=self.date2020)
        self.pledge_3.save()
        self.pledges = [self.pledge_1, self.pledge_2, self.pledge_3]

        # HAT Results
        self.hat_results_1 = HatResultsDatabase.objects.get(pk=1)
コード例 #2
0
ファイル: serializer.py プロジェクト: atemena/Small-Deeds-API
	def create(self, validated_data):
		pledge = Pledge(
			user=validated_data['user'],
			deed=validated_data['deed'],
			threshold=validated_data['threshold'],
			active=validated_data['active']
		)
		pledge.save()
		return pledge
コード例 #3
0
ファイル: views.py プロジェクト: tomdyson/climatevote
def pledge(request):
    pledge = Pledge(
        name=request.POST["name"],
        postcode=request.POST["postcode"],
        email=request.POST["email"],
        message=request.POST["message"],
    )
    mp_details = getMPDetails(pledge.postcode)
    mp = mp_details["full_name"]
    pledge.mp = mp
    pledge.constituency = mp_details["constituency"]
    pledge.put()
    return render_to_response("pledge.html", {"mp": mp})
コード例 #4
0
ファイル: __init__.py プロジェクト: jzhang621/merit_app
def commit_pledge():
  """
  API endpoint used by the front-end to commit a pledge in the pledges database.
  """
  name = request.form['pledgeName']
  major = request.form['major']
  year = request.form['year']

  pledge_id = Pledge.add_pledge(name, major, year)
  return '<div>{0}</div>'.format(pledge_id)
コード例 #5
0
ファイル: views.py プロジェクト: philmcmahon/benpledge
def make_pledge(request):
    if request.method == 'POST':
        # get hidden fields from the form
        time_period = int(request.POST['time_period'])
        measure_id = request.POST['measure_id']
        hat_results_id = request.POST['hat_results_id']
        # fetch measure from the database
        measure = Measure.objects.get(id=measure_id)

        # if hat results available for pledge, store them
        if hat_results_id:
            hat_results = HatResultsDatabase.objects.get(id=hat_results_id)
        else:
            hat_results = None

        # check pledge type
        if request.POST.get('interest_only'):
            pledge_type = Pledge.INTEREST_ONLY
        else:
            pledge_type = Pledge.PLEDGE

        # if the pledge has not already been made by this user for this measure
        # save the pledge
        if len(Pledge.objects.filter(measure=measure, user=request.user)) == 0:
            if pledge_type == Pledge.PLEDGE:
                now = datetime.now()
                duration = time_period * 30 # time period is in months
                deadline = now + timedelta(days=duration)
            else:
                deadline = None
            # create pledge
            pledge = Pledge(measure=measure, user=request.user, deadline=deadline,
                hat_results=hat_results, receive_updates=request.POST.get('receive_updates', False),
                pledge_type=pledge_type)
            pledge.save()
        else:
            # if pledge has already been made for that measure...
            pass
        return redirect('profile')
    else:
        print "Not a POST request"
        return redirect('profile')
コード例 #6
0
ファイル: tests.py プロジェクト: philmcmahon/benpledge
class BaseTestCase(TestCase):
    fixtures = ['publicweb_test_fixture.json', 'auth.json', 'hatresults50.json']
    # ['auth.json', 'hathouseidlookup50.json', 'hatresults50.json', 'lsoadomestic50.json', 'postcodeoalookup50.json', 'ecoeligible50.json', 'publicweb_test_fixture.json']

    def setUp(self):
        # users
        self.phil = User.objects.get(username="******")
        self.test99 = User.objects.get(username="******")

        #client 
        self.c = Client()
        self.c.login(username='******', password='******')

        # measures
        self.loft_insulation = Measure.objects.get(id=1)
        self.solar_panel_1kw = Measure.objects.get(id=13)
        self.cylinder_thermostat = Measure.objects.get(id=21)

        # times
        self.datetime_one_week_today = datetime.now() + timedelta(days=7)
        self.datetime_one_week_ago = datetime.now() + timedelta(days=-7)

        self.date_one_week_today = (datetime.now() + timedelta(days=7)).date()
        self.date_ten_days_time = (datetime.now() + timedelta(days=10)).date()

        self.date2020 = date(2020, 1, 1)



        # pledges
        self.pledge_1 = Pledge(id=1, measure=self.loft_insulation, user=self.phil, deadline=self.date_one_week_today)
        self.pledge_1.save()
        self.pledge_2 = Pledge(id=2, measure=self.solar_panel_1kw, user=self.phil, deadline=self.date_ten_days_time)
        self.pledge_3 = Pledge(id=3, measure=self.loft_insulation, user=self.test99, deadline=self.date2020)
        self.pledge_3.save()
        self.pledges = [self.pledge_1, self.pledge_2, self.pledge_3]

        # HAT Results
        self.hat_results_1 = HatResultsDatabase.objects.get(pk=1)
コード例 #7
0
ファイル: utils.py プロジェクト: philmcmahon/benpledge
def pledge_results_with_progress(pledges):
    """Takes a list of pledges and returns a dict containing progress details"""
    pledge_progress = {}
    for p in pledges:
        if p.pledge_type == Pledge.PLEDGE:
            time_progress = Pledge.time_progress(p)
        else:
            time_progress = None
        pledge_progress[p.id] = {
            'pledge' : p,
            'time_progress': time_progress,
            'savings': get_pledge_energy_savings(p),
        }
    return pledge_progress
コード例 #8
0
ファイル: __init__.py プロジェクト: jzhang621/merit_app
def get_pledge_report(pledge):
  """
  Render the merit report for the given pledge
  """
  title = pledge
  pledge_info = Pledge.get_pledge_by_name(pledge)

  pledge_id = pledge_info.id
  total = pledge_info.value
  records = Record.get_records_by_pledge(pledge_id)

  approved = [r for r in records if r.approved]
  pending = [r for r in records if not r.reviewed]
  rejected = [r for r in records if r.reviewed and not r.approved]
  return render_template('pledge.html', page_title=title, approved=approved, pending=pending, rejected=rejected, pledge_total=total)
コード例 #9
0
ファイル: __init__.py プロジェクト: jzhang621/merit_app
def register_pledges():
  pledges = Pledge.get_all_pledges()
  return dict(pledges=pledges)
コード例 #10
0
ファイル: views.py プロジェクト: tomdyson/climatevote
def pledges(request):
    query = Pledge.all()
    return render_to_response("pledges.html", {"query": query})
コード例 #11
0
ファイル: views.py プロジェクト: tomdyson/climatevote
def messages(request, pledger):
    pledge = Pledge.get(pledger)
    return render_to_response("message.html", {"pledge": pledge})