コード例 #1
0
ファイル: views.py プロジェクト: robftz/bizmodelcomp
def new(request):

    owner = None
    if request.user.is_authenticated():
        owner = request.user

    if request.user.is_authenticated:
        competition = Competition(name="New competition",
                hosted_url = rand_key(),
                owner=owner)
    else:
        competition = Competition(name="New competition",
                hosted_url = rand_key())

    competition.save()

    request.session["new_comp_id"] = competition.id

    return HttpResponseRedirect("/new/who/")
コード例 #2
0
ファイル: util.py プロジェクト: robftz/bizmodelcomp
def send_verification_email(user, next_page):

    verification_key = None

    try:
        #only one per user. if we've already made one, send
        #a friendly reminder
        verification_key = VerificationKey.objects.get(user=user)
    except:

        #create unique random verification key. it's possible these loops
        #won't find one, but that's quite unlikely and 500ing seems less
        #risky potentially infinite looping
        for attempt in range(1, 1000):
            key = rand_key()
            print 'send veri email: key %s' % key
            try:
                
                verification_key = VerificationKey(key=key,
                                                   user = user)
                print 'made veri key'
                verification_key.save()
                print 'saved veri key'
                #if this hasn't thrown an exception, it's unique and we're
                #okay to quit searching
                print 'breakin'
                break
            
            except: pass
            
        else:
            print 'couldnt find unique valid key, aborting'
            #couldn't create a unique valid key for some reason
            return False

    verification_path = "/accounts/verify/%s/?next=%s" % (verification_key.key, next_page)
    verification_link = request.build_absolute_uri(verification_path)

    subject = "Verify your competition account"
    to_email = user.email
    message = """Hello,

To keep the competition pitches secure, we need you to confirm that this really is your email address, which you can do by using the link below. You'll then be taken to the page you were heading toward when you registered.

%s

Thanks very much, and please let us know (you can just reply to this email) if you have any questions or issues.

Stay well,
nvana""" % (verification_link)

    print 'sending email verify email'
    send_email(subject, message, to_email)

    return True
コード例 #3
0
ファイル: models.py プロジェクト: robftz/Shippit
    def create_invoice(project):

        #create the invoice with a random key and incremented invoice #
        new_invoice = Invoice(project=project,
                key = rand_key(),
                invoice_number=Invoice.objects.all().count() + 1,
                please_use_static_function___Invoice_create___instead_of_building_by_hand="okay")
        new_invoice.save()

        #claim all time chunks without an invoice
        unclaimed_entries = TimeEntry.objects.filter(project=project,
                invoice__pk=1)
        for entry in unclaimed_entries:
            entry.invoice = new_invoice
            entry.save()

        return new_invoice
コード例 #4
0
ファイル: models.py プロジェクト: robftz/bizmodelcomp
    def send_judging_open_email(self, phase):

        if phase in self.received_phase_judging_open_emails_from.all():

            #already sent an alert, so do nothing
            return False

        else:
            try:
                #key already exists?
                verification_key = VerificationKey.objects.filter(email=self.email)[0]
                verification_key.is_verified=True
            except:
                #doesn't exist, make a new one pointing to the email that's pre-approved
                verification_key = VerificationKey(key=rand_key(),
                                                   user=None,
                                                   email=self.email,
                                                   is_verified=True)
            #in either case, save changes
            verification_key.save()
            
            judging_path = "/judge/?ev=%s" % key
            
            to_email = self.email
            subject = "Judging now open for %s" % self.competition.name
            message_markdown = """Hello,

Judging for %s is now open and will run until %s or as soon as all the applications have been assessed.

The link below will ask you to create an account and then take you to start judging submitted pitches. To ensure that we know who you are, please register with the same email address that this note is being sent to (%s).

%s

Your help as a judge is hugely appreciated. Please don't hesistate to reply if you have any questions, problems, or concerns.

Sincerely,

%s team""" % (self.competition.name,
              self.competition.current_phase().judging_close,
              self.email,
              judging_link,
              self.competition.name)
        
            
            send_email(subject, message_markdown, to_email)
コード例 #5
0
ファイル: views.py プロジェクト: robftz/bizmodelcomp
def handle_uploaded_file(request, f, upload, pitch):

    upload_path = '%suploads/' % MEDIA_ROOT
    if not os.path.isdir(upload_path):
        os.mkdir(upload_path)
        
    file_name = ""
    
    #add to a random directory to avoid collisions
    rand_folder = rand_key(20)
    upload_path = "%s%s/" % (upload_path, rand_folder)
    download_path = "%s/" % rand_folder

    if not os.path.isdir(upload_path):
        os.mkdir(upload_path)

    #preserve filename where possible
    if f.name:
        #name same as original file, in random folder
        upload_path = "%s%s" % (upload_path, f.name)
        file_name = "%s/%s" % (rand_folder, f.name)
    else:
        #random name
        upload_path = "%s%s.bmc" % (upload_path, rand_folder)
        file_name = "%s/%s.bmc" % (rand_folder, rand_folder)

    print 'upload path: %s' % upload_path
    print 'file_name: %s' % file_name

    destination = open(upload_path, 'wb+')
    for chunk in f.chunks():
        destination.write(chunk)
    destination.close()

    pitch_file = None
    try:
        pitch_file = PitchFile.objects.filter(pitch=pitch).get(upload=upload)
        pitch_file.file_location = upload_path
        pitch_file.filename = file_name
    except:
        pitch_file = PitchFile(upload=upload,
                               file_location=upload_path,
                               filename=file_name,
                               pitch=pitch)
    pitch_file.save()

    #send file to scribd for display
    register_openers()

    datagen, headers = multipart_encode({"file": open(pitch_file.file_location, "rb")})
    request = urllib2.Request(SCRIBD_UPLOAD_URL, datagen, headers)

    #xml with <doc_id>, <access_key>, and <secret_password>
    scribd_response = urllib2.urlopen(request).read()
    print 'Scribd response: %s' % scribd_response
    xml = minidom.parseString(scribd_response)
    try:
        doc_id = xml.getElementsByTagName("doc_id")[0].firstChild.data
        access_key = xml.getElementsByTagName("access_key")[0].firstChild.data
        secret_password = xml.getElementsByTagName("secret_password")[0].firstChild.data

        scribd_file_data = None
        try:
            scribd_file_data = ScribdFileData.objects.get(pitch_file=pitch_file)
            scribd_file_data.doc_id = doc_id
            scribd_file_data.access_key = access_key
            scribd_file_data.secret_password = secret_password
        except:
            scribd_file_data = ScribdFileData(pitch_file=pitch_file,
                    doc_id=doc_id,
                    access_key=access_key,
                    secret_password=secret_password)

        scribd_file_data.save()
        
    except:
        #no scribd file basically means it was a non-doc (image etc)
        print 'Scribd exception: %s' % sys.exc_info()[0]
        try:
            #we might have an old upload that _did_ use scribd for this upload, 
            #in which case we scrap it
            scribd_file_data = ScribdFileData.objects.get(pitch_file=pitch_file)
            scribd_file_data.delete()
        except:
            pass
コード例 #6
0
ファイル: scripts.py プロジェクト: robftz/bizmodelcomp
def create_dummy_competition(user):

    #find unique hosted url
    url = None
    while True:
        url = rand_key(6)
        try:
            Competition.objects.get(hosted_url=key)
        except:
            break

    #create competition
    competition = Competition(owner=user,
            hosted_url=url,
            name="Lorem Ipsum",
            website="http://loremipsum.com")
    competition.save()

    #create default phase
    phase_1 = Phase(competition=competition,
            name="first online phase",
            is_judging_enabled=False)
    phase_1.save()

    #a second, emptier phase
    phase_2 = Phase(competition=competition,
            name="second online phase",
            is_judging_enabled=True)
    phase_2.save() 

    #a third, live and incomplete phase
    phase_3 = Phase(competition=competition,
            name="third live phase")
    phase_3.save() 

    competition.current_phase = phase_2
    competition.save()

    #add a few questions.
    #on phase 1 & 2 (online) you have 4 questions that 
    #are scored normally, and then one open feedback spot
    for i in range(1, 5):
        question = PitchQuestion(order=i,
                phase=phase_1,
                prompt=LOREM[:50],
                max_points=10)
        if i == 4:
            question.judge_feedback_prompt = "Overall thoughts?"
            question.is_hidden_from_applicants = True
        question.save()

        question = PitchQuestion(order=i,
                phase=phase_2,
                prompt=LOREM[:50],
                max_points=10)
        if i == 4:
            question.judge_feedback_prompt = "Overall thoughts?"
            question.is_hidden_from_applicants = True
        question.save()

    #three open feedback questions for the live pitch
    for i in range(1, 3):
        question = PitchQuestion(order=i,
                phase=phase_3,
                prompt=LOREM[:50],
                max_points=10,
                judge_feedback_prompt = LOREM[:20],
                is_hidden_from_applicants = True)
        question.save()

    #some judges
    for i in range(1, 5):
        judge = JudgeInvitation(competition=competition,
                email="*****@*****.**" % i,
                has_received_invite_email=True)
        judge.save()

    #create a bunch of applicants
    for i in range(1, 100):

        email_num = rand_key(12)

        #applicant
        founder = Founder(name="Founder %s" % i,
                email = "*****@*****.**" % email_num,
                phone = "1234567890",
                birth = "1900-01-28")
        try:
            founder.save()
        except:
            continue

        competition.applicants.add(founder)

        team = Team(owner=founder,
                name="Team %s" % i)
        team.save()

        #answers, but only for the first 2 phases (3rd live phase hasn't been done yet!) 
        for phase in [phase_1, phase_2]:
            
            #application
            pitch = Pitch(team=team,
                    phase=phase,
                    is_draft=False)
            pitch.save()
            
            #judging. we intentionally don't check for collisions
            #so that most apps will get judged twice, but not 100%
            judge_1 = get_random_judge(phase)
            judge_2 = get_random_judge(phase)

            judged = JudgedPitch(pitch=pitch,
                    judge=judge_1)
            judged.save()

            #don't allow the same judge to rate the same app multiple times
            judged_2 = None
            if judge_1 != judge_2:
                judged_2 = JudgedPitch(pitch=pitch,
                        judge=judge_2)
                judged_2.save()
             
            #loop through all questions to answer and judge them
            for question in phase.questions():

                answer = None

                if not question.is_hidden_from_applicants:
                    #student can see the question, should answer it
                    answer = PitchAnswer(question=question,
                            pitch=pitch,
                            answer=LOREM)
                    answer.save()

                #judges always answer, one way or another. answer=Null mean
                #that the question was hidden from applicant and judges need leave feedback
                j_answer = JudgedAnswer(judged_pitch=judged,
                        score=get_random_score(question),
                        answer=answer)
                if question.judge_feedback_prompt:
                    j_answer.feedback = LOREM
                j_answer.save()

                if judged_2:
                    j_answer = JudgedAnswer(judged_pitch=judged_2,
                        score=get_random_score(question),
                        answer=answer)
                    if question.judge_feedback_prompt:
                        j_answer.feedback = LOREM
                    j_answer.save()

    #setup steps - phase 1 done
    steps = phase_1.setup_steps()
    steps.details_confirmed = True
    steps.application_setup = True
    steps.announced_applications = True
    steps.invited_judges = True
    steps.announced_judging_open = True
    steps.selected_winners = True
    steps.save()

    #setup steps - phase 2 just needs winners declared
    steps = phase_2.setup_steps()
    steps.details_confirmed = True
    steps.application_setup = True
    steps.announced_applications = True
    steps.invited_judges = True
    steps.announced_judging_open = True
    steps.selected_winners = False
    steps.save()

    competition.save()

    return competition