Exemple #1
0
    def post(self):
        """Create a new language and fill it with empty translations"""
        if not users.is_current_user_admin():
            self.error(403)

        code = self.request.get('code')
        label = self.request.get('label')

        language = Language.all().filter('code =', code).get()
        if language is not None:
            self.error(500)
        else:
            language = Language(code=code,
                                label=label,
                                enabled_in_tool=False,
                                enabled_on_site=False)
            for phrase in Phrase.all():
                translation = Translation(phrase=phrase, text='')
                translation.put()
                language.translations.append(translation.key())
            language.put()

        init_cached_languages()

        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write('')
Exemple #2
0
    def test_load(self):
        language = Language()
        # confirm that defaults are used
        self.assertEquals(language.strings["speed"], "speed")

        language = Language("base")
        # confirm that custom values added
        self.assertEquals(language.strings["speed"], "sebesség")
        # confirm that not custom defined values are still defaults
        self.assertEquals(language.strings["long 1"], "dolor sit amet")
Exemple #3
0
 def test_save(self):
     sample_file = "test/lang_en.xml"
     check_file = "test/lang_check.xml"
     if isfile(sample_file):
         remove(sample_file)
     with open(check_file, "r") as check_file_handle:
         check_xml = check_file_handle.read()
     language = Language()
     language.save(sample_file)
     with open(sample_file, "r") as sample_file_handle:
         sample_xml = sample_file_handle.read()
     self.assertEquals(sample_xml, check_xml)
Exemple #4
0
def parse_file():
    file = open('./languages.txt', 'r')
    for line in file:
        lang_name = line.rstrip()
        l = Language(language = lang_name)
        db.session.add(l)
    db.session.commit()
Exemple #5
0
    def post(self):
        """Post new suggestion"""
        lang_code = self.request.path.split('/')[-3]
        language = Language.all().filter('code =', lang_code).get()

        if language is None:
            self.error(404)

        user = get_current_youtify_user_model()

        if not (users.is_current_user_admin()
                or user.key() in language.leaders):
            self.error(403)

        translation_id = self.request.path.split('/')[-1]
        translation = Translation.get_by_id(int(translation_id))

        if translation is None:
            self.error(404)

        translation.text = self.request.get('text')
        translation.save()

        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write('success')
    def add_new(self, tag_id, font_id, language):
        new_tag = Language(tag_id=tag_id, font_id=font_id, language=language)

        db_session.add(new_tag)
        db_session.commit()

        return new_tag
Exemple #7
0
    def post(self):
        """Deploy action"""
        json = {}
        for language in Language.all().filter('enabled_on_site =', True):
            logging.info("Buiding translation snapshot for " + language.code)
            translations = {}
            for key in language.translations:
                translation = db.get(key)
                translations[translation.phrase.text] = translation.text
            json[language.code] = translations

        logging.info("Encoding snapshot JSON")
        json = simplejson.dumps(json)

        logging.info("Switching active snapshot")

        active_snapshot = SnapshotMetadata.all().filter('active =', True).get()
        if active_snapshot:
            active_snapshot.active = False
            active_snapshot.save()

        metadata = SnapshotMetadata(active=True)
        metadata.put()
        content = SnapshotContent(metadata=metadata, json=json)
        content.put()

        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write('success')
Exemple #8
0
    def post(self):
        """Deploy action"""
        json = {}
        for language in Language.all().filter('enabled_on_site =', True):
            logging.info("Buiding translation snapshot for " + language.code)
            translations = {}
            for key in language.translations:
                translation = db.get(key)
                translations[translation.phrase.text] = translation.text
            json[language.code] = translations

        logging.info("Encoding snapshot JSON")
        json = simplejson.dumps(json)

        logging.info("Switching active snapshot")

        active_snapshot = SnapshotMetadata.all().filter('active =', True).get()
        if active_snapshot:
            active_snapshot.active = False
            active_snapshot.save()

        metadata = SnapshotMetadata(active=True)
        metadata.put()
        content = SnapshotContent(metadata=metadata, json=json)
        content.put()

        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write('success')
