示例#1
0
def create_link():
    if not current_user.is_authenticated:
        return redirect(url_for('index'))
    form = LinkForm()
    if form.validate_on_submit():
        email = form.email.data
        user = User.query.filter_by(email=email).first()
        if user is None:
            user = User(email=email)
            user.set_token(email)
            db.session.add(user)
            db.session.commit()
        text_msg = f"""
            Login requested for email {user.email},
            unique link is {request.url_root}login/{user.token}
        """
        flash(text_msg)
        try:
            with app.app_context():
                msg = Message(
                    subject="Magic link !!!",
                    sender=app.config.get("MAIL_USERNAME"),
                    recipients=[email],
                    body=text_msg
                )
                mail.send(msg)
        except Exception as e:
            print(e)
        return redirect(url_for('links'))

    return render_template('create_link.html', title='Create link', form=form)
示例#2
0
def link_accounts(request):
    if request.method == 'POST': # If the form has been submitted...
        form = LinkForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            # Process the data in form.cleaned_data
            # ...
            return HttpResponseRedirect('/thanks/') # Redirect after POST
    else:
        token = request.GET.get('token')
        events, client = cal_events.getAllEvents(token)

        calendars = cal_events.getAllCalendars(client)

        calendar_choices = tuple((val, choice) for val, choice in enumerate(calendars))

        profiles = request.user.get_profile().profiles
        profiles = eval(profiles)
        profiles.pop("id")
        
        profile_choices = tuple(((val, choice.capitalize()) for val, choice in enumerate(profiles.keys())))


        form = LinkForm(initial= {'calendar_choices': calendar_choices,
                                  'share_choices': profile_choices,
                                  'format_text': 'Hello World'})

    return render(request, 'link_form.html', {
        'form': form,
    })
示例#3
0
 def form_valid(self, form):
     link = LinkForm(self.request.POST, instance=Link(confirmed=False))
     link.save()
     
     LinkAddedMail(link)
     
     messages.success(self.request, u'Teşekkürler. Bağlantı başarı ile eklendi. Yöneticiler onayladığında listede yerini alacaktır.')
     return redirect('users:settings')
示例#4
0
def summary():
    form = LinkForm()
    # u = request.args.get("url")
    u = form.link.data
    text, keywords = sum_it_up(u)

    if form.validate_on_submit():
        flash(f'Summarized!', 'success')
    return render_template('summary.html', form=form, text=text, u=u, keywords=keywords)
示例#5
0
def addlink(language):
    '''
    Allow a user add a new link for a language.
    If link already exits within language, user rating is added.
    Credit: Topics select field
    https://stackoverflow.com/questions/40905579/flask-wtf-dynamic-select-field-with-an-empty-option
    https://stackoverflow.com/questions/28133859/how-to-populate-wtform-select-field-using-mongokit-pymongo
    '''
    form = LinkForm()
    document_language = mongo.db.languages.find_one_or_404(
        {"language": language}, {"topics": 1})
    topics = document_language["topics"]
    form.topic.choices = [("", "-select-")] + [(topic, topic)
                                               for topic in topics]
    if form.validate_on_submit():
        existing_link = mongo.db.links.find_one({
            "language": language,
            "url": form.url.data
        })
        if existing_link:
            print(existing_link["_id"])
            mongo.db.links.update_one(
                {"_id": ObjectId(existing_link["_id"])},
                {"$push": {
                    "ratings": int(form.rate.data)
                }})
            flash(
                f'Link exists: {existing_link["topic"]} - {existing_link["link_type"]} - {existing_link["link_name"]}. Your rating was added!'
            )
            return redirect(url_for("links", language=language))
        else:
            mongo.db.links.insert_one({
                "language": language,
                "topic": form.topic.data,
                "url": form.url.data,
                "link_name": form.name.data,
                "link_type": form.link_type.data,
                "description": form.description.data,
                "check": False,
                "flag": False,
                "ratings": [int(form.rate.data)]
            })
            flash("Perfect - link added!")
            return redirect(url_for("links", language=language))
    elif request.method == "GET":
        pass
    else:
        flash("Oops - check fields!", "error")
    return render_template("addlink.html",
                           form=form,
                           language=language,
                           sample1=session["sample1"],
                           sample2=session["sample2"],
                           sample3=session["sample3"],
                           sample4=session["sample4"],
                           quote=session["quote"])
示例#6
0
文件: admin.py 项目: wangch230/myblog
def new_link():
    form = LinkForm()
    if form.validate_on_submit():
        name = form.name.data
        url = form.url.data
        link = Link(name=name, url=url)
        db.session.add(link)
        db.session.commit()
        flash('Link created.', 'success')
        return redirect(url_for('.manage_link'))
    return render_template('admin/new_link.html', form=form)
示例#7
0
文件: admin.py 项目: wangch230/myblog
def edit_link(link_id):
    form = LinkForm()
    link = Link.query.get_or_404(link_id)
    if form.validate_on_submit():
        link.name = form.name.data
        link.url = form.url.data
        db.session.commit()
        flash('Link updated.', 'success')
        return redirect(url_for('.manage_link'))
    form.name.data = link.name
    form.url.data = link.url
    return render_template('admin/edit_link.html', form=form)
示例#8
0
def link_edit(request, id):
    link = get_object_or_404(Link, pk=id)
    shop = request.shop
    if link.menu.shop != shop:
        raise Http404
    form = LinkForm(shop, request.POST or None, instance=link)
    if form.is_valid():
        form.save()
        request.flash["message"] = unicode(_("Link successfully edited."))
        request.flash["severity"] = "success"
        return HttpResponseRedirect(reverse("link_edit", args=[id]))
    return render_to_response(
        "store_admin/web_store/navigation_edit_link.html", {"form": form, "link": link}, RequestContext(request)
    )
示例#9
0
def add_link(request, target):
    if request.POST :
        form = LinkForm(request.POST)

        if form.is_valid() :
            link = target.create_Link(request.user, target=target, 
                                      text = form.cleaned_data['text'],
                                      url = form.cleaned_data['url'],
                                      service=form.cleaned_data['service'])

            return render_to_response('plus_links/one_link.html',{'text':link.text, 'url':link.url})
        else :
            print form.errors
            return render_to_response('plus_links/error.html',{'errors':form.errors})
示例#10
0
def link_edit(request, id):
    link = get_object_or_404(Link, pk=id)
    shop = request.shop
    if link.menu.shop != shop:
        raise Http404
    form = LinkForm(shop, request.POST or None, instance=link)
    if form.is_valid():
        form.save()
        request.flash['message'] = unicode(_("Link successfully edited."))
        request.flash['severity'] = "success"
        return HttpResponseRedirect(reverse('link_edit', args=[id]))
    return render_to_response(
        'store_admin/web_store/navigation_edit_link.html', {
            'form': form,
            'link': link
        }, RequestContext(request))
示例#11
0
def summary():
    form = LinkForm()
    u = request.form.getlist('link')
    print(u)
    text, keywords = getSum(u)
    print(text, ' ', keywords)
    text = ' '.join(text)
    if form.validate_on_submit():
        flash(f'Summarized!', 'success')
    return render_template('summary.html',
                           form=form,
                           text=text,
                           u1=u[0],
                           u2=u[1],
                           u3=u[2],
                           keywords=keywords)
示例#12
0
def navigation(request):
    shop = request.shop
    menus = Menu.objects.filter(shop=shop)
    link_form = LinkForm(shop, request.POST or None)
    return render_to_response('store_admin/web_store/navigation.html', {
        'menus': menus,
        'link_form': link_form
    }, RequestContext(request))
示例#13
0
def link_change(request, link_id):
    link = get_object_or_404(Link, pk=link_id)
    if request.method == "POST":
        form = LinkForm(request.POST, instance=link)
        if form.is_valid():
            link.save()
            return redirect(reverse("django_linksharing.views.user_index"))
        else:
            form = LinkForm(request.POST, instance=link)
    else:
        form = LinkForm(instance=link)

    return render_to_response(
        "django_linksharing/link_change.html",
        {"user": request.user, "form": form, "link": link},
        context_instance=RequestContext(request),
    )
def link_add(request, id):
    menu = get_object_or_404(Menu, pk=id)
    shop = request.shop
    if menu.shop != shop:
        raise Http404
    form = LinkForm(shop, request.POST or None)
    if form.is_valid():
        link = form.save(commit = False)
        link.menu = menu
        link.order = menu.links().count() + 1 
        link.save()
        request.flash['message'] = unicode(_("Link successfully saved."))
        request.flash['severity'] = "success"
        return HttpResponseRedirect(reverse('web_store_navigation'))
    return render_to_response('store_admin/web_store/navigation_add_link.html',
                              {'form': form,
                               'menu': menu},
                              RequestContext(request))
示例#15
0
def add_link(request, target):
    if request.POST :
        form = LinkForm(request.POST)

        if form.is_valid() :
            link = target.create_Link(request.user, target=target, 
                                      text = form.cleaned_data['text'],
                                      url = form.cleaned_data['url'],
                                      service=form.cleaned_data['service'])
            
            from apps.plus_feed.models import FeedItem 
            FeedItem.post_ADD_LINK(request.user, target.get_inner(), form.cleaned_data['url'])

            link_html = get_template('plus_links/one_link.html').render(RequestContext(request, {'text':link.text, 'url':link.url, 'link_id':link.id, 'can_delete':hasattr(link, 'delete') and True or False}))
            data = simplejson.dumps({'new_link':link_html})
            return HttpResponse(data, mimetype='application/json')
        else :
            list_and_form_err = get_template('plus_links/errors.html').render(RequestContext(request, {'form_data':form.data, 'errors':form.errors, 'target_id':target.id, 'target_class':ContentType.objects.get_for_model(target.get_inner()).id}))
            data = simplejson.dumps({'list_and_form':list_and_form_err})
            return HttpResponse(data, mimetype='application/json')
示例#16
0
def add_link(request, target):
    if request.POST:
        form = LinkForm(request.POST)

        if form.is_valid():
            link = target.create_Link(request.user,
                                      target=target,
                                      text=form.cleaned_data['text'],
                                      url=form.cleaned_data['url'],
                                      service=form.cleaned_data['service'])

            from apps.plus_feed.models import FeedItem
            FeedItem.post_ADD_LINK(request.user, target.get_inner(),
                                   form.cleaned_data['url'])

            link_html = get_template('plus_links/one_link.html').render(
                RequestContext(
                    request, {
                        'text': link.text,
                        'url': link.url,
                        'link_id': link.id,
                        'can_delete': hasattr(link, 'delete') and True or False
                    }))
            data = simplejson.dumps({'new_link': link_html})
            return HttpResponse(data, mimetype='application/json')
        else:
            list_and_form_err = get_template('plus_links/errors.html').render(
                RequestContext(
                    request, {
                        'form_data':
                        form.data,
                        'errors':
                        form.errors,
                        'target_id':
                        target.id,
                        'target_class':
                        ContentType.objects.get_for_model(
                            target.get_inner()).id
                    }))
            data = simplejson.dumps({'list_and_form': list_and_form_err})
            return HttpResponse(data, mimetype='application/json')
示例#17
0
def link_add2(request, id):
    menu = get_object_or_404(Menu, pk=id)
    shop = request.shop
    if menu.shop != shop:
        raise Http404

    if request.method == "POST":
        form = LinkForm(shop, request.POST or None)
        if form.is_valid():
            link = form.save(commit=False)
            link.menu = menu
            link.order = menu.links().count() + 1
            link.save()
            request.flash["message"] = unicode(_("Link successfully saved."))
            request.flash["severity"] = "success"
        else:
            request.flash["message"] = unicode(_("Could not save link, all fields are required"))
            request.flash["severity"] = "error"

        return HttpResponseRedirect(reverse("web_store_navigation"))

    raise Http404
示例#18
0
def link_add2(request, id):
    menu = get_object_or_404(Menu, pk=id)
    shop = request.shop
    if menu.shop != shop:
        raise Http404

    if request.method == "POST":
        form = LinkForm(shop, request.POST or None)
        if form.is_valid():
            link = form.save(commit=False)
            link.menu = menu
            link.order = menu.links().count() + 1
            link.save()
            request.flash['message'] = unicode(_("Link successfully saved."))
            request.flash['severity'] = "success"
        else:
            request.flash['message'] = unicode(
                _("Could not save link, all fields are required"))
            request.flash['severity'] = "error"

        return HttpResponseRedirect(reverse('web_store_navigation'))

    raise Http404
示例#19
0
def link(request):
    form = LinkForm()
    if request.method == "POST":
        form = LinkForm(request.POST)
        if form.is_valid():
            site = get_object_or_404(Site, pk=int(form.cleaned_data["site"]))
            player = get_object_or_404(Player, name=form.cleaned_data["player"], site=site)
            player.user = request.user
            player.save()
            try:
                profile_link.send(User, user=request.user, player=player)
            except Exception as e:
                logging.exception(e.args[0])
                raise Http404
            return HttpResponseRedirect(reverse("account_profile"))
    bodyscripts = form.media.render_js()
    sheets = form.media.render_css()
    defaultSite = form.fields["site"].choices[0][0]
    return render_to_response(
        "link.html",
        {"form": form, "default_site": defaultSite, "sheets": sheets, "bodyscripts": bodyscripts},
        context_instance=RequestContext(request),
    )
示例#20
0
def link_add(request):
    if request.method == "POST":
        form = LinkForm(request, request.POST)
        if form.is_valid():
            form.save()
            return redirect(reverse("django_linksharing.views.user_index"))
        else:
            form = LinkForm(request, request.POST)
    else:
        form = LinkForm(request)

    return render_to_response(
        "django_linksharing/link_add.html",
        {"user": request.user, "form": form},
        context_instance=RequestContext(request),
    )
示例#21
0
def main():
    form = LinkForm()

    return render_template('index.html', form=form)
示例#22
0
def main():
    form = LinkForm()
    if form.validate_on_submit():
        flash(f'Correct input!', 'success')
        return redirect(url_for('main'))
    return render_template('index.html', form=form)