Пример #1
0
def subscribe():
    email = request.form.get('subscriber')
    new_subscriber = Sub(email=email)
    new_subscriber.save_subscriber()
    mail_message("Subscribed to Blog-Web",
                 "email/welcome_subscriber",
                 new_subscriber.email,
                 new_subscriber=new_subscriber)
    flash('Sucessfully subscribed : )')
    return redirect(url_for('main.index'))
Пример #2
0
def getSid(subname):
    with app.app_context():
        try:
            sub = Sub.get(fn.Lower(Sub.name) == subname.lower())
            return True, sub.sid
        except Sub.DoesNotExist:
            return False, ''
Пример #3
0
def subscribers(save):
    """Update subscriber counts for all the subs."""
    if save:
        print('Name                             Before   After')
    else:
        print('Name                            Current Correct')

    subs = Sub.select(Sub.sid, Sub.name, Sub.subscribers).order_by(Sub.name)
    for sub in subs:
        count = SubSubscriber.select().where(
            (SubSubscriber.sid == sub.sid)
            & (SubSubscriber.status == 1)).count()
        print(f'{sub.name:32}{sub.subscribers:7}{count:8}')
        if save:
            Sub.update(subscribers=SubSubscriber.select().where(
                (SubSubscriber.sid == sub.sid)
                & (SubSubscriber.status == 1)).count()).where(
                    Sub.sid == sub.sid).execute()
Пример #4
0
def listSubs():
    defaults = [
        x.value
        for x in SiteMetadata.select().where(SiteMetadata.key == 'default')
    ]
    defaults = Sub.select(Sub.sid, Sub.name).where(Sub.sid << defaults)
    print("Default Subs: ")
    for i in defaults:
        print("  ", i.name)
Пример #5
0
def remove(sub):
    try:
        sub = Sub.get(fn.Lower(Sub.name) == sub.lower())
    except Sub.DoesNotExist:
        return print("Error: Sub does not exist")

    try:
        metadata = SiteMetadata.get((SiteMetadata.key == 'default') & (SiteMetadata.value == sub.sid))
        metadata.delete_instance()
        print('Done.')
    except SiteMetadata.DoesNotExist:
        print('Error: Sub is not a default')
Пример #6
0
def add(sub):
    try:
        sub = Sub.get(fn.Lower(Sub.name) == sub.lower())
    except Sub.DoesNotExist:
        return print("Error: Sub does not exist")

    try:
        SiteMetadata.get((SiteMetadata.key == 'default') & (SiteMetadata.value == sub.sid))
        print('Error: Sub is already a default!')
    except SiteMetadata.DoesNotExist:
        SiteMetadata.create(key='default', value=sub.sid)
        print('Done.')
Пример #7
0
 def test_subcat_cat(self):
     cat = Cat(name='Web Developement')
     sub = Sub(name='Frontend')
     job = Job(name='A')
     db.session.add_all([cat, sub, job])
     db.session.commit()
     job.add_cat(cat)
     cat.assign_sub_cat(sub)
     db.session.commit()
     job.add_sub_cat(sub)
     db.session.commit()
     check = (sub in job.subs)
     self.assertTrue(check)
Пример #8
0
def test_submit_poll_post(client, user_info, test_config):
    register_user(client, user_info)
    create_sub(client)

    rv = client.get(url_for("subs.submit", ptype="text", sub="test"))
    data = {
        "csrf_token": csrf_token(rv.data),
        "title": "Testing poll!",
        "ptype": "poll",
        "hideresults": "1",
    }
    rv = client.post(
        url_for("subs.submit", ptype="text", sub="test"),
        data=data,
        follow_redirects=False,
    )
    assert get_error(rv.data) == b"That post type is not allowed in this sub."
    sub = Sub.get(Sub.name == "test")
    SubMetadata.create(sid=sub.sid, key="allow_polls", value=1)
    rv = client.post(
        url_for("subs.submit", ptype="text", sub="test"),
        data=data,
        follow_redirects=False,
    )
    assert get_error(rv.data) == b"Not enough poll options provided."
    data["options-0"] = "Test 1"
    data["options-1"] = "Test 2"
    data["options-2"] = "Test 3" * 60
    data["closetime"] = "asdf"
    rv = client.post(
        url_for("subs.submit", ptype="text", sub="test"),
        data=data,
        follow_redirects=False,
    )
    assert get_error(rv.data) == b"Poll option text is too long."
    data["options-2"] = "Test 3"
    rv = client.post(
        url_for("subs.submit", ptype="text", sub="test"),
        data=data,
        follow_redirects=False,
    )
    assert get_error(rv.data) == b"Invalid closing time."
    data["closetime"] = (
        datetime.datetime.utcnow() - datetime.timedelta(days=2)
    ).isoformat() + "Z"
    rv = client.post(
        url_for("subs.submit", ptype="text", sub="test"),
        data=data,
        follow_redirects=False,
    )
    assert get_error(rv.data) == b"The closing time is in the past!"
    data["closetime"] = (
        datetime.datetime.utcnow() + datetime.timedelta(days=62)
    ).isoformat() + "Z"
    rv = client.post(
        url_for("subs.submit", ptype="text", sub="test"),
        data=data,
        follow_redirects=False,
    )
    assert get_error(rv.data) == b"Poll closing time is too far in the future."
    data["closetime"] = (
        datetime.datetime.utcnow() + datetime.timedelta(days=2)
    ).isoformat() + "Z"
    rv = client.post(
        url_for("subs.submit", ptype="text", sub="test"),
        data=data,
        follow_redirects=False,
    )
    assert get_error(rv.data) == b""
    assert "/s/test/1" == rv.location

    rv = client.get(url_for("sub.view_post", sub="test", pid=1), follow_redirects=True)
    soup = BeautifulSoup(rv.data, "html.parser", from_encoding="utf-8")
    options = [
        s.string.strip() for s in soup.find_all("span", class_="poll-option-text")
    ]
    assert options == ["Test 1", "Test 2", "Test 3"]