Exemple #9
0
def init_cached_languages():
    """This method initializes the app cached translations"""
    global languages, lang_codes, lang_map

    del languages[:]
    del lang_codes[:]
    lang_map.clear()

    for lang in Language.all().order("-date"):
        logging.info("Generating cache for language %s" % lang.code)
        languages.append(
            {
                "id": lang.key().id(),
                "code": lang.code,
                "label": lang.label,
                "enabled_in_tool": lang.enabled_in_tool,
                "enabled_on_site": lang.enabled_on_site,
            }
        )

    lang_codes = [i["code"] for i in languages]

    for lang in languages:
        lang_map[lang["code"].lower().replace("_", "-")] = lang["code"]
        lang_map[lang["code"].split("_")[0]] = lang["code"]
Exemple #10
0
    def post(self):
        """Deploy action"""
        json = {}
        for language in Language.all():
            translations = {}
            for key in language.translations:
                translation = db.get(key)
                translations[translation.phrase.text] = translation.text
            json[language.code] = translations
        json = simplejson.dumps(json)

        active_snapshot = SnapshotMetadata.all().filter('active =', True).get()
        if active_snapshot:
            active_snapshot.active = False
            active_snapshot.save()

        metadata = SnapshotMetadata(active=True)
        metadata.put()
        content = SnapshotContent(metadata=metadata, json=json)
        content.put()

        init_cached_translations()

        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write('success')
def _add_translation_if_not_exist(word="", tr="", l1="", l2=""):
    language = Language(l1=l1, l2=l2)
    wordrow = Word.query.filter_by(word=word).first()
    if not wordrow:
        wordrow = Word(word=word, state="learning", language=language)
        db.session.add(wordrow)

    translation = Translation(translation=tr, word=wordrow)
    db.session.add(translation)
    db.session.commit()
Exemple #12
0
def add_lang(lang):
    """Add lang string to db."""
    this_lang = Language.query.filter(
        Language.language_name.ilike(lang)).first()

    if this_lang:
        return

    this_lang = Language(language_name=lang)
    db.session.add(this_lang)
    db.session.commit()
Exemple #13
0
def seed_data():
    """Create example data for the test database."""

    engineering_types = [
        'Full Stack', 'Front End', 'Back End', 'Web', 'Mobile', 'Game',
        'DevOps', 'CRM', 'Test', 'Embedded', 'Security', 'Infrastucture',
        'Architect', 'Platform', 'Other'
    ]
    for name in engineering_types:
        add_type = EngineeringType(engineer_type=name)
        db.session.add(add_type)

    lang_list = open("lang_list.txt")
    for name in lang_list:
        add_lang = Language(language_name=name)
        db.session.add(add_lang)

    user_1 = User(fname='Denise',
                  lname='Dekker',
                  email='*****@*****.**',
                  password='******',
                  city='Oakland',
                  state='CA',
                  twitter='dmcdekker',
                  linkedin='denise-m-dekker',
                  website_url='dmdekker.io',
                  description='Some long and lovely text about me',
                  engineer_type=3,
                  is_active=True,
                  is_mentor=False,
                  photo='/static/images/denise_dekker.jpg')

    #relationship = Relationship(mentee_id=user_1)

    language_id_1 = LanguageMiddle(language_id=3, user=user_1)
    language_id_2 = LanguageMiddle(language_id=6, user=user_1)
    language_id_3 = LanguageMiddle(language_id=10, user=user_1)
    language_id_3 = LanguageMiddle(language_id=16, user=user_1)
    language_id_3 = LanguageMiddle(language_id=8, user=user_1)

    education = Education(school_name='Mills College',
                          school_city='Oakland',
                          school_state='CA',
                          degree_level='BA',
                          major='CS',
                          year='2017')

    ed_id = EducationMiddle(education=education, user=user_1)

    db.session.add_all([
        user_1, language_id_1, language_id_2, language_id_3, education, ed_id
    ])
    db.session.commit()
Exemple #14
0
def process_input_text(text, min_prob=0.9):
    """Identify language and suggest correction in case of misspellings
    Takes input text and minimum desired probability for language detection

    :return detected language, probability, suggestion and similarity
    """
    lang, prob = detect_language(text, min_prob)
    d = map_language_to_dict(lang)
    suggestion, similarity = spellcheck(text, d)
    result = Response(Language(lang, prob), SpellCheck(suggestion, similarity))

    return result
def show_user_edit(user_id):
    """Edit user's info."""

    if 'user_id' not in session:
        return redirect("/")
    elif session['user_id'] != user_id:
        return redirect("/users/%s" % session['user_id'])

    user = User.query.get(user_id)

    languages = Language.lang_iteration()
 
    return render_template("user_edit.html", user=user, user_img=user.get_user_img(), languages=languages)
def show_contact_form(user_id):
    """Show form for contact signup."""

    if 'user_id' not in session:
        return redirect("/")
    elif session['user_id'] != user_id:
        return redirect("/users/%s" % session['user_id'])

    user = User.query.get(user_id)

    languages = Language.lang_iteration()

    return render_template("contact_add.html", user_id=user_id, languages=languages)
Exemple #17
0
    def post(self):
        """Create a new language and fill it with empty translations"""
        if not users.is_current_user_admin():
            self.error(403)

        code = self.request.get('code')
        label = self.request.get('label')

        language = Language.all().filter('code =', code).get()
        if language is not None:
            self.error(500)
        else:
            language = Language(code=code, label=label, enabled_in_tool=False, enabled_on_site=False)
            for phrase in Phrase.all():
                translation = Translation(phrase=phrase, text='')
                translation.put()
                language.translations.append(translation.key())
            language.put()

        init_cached_languages()

        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write('')
Exemple #18
0
    def delete(self):
        """Delete a specific language"""
        if not users.is_current_user_admin():
            self.error(403)

        language_id = self.request.path.split('/')[-1]
        language = Language.get_by_id(int(language_id))

        if language:
            language.delete()
            init_cached_languages()
            self.response.headers['Content-Type'] = 'text/plain'
            self.response.out.write('success')
        else:
            self.error(404)
Exemple #19
0
    def post(self):
        """Create a new phrase"""
        if not users.is_current_user_admin():
            self.error(403)
        else:
            text = self.request.get('text')
            phrase = Phrase(text=text)
            phrase.put()

            for lang in Language.all():
                translation = Translation(phrase=phrase, text='')
                translation.save()

                lang.translations.append(translation.key())
                lang.save()
Exemple #20
0
    def post(self):
        """Create a new phrase"""
        if not users.is_current_user_admin():
            self.error(403)
        else:
            text = self.request.get('text')
            phrase = Phrase(text=text)
            phrase.put()

            for lang in Language.all():
                translation = Translation(phrase=phrase, text='')
                translation.save()

                lang.translations.append(translation.key())
                lang.save()
Exemple #21
0
    def get(self):
        lang_code = self.request.path.split("/")[-2]
        language = Language.all().filter("code =", lang_code).get()

        if language is None:
            self.error(404)

        json = []

        for key in language.leaders:
            user = db.get(key)
            json.append({"id": user.key().id(), "name": user.google_user.nickname(), "email": user.google_user.email()})

        self.response.headers["Content-Type"] = "application/json"
        self.response.out.write(simplejson.dumps(json))
Exemple #22
0
    def delete(self):
        """Delete a specific language"""
        if not users.is_current_user_admin():
            self.error(403)

        language_id = self.request.path.split('/')[-1]
        language = Language.get_by_id(int(language_id))

        if language:
            language.delete()
            init_cached_languages()
            self.response.headers['Content-Type'] = 'text/plain'
            self.response.out.write('success');
        else:
            self.error(404)
Exemple #23
0
    def get(self):
        """Get all translations for a specific language"""
        lang_code = self.request.path.split("/")[-2]
        language = Language.all().filter("code =", lang_code).get()

        if language is None:
            self.error(404)

        json = []
        translations = db.get(language.translations)
        for translation in translations:
            json.append(
                {"id": translation.key().id(), "original": translation.phrase.text, "translation": translation.text}
            )

        self.response.headers["Content-Type"] = "application/json"
        self.response.out.write(simplejson.dumps(json))
Exemple #24
0
def import_languages():
    for file_path in filter(lambda x: x.startswith('profile_language'),
                            get_parquet_file_paths()):
        table = pq.read_table(file_path)
        df = table.to_pandas()
        for idx, row in df.iterrows():
            print(f"lang {idx}")
            c = Language()
            c.id = uuid.uuid4().hex
            c.created = row['created']
            c.updated = row['updated']
            c.name = row['name']
            c.profile_id = row['profile_id']
            session.add(c)
        session.commit()
Exemple #25
0
    def delete(self):
        """Remove a user from the list of leaders"""
        lang_code = self.request.path.split('/')[-3]
        user_id = self.request.path.split('/')[-1]
        language = Language.all().filter('code =', lang_code).get()
        user = YoutifyUser.get_by_id(int(user_id))

        if language is None:
            self.error(404)

        if user is None:
            self.error(404)

        language.leaders.remove(user.key())
        language.save()

        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write('success')
Exemple #26
0
    def delete(self):
        """Remove a user from the list of leaders"""
        lang_code = self.request.path.split('/')[-3]
        user_id = self.request.path.split('/')[-1]
        language = Language.all().filter('code =', lang_code).get()
        user = YoutifyUser.get_by_id(int(user_id))

        if language is None:
            self.error(404)

        if user is None:
            self.error(404)
        
        language.leaders.remove(user.key())
        language.save()

        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write('success')
Exemple #27
0
    def get(self):
        lang_code = self.request.path.split('/')[-2]
        language = Language.all().filter('code =', lang_code).get()

        if language is None:
            self.error(404)

        json = []

        for key in language.leaders:
            user = db.get(key)
            json.append({
                'id': user.key().id(),
                'name': user.google_user2.nickname(),
                'email': user.google_user2.email(),
            })

        self.response.headers['Content-Type'] = 'application/json'
        self.response.out.write(simplejson.dumps(json))
Exemple #28
0
    def get(self):
        lang_code = self.request.path.split('/')[-2]
        language = Language.all().filter('code =', lang_code).get()

        if language is None:
            self.error(404)

        json = []

        for key in language.leaders:
            user = db.get(key)
            json.append({
                'id': user.key().id(),
                'name': user.google_user2.nickname(),
                'email': user.google_user2.email(),
            })

        self.response.headers['Content-Type'] = 'application/json'
        self.response.out.write(simplejson.dumps(json))
Exemple #29
0
    def post(self):
        """Update a specific language"""
        if not users.is_current_user_admin():
            self.error(403)

        language_id = self.request.path.split('/')[-1]
        language = Language.get_by_id(int(language_id))

        if language:
            language.enabled_in_tool = self.request.get('enabled_in_tool') == 'true'
            language.enabled_on_site = self.request.get('enabled_on_site') == 'true'

            language.save()

            init_cached_languages()

            self.response.headers['Content-Type'] = 'text/plain'
            self.response.out.write('success');
        else:
            self.error(404)
Exemple #30
0
    def post(self):
        """Add a new leader for this language"""
        lang_code = self.request.path.split('/')[-2]
        language = Language.all().filter('code =', lang_code).get()
        user_id = self.request.get('user')

        if language is None:
            self.error(404)

        if user_id is None:
            self.error(400)

        user = YoutifyUser.get_by_id(int(user_id))
        
        if user.key() not in language.leaders:
            language.leaders.append(user.key())
            language.save()

        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write('success')
Exemple #31
0
    def post(self):
        """Add a new leader for this language"""
        lang_code = self.request.path.split("/")[-2]
        language = Language.all().filter("code =", lang_code).get()
        user_id = self.request.get("user")

        if language is None:
            self.error(404)

        if user_id is None:
            self.error(400)

        user = YoutifyUser.get_by_id(int(user_id))

        if user.key() not in language.leaders:
            language.leaders.append(user.key())
            language.save()

        self.response.headers["Content-Type"] = "text/plain"
        self.response.out.write("success")
Exemple #32
0
    def post(self):
        """Update a specific language"""
        if not users.is_current_user_admin():
            self.error(403)

        language_id = self.request.path.split("/")[-1]
        language = Language.get_by_id(int(language_id))

        if language:
            language.enabled_in_tool = self.request.get("enabled_in_tool") == "true"
            language.enabled_on_site = self.request.get("enabled_on_site") == "true"

            language.save()

            init_cached_languages()

            self.response.headers["Content-Type"] = "text/plain"
            self.response.out.write("success")
        else:
            self.error(404)
Exemple #33
0
    def post(self):
        """Add a new leader for this language"""
        lang_code = self.request.path.split('/')[-2]
        language = Language.all().filter('code =', lang_code).get()
        user_id = self.request.get('user')

        if language is None:
            self.error(404)

        if user_id is None:
            self.error(400)

        user = YoutifyUser.get_by_id(int(user_id))

        if user.key() not in language.leaders:
            language.leaders.append(user.key())
            language.save()

        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write('success')
Exemple #34
0
    def get(self):
        """Get all translations for a specific language"""
        lang_code = self.request.path.split('/')[-2]
        language = Language.all().filter('code =', lang_code).get()

        if language is None:
            self.error(404)

        json = []
        translations = db.get(language.translations)
        for translation in translations:
            try:
                json.append({
                    'id': translation.key().id(),
                    'original': translation.phrase.text,
                    'translation': translation.text,
                })
            except:
                translation.delete()

        self.response.headers['Content-Type'] = 'application/json'
        self.response.out.write(simplejson.dumps(json))
Exemple #35
0
    def delete(self):
        """Delete a specific phrase and all its translations"""
        if not users.is_current_user_admin():
            self.error(403)

        phrase_id = self.request.path.split('/')[-1]
        phrase = Phrase.get_by_id(int(phrase_id))

        if phrase:
            for lang in Language.all():
                for translation in db.get(lang.translations):
                    if translation.phrase.key() == phrase.key():
                        lang.translations.remove(translation.key())
                        translation.delete()
                        lang.save()

            phrase.delete()

            self.response.headers['Content-Type'] = 'text/plain'
            self.response.out.write('success')
        else:
            self.error(404)
Exemple #36
0
    def delete(self):
        """Delete a specific phrase and all its translations"""
        if not users.is_current_user_admin():
            self.error(403)

        phrase_id = self.request.path.split('/')[-1]
        phrase = Phrase.get_by_id(int(phrase_id))

        if phrase:
            for lang in Language.all():
                for translation in db.get(lang.translations):
                    if translation.phrase.key() == phrase.key():
                        lang.translations.remove(translation.key())
                        translation.delete()
                        lang.save()

            phrase.delete()

            self.response.headers['Content-Type'] = 'text/plain'
            self.response.out.write('success');
        else:
            self.error(404)
Exemple #37
0
    def get(self):
        """Get all translations for a specific language"""
        lang_code = self.request.path.split('/')[-2]
        language = Language.all().filter('code =', lang_code).get()

        if language is None:
            self.error(404)

        json = []
        translations = db.get(language.translations)
        for translation in translations:
            try:
                json.append({
                    'id': translation.key().id(),
                    'original': translation.phrase.text,
                    'translation': translation.text,
                })
            except:
                translation.delete()

        self.response.headers['Content-Type'] = 'application/json'
        self.response.out.write(simplejson.dumps(json))
Exemple #38
0
    def post(self):
        """Update a specific language"""
        if not users.is_current_user_admin():
            self.error(403)

        language_id = self.request.path.split('/')[-1]
        language = Language.get_by_id(int(language_id))

        if language:
            language.enabled_in_tool = self.request.get(
                'enabled_in_tool') == 'true'
            language.enabled_on_site = self.request.get(
                'enabled_on_site') == 'true'

            language.save()

            init_cached_languages()

            self.response.headers['Content-Type'] = 'text/plain'
            self.response.out.write('success')
        else:
            self.error(404)
Exemple #39
0
def update(id):
    """ Update volunteer record """

    fname = request.form.get('first')
    lname = request.form.get('last')
    phone = request.form.get('phone')
    photo = request.form.get('photo')
    active = request.form.get('active')
    print active

    volunteer = Volunteer.query.get(id)
    if fname != volunteer.first_name:
        volunteer.first_name = fname
    if lname != volunteer.last_name:
        volunteer.last_name = lname
    if phone != volunteer.phone:
        volunteer.phone = phone
    if active != volunteer.active:
        volunteer.active = active
    if photo != volunteer.photo:
        volunteer.photo = photo

    # Determine changes in language set for volunteer
    new_languages = set(request.form.getlist('languages'))
    old_languages = {lang.language for lang in volunteer.languages}
    languages_to_add = new_languages - (new_languages & old_languages)
    languages_to_remove = old_languages - new_languages

    # Update languages
    for language in languages_to_add:
        language_id = Language.get_id_by_language(language)
        db.session.add(VolunteerLanguage(v_id=id, l_id=language_id))
    for language in languages_to_remove:
        language = Language.query.filter_by(language=language).one()
        db.session.delete(language)

    db.session.commit()
    return redirect("/volunteers/all")
Exemple #40
0
def init_cached_languages():
    """This method initializes the app cached translations"""
    global languages, lang_codes, lang_map

    del languages[:]
    del lang_codes[:]
    lang_map.clear()

    for lang in Language.all().order('-date'):
        logging.info("Generating cache for language %s" % lang.code)
        languages.append({
            'id': lang.key().id(),
            'code': lang.code,
            'label': lang.label,
            'enabled_in_tool': lang.enabled_in_tool,
            'enabled_on_site': lang.enabled_on_site,
        })

    lang_codes = [i['code'] for i in languages]

    for lang in languages:
        lang_map[lang['code'].lower().replace('_', '-')] = lang['code']
        lang_map[lang['code'].split('_')[0]] = lang['code']
Exemple #41
0
def init_cached_languages():
    """This method initializes the app cached translations"""
    global languages, lang_codes, lang_map

    del languages[:]
    del lang_codes[:]
    lang_map.clear()

    for lang in Language.all().order('-date'):
        logging.info("Generating cache for language %s" % lang.code)
        languages.append({
            'id': lang.key().id(),
            'code': lang.code,
            'label': lang.label,
            'enabled_in_tool': lang.enabled_in_tool,
            'enabled_on_site': lang.enabled_on_site,
        })

    lang_codes = [i['code'] for i in languages]

    for lang in languages:
        lang_map[lang['code'].lower().replace('_', '-')] = lang['code']
        lang_map[lang['code'].split('_')[0]] = lang['code']
def user_detail(user_id):
    """Show info about user."""
    
    if 'user_id' not in session:
        return redirect("/")
    elif session['user_id'] != user_id:
        return redirect("/users/%s" % session['user_id'])

    user = User.query.get(user_id)
    
    contacts = UserController.contact_iteration(user_id)

    languages = Language.lang_iteration()

    existing_message = ""

    if len(contacts) == 0:
        flash("The user has no contacts, you need to add one")
        return redirect("/users/%s/add_contact" % user_id)

    return render_template("contact_edit.html", user=user, 
                            user_id=user_id, contacts=json.dumps(contacts),
                            contact_objects = contacts, languages=json.dumps(languages), 
                            existing_message=existing_message, user_img=user.get_user_img())
Exemple #43
0
    def post(self):
        """Post new suggestion"""
        lang_code = self.request.path.split('/')[-3]
        language = Language.all().filter('code =', lang_code).get()

        if language is None:
            self.error(404)

        user = get_current_youtify_user_model()

        if not (users.is_current_user_admin() or user.key() in language.leaders):
            self.error(403)

        translation_id = self.request.path.split('/')[-1]
        translation = Translation.get_by_id(int(translation_id))

        if translation is None:
            self.error(404)

        translation.text = self.request.get('text')
        translation.save()

        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write('success')
Exemple #44
0
def example_data():
    """Create example data for the test database."""
    Dislike.query.delete()
    Stargazer.query.delete()
    Watcher.query.delete()
    Follower.query.delete()
    Contributor.query.delete()
    RepoLanguage.query.delete()
    Language.query.delete()
    Repo.query.delete()
    Account.query.delete()
    User.query.delete()

    jane = User(user_id="1",
                login="******",
                name="Jane",
                last_crawled=datetime.datetime.now(),
                last_crawled_depth=2)
    alex = User(user_id="2",
                login="******",
                name="Alex",
                last_crawled=(datetime.datetime.now() -
                              datetime.timedelta(weeks=6)),
                last_crawled_depth=2)
    kelly = User(user_id="3", login="******", name="Kelly")
    db.session.add_all([jane, alex, kelly])
    db.session.commit()

    jane_account = Account(user_id="1", access_token="abc123")
    db.session.add(jane_account)
    db.session.commit()

    py_repo = Repo(repo_id="1",
                   name="python-repo",
                   description="A Python repository",
                   owner_id="1",
                   last_crawled=datetime.datetime.now(),
                   last_crawled_depth=2,
                   url="https://github.com/jhacks/python-repo",
                   stargazers_count=2)
    js_repo = Repo(repo_id="2",
                   name="js-repo",
                   description="A Javascript repository",
                   owner_id="1",
                   last_crawled=(datetime.datetime.now() -
                                 datetime.timedelta(weeks=6)),
                   last_crawled_depth=1,
                   url="https://github.com/jhacks/js-repo",
                   stargazers_count=1)
    db.session.add_all([py_repo, js_repo])
    db.session.commit()

    astar = Stargazer(repo_id="1", user_id="2")
    kstar = Stargazer(repo_id="1", user_id="3")
    kstar_js = Stargazer(repo_id="2", user_id="3")
    a_dislike_js = Dislike(repo_id="2", user_id="2")
    # k_dislike_js = Dislike(repo_id="2", user_id="3")
    db.session.add_all([astar, kstar, kstar_js, a_dislike_js])
    db.session.commit()

    kwatch = Watcher(repo_id="1", user_id="3")
    a_j_follow = Follower(user_id="1", follower_id="2")
    k_j_follow = Follower(user_id="1", follower_id="3")
    j_a_follow = Follower(user_id="2", follower_id="1")
    db.session.add_all([kwatch, a_j_follow, k_j_follow, j_a_follow])
    db.session.commit()

    jcon = Contributor(repo_id="1", user_id="1")
    kcon = Contributor(repo_id="1", user_id="3")
    db.session.add_all([jcon, kcon])
    db.session.commit()

    # python = Topic(topic_id="1", topic_name="python")
    # api = Topic(topic_id="2", topic_name="api")
    # db.session.add_all([python, api])
    # db.session.commit()

    # py_rep1 = RepoTopic(topic_id="1", repo_id="1")
    # api_rep1 = RepoTopic(topic_id="2", repo_id="1")
    # db.session.add_all([py_rep1, api_rep1])
    # db.session.commit()

    py_lang = Language(language_id="1", language_name="python")
    c_lang = Language(language_id="2", language_name="c")
    db.session.add_all([py_lang, c_lang])
    db.session.commit()

    py_lang_rep1 = RepoLanguage(language_id="1",
                                repo_id="1",
                                language_bytes=5000)
    c_lang_rep1 = RepoLanguage(language_id="2",
                               repo_id="1",
                               language_bytes=100)
    db.session.add_all([py_lang_rep1, c_lang_rep1])
    db.session.commit()
Exemple #45
0
def create_language(language):
    language = Language(language=language)
    db.session.add(language)
    db.session.commit()
Exemple #46
0
def get_leader_langs_for_user(youtify_user):
    ret = []
    for language in Language.all():
        if youtify_user.key() in language.leaders:
            ret.append(language.code)
    return ret
Exemple #47
0
def get_leader_langs_for_user(youtify_user):
    ret = []
    for language in Language.all():
        if youtify_user.key() in language.leaders:
            ret.append(language.code)
    return ret
Exemple #48
0
# define language objects.
# i don't currently care about the words and stuff
from model import DivergenceModel
from model import Language
from model import Community
import networkx as nx

language1 = Language("Language1")
language2 = Language("Language2")
language3 = Language("Language3")
language4 = Language("Language4")
language5 = Language("Language5")
language6 = Language("Language6")

# make a list of the languages to give to the model.
languageList = [
    language1, language2, language3, language4, language5, language6
]

# input some meanings and forms into the languages
for eachlanguage in languageList:
    eachlanguage.formMeaningDict = {}

language1.add_meaning("Lizard", ([("wiri-wiri", 75, 0), ("mirdi", 10, 0)]))
language2.add_meaning("Lizard", ([("wiri-wiri", 15, 0)]))
language3.add_meaning("Lizard", ([("wiri-wiri", 50, 0), ("mirdi", 10, 0)]))
language4.add_meaning("Lizard", ([("julirri", 80, 0), ("jindararda", 40, 0)]))
language5.add_meaning("Lizard", ([("jindararda", 70, 0),
                                  ("wiri-wiri", 50, 0)]))
language6.add_meaning("Lizard", ([("mirdi", 60, 0), ("jindararda", 60, 0)]))
def register_form():
    """Show form for user signup."""

    languages = Language.lang_iteration()
    
    return render_template("register_form.html", languages=languages)