Beispiel #1
0
def add_prereq_to_outcome(request,outcome_id):
    context = {}
    context['user'] = request.user
    this_outcome = Outcome.objects.get(id=outcome_id)
    context['outcome'] = this_outcome
    if request.method=="POST":
        outcome_id = request.POST.get('outcome_id','')
        prereq_name = request.POST.get('prereq_name','')
        prereq_description = request.POST.get('prereq_description','')
        prereq_creator_id = request.POST.get('prereq_creator_id','')
        if prereq_name=='' or prereq_description=='' or prereq_creator_id=='' or outcome_id=='':
            to_json = {
                'result': 'failed'
            }
            return HttpResponse(simplejson.dumps(to_json), content_type="application/json")
        else:
            prereq_creator = User.objects.get(id=prereq_creator_id)
            prereq = Outcome(name=prereq_name,description=prereq_description,creator=prereq_creator)
            prereq.save()
            prereq.instructors.add(prereq_creator)
            this_outcome.prerequisites.add(prereq)
            this_outcome.save()
            to_json = {
                'result': 'succeeded',
            }
            return HttpResponse(simplejson.dumps(to_json), content_type="application/json")
    else:
        context['outcomes'] = Outcome.objects.all()
        context['outcome_prereqs'] = this_outcome.prerequisites.all()
        return render_to_response('add_prereq_to_outcome.html', context, RequestContext(request,context))
Beispiel #2
0
def add_outcome_to_module(request,module_id):
    context = {}
    context['user'] = request.user
    this_module = Module.objects.get(id=module_id)
    context['module'] = this_module
    if request.method=="POST":
        module_id = request.POST.get('module_id','')
        outcome_name = request.POST.get('outcome_name','')
        outcome_description = request.POST.get('outcome_description','')
        outcome_creator_id = request.POST.get('outcome_creator_id','')
        if outcome_name=='' or outcome_description=='' or outcome_creator_id=='' or module_id=='':
            to_json = {
                'result': 'failed'
            }
            return HttpResponse(simplejson.dumps(to_json), content_type="application/json")
        else:
            outcome_creator = User.objects.get(id=outcome_creator_id)
            outcome = Outcome(name=outcome_name,description=outcome_description,creator=outcome_creator)
            outcome.save()
            outcome.instructors.add(outcome_creator)
            outcome.modules.add(this_module)
            to_json = {
                'result': 'succeeded',
            }
            return HttpResponse(simplejson.dumps(to_json), content_type="application/json")
    else:
        context['outcomes'] = Outcome.objects.all()
    return render_to_response('add_outcome_to_module.html', context, RequestContext(request,context))
Beispiel #3
0
def create():
    form = CreateBetForm()
    if form.validate_on_submit():
        with transaction() as tx:
            bet = Bet(title=form.name.data,
                      description=form.description.data,
                      owner=current_user)
            tx.add(bet)
            for t in form.outcomes.entries:
                tx.add(Outcome(title=t.data, bet=bet))
        return redirect(url_for('bets.bet', bet_id=bet.bet_id))
    return render_template("bets/create.html", create_form=form)
    def test_add_winner(self):
        """Test the public ``add_winner'' function provided by the
        Outcome() class.
        """

        con = Constituency("test")
        con2 = Constituency("test2")

        party1 = Party("party1")
        party2 = Party("party2")

        candidate1 = Candidate("candidate1", party1, con)
        candidate2 = Candidate("candidate2", party2, con2)

        outcome = Outcome()

        outcome.add_winner(candidate1)

        self.assertEqual(len(outcome.winners), 1)
        self.assertTrue(candidate1 in outcome.winners)

        # attempt to add the same candidate
        with self.assertRaises(AssertionError):
            outcome.add_winner(candidate1)
def read_cricket_labels(innings1_file, innings2_file):
    labels = []
    illegal_balls = []
    ball_num = 1
    for innings in [innings1_file, innings2_file]:
        infile = open(innings, 'r')
        for line in infile.readlines():
            cols = line.strip().split(',')
            detailed_outcome = cols[4]
            if 'wide' in detailed_outcome or 'no ball' in detailed_outcome:
                illegal_balls.append(ball_num)

            outcome = Outcome.get_label_from_commentary(cols[-1])
            labels.append(outcome)
            ball_num += 1
    return labels, illegal_balls
Beispiel #6
0
def read_cricket_labels(innings1_file, innings2_file):
    labels = []
    illegal_balls = []
    ball_num = 1
    for innings in [innings1_file, innings2_file]:
        infile = open(innings, 'r')
        for line in infile.readlines():
            cols = line.strip().split(',')
            detailed_outcome = cols[4]
            if 'wide' in detailed_outcome or 'no ball' in detailed_outcome:
                illegal_balls.append(ball_num)

            outcome = Outcome.get_label_from_commentary(cols[-1])
            labels.append(outcome)
            ball_num += 1
    return labels, illegal_balls
Beispiel #7
0
 def process_request(self):
     intermediate_private_key = get_btc().create_private_key()
     event = Event(
         content=self.processed_form.content.data,
         bitcoin_private_key=intermediate_private_key.to_compressed_wif(),
         bitcoin_public_key=intermediate_private_key.get_public_key().
         to_hex(),
         bitcoin_address=intermediate_private_key.get_address().to_wif(),
     )
     self.change_tags(event, self.processed_form)
     get_db().session.add(event)
     get_db().session.flush()
     for outcome in self.processed_form.outcomes.entries:
         private_key = get_btc().create_private_key()
         get_db().session.add(
             Outcome(
                 event_id=event.id,
                 content=outcome.content.data,
                 bitcoin_private_key=private_key.to_compressed_wif(),
                 bitcoin_public_key=private_key.get_public_key().to_hex(),
                 bitcoin_address=private_key.get_address().to_wif(),
             ))
     get_db().session.commit()
Beispiel #8
0
    def test_add_winner(self):
        """Test the public ``add_winner'' function provided by the
        Outcome() class.
        """

        con = Constituency("test")
        con2 = Constituency("test2")

        party1 = Party("party1")
        party2 = Party("party2")

        candidate1 = Candidate("candidate1", party1, con)
        candidate2 = Candidate("candidate2", party2, con2)

        outcome = Outcome()

        outcome.add_winner(candidate1)

        self.assertEqual(len(outcome.winners), 1)
        self.assertTrue(candidate1 in outcome.winners)

        # attempt to add the same candidate
        with self.assertRaises(AssertionError):
            outcome.add_winner(candidate1)
Beispiel #9
0
from models import Asset, Outcome, Income

from finance_manager import FinanceManager
from data import asset_data, outcome_data, income_data

assets = [Asset(**item) for item in asset_data]
outcomes = [Outcome(**item) for item in outcome_data]

incomes = [Income(**item) for item in income_data]

FinanceManager.commit(incomes)
# FinanceManager.commit(assets)
# FinanceManager.commit(outcomes)