Пример #1
0
def register(request):
    if request.method == "POST":
        form = EnterpriseRegistrationForm(request.POST)
        if not form.is_valid():
            print("form invalid")
            render(request, 'enterprise/register.html', {'form': form})
        else:
            enterprise = form.cleaned_data.get('enterprise')
            types = form.cleaned_data.get('types')
            # assets = form.cleaned_data.get('assets')

            operations = form.cleaned_data.get('operations')
            materials = form.cleaned_data.get('materials')

            # t, created= Type.objects.get_or_create(name=types)
            # a, creted = Asset.objects.get_or_create(name=assets)
            er = Enterprise.objects.create(enterprise=enterprise,)
            er.types = types
            # er.assets = assets
            er.operations = operations
            er.materials = materials

            welcome = u'{0} is now in the network, have a look at its profile.'.format(enterprise)
            node = Node(myuser=MyUser.objects.get(pk=1), post=welcome)
            node.save()

            return redirect('/accounts/logup')
    else:
        return render(request, 'enterprise/register.html', {'form': EnterpriseRegistrationForm()})
Пример #2
0
def migrate_from_workspaces(apps, schema_editor):

    if not workspace_exists():
        return

    cursor = connection.cursor()
    cursor.execute("ALTER TABLE public.vaultier_member ALTER COLUMN workspace_id DROP NOT NULL;")
    cursor.execute("SELECT * FROM vaultier_workspace")
    nodes = []
    for w in _dictfetchall(cursor):
        node = Node(
            name=w['name'],
            meta=json.dumps({'description': w['description']}),
            created_by_id=w['created_by_id'],
            type=1


        )
        node.save()
        node.acl.initialize_node()
        node._workspace = w['id']
        nodes.append(node)
        _migrate_members(node)
        _migrate_vaults(node)
        _migrate_acl('workspace', w['id'], node)
Пример #3
0
def logup(request):
    if request.method == 'POST':
        form = LogupForm(request.POST)
        if not form.is_valid():
            # return "form invalid"
            render(request, 'accounts/logup.html', {'form': form})
        else:

            email = form.cleaned_data.get('email')
            enterprise = form.cleaned_data.get('enterprise')
            first_name = form.cleaned_data.get('first_name')
            last_name = form.cleaned_data.get('last_name')
            password = form.cleaned_data.get('password')
            MyUser.objects.create_myuser(email=email, enterprise=enterprise, first_name=first_name, last_name=last_name,
                                         password=password,)

            myuser = authenticate(email=email, password=password)
            # myuser.backend = 'django.contrib.auth.backends.ModelBackend'
            # authenticate(email=email, password=password)
            login(request, myuser)
            welcome_post = u'{0} from {1} has joined the network.'.format(myuser.first_name, myuser.enterprise)
            node = Node(myuser=myuser, post=welcome_post)
            node.save()
            myuser.myuserprofile.notify_joined(enterprise=enterprise, node=node)
            return redirect('/enterprise/'+myuser.enterprise.slug)
    else:
        return render(request, 'accounts/logup.html', {'form': LogupForm()})
Пример #4
0
def follow(request):
    myuser = request.user
    # to_us = MyUser.objects.get(id=request.POST['to_user'])
    if request.method == 'POST':
        to_use = MyUser.objects.get(id=request.POST['to_user'])
        to_user = MyUser.objects.get(id=request.POST['to_user']).myuserprofile
        rel, created = Relationship.objects.get_or_create(
            from_user=myuser.myuserprofile,
            to_user=to_user,
            defaults={'status': 'F'}
        )
        if created:
            follow_post = u'{0}from {1} is now following you.'.format(myuser.first_name, myuser.enterprise)

            node = Node(myuser=myuser, post=follow_post, is_active=False)
            node.save()

            myuser.myuserprofile.notify_followed(user=to_use, node=node)

        if not created:
            rel.status = 'F'
            rel.save()

        return HttpResponseRedirect('/user/'+to_use.slug)
    else:
        return HttpResponseRedirect('/')
Пример #5
0
def enterprise_profile_edit(request, slug):
    enterprise = request.user.enterprise
    page_enterprise = get_object_or_404(Enterprise, slug=slug)    
    if request.method == 'POST':
        
        form = EnterpriseProfileForm(request.POST, request.FILES)
        print(form.errors)
        if form.is_valid():
            image = form.cleaned_data.get('image')
            about = form.cleaned_data.get('about')
            contact = form.cleaned_data.get('contact')
            website = form.cleaned_data.get('website')
            address = form.cleaned_data.get('address')
            capabilities = form.cleaned_data.get('capabilities')
            people_detail = form.cleaned_data.get('people_detail')
            product_intro = form.cleaned_data.get('product_intro')

            ep = EnterpriseProfile.objects.get(enterprise=enterprise)

            ep.image = image
            ep.image_thumbnail = image
            ep.address = address
            ep.contact = contact
            ep.about = about
            ep.website = website
            ep.capabilities = capabilities
            ep.people_detail = people_detail
            ep.product_intro = product_intro
            ep.save()

            myuser = request.user
            edit_post = u'{0} from {1} has edited the enterprise profile.'.format(myuser.first_name, myuser.enterprise)
            node = Node(myuser=myuser, post=edit_post)
            node.save()

            myuser.myuserprofile.notify_edited(enterprise=enterprise, node=node)

            return redirect('/enterprise/'+ slug)
        else:
            print('wtf')

    else:
        form = EnterpriseProfileForm(instance=enterprise, initial={
            'about': enterprise.enterpriseprofile.about,
            'address': enterprise.enterpriseprofile.address,
            'contact': enterprise.enterpriseprofile.contact,
            'website': enterprise.enterpriseprofile.website,
            'image': enterprise.enterpriseprofile.get_image,
            'capabilities': enterprise.enterpriseprofile.capabilities,
            'people_detail': enterprise.enterpriseprofile.people_detail,
            'product_intro': enterprise.enterpriseprofile.product_intro,
            })
    return render(request, 'enterprise_profile/enterprise_profile_edit.html', {'form':form,'page_enterprise':page_enterprise})
Пример #6
0
def _migrate_secret(card_node):
    cursor = connection.cursor()
    cursor.execute("SELECT * FROM vaultier_secret WHERE card_id = %s",
                   [card_node._card])

    for c in _dictfetchall(cursor):
        node = Node(
            name=c['name'],
            created_by_id=c['created_by_id'],
            parent=card_node,
            type=2
        )
        node.save(force_insert=True)
Пример #7
0
def _migrate_vaults(workspace_node):
    cursor = connection.cursor()
    cursor.execute("SELECT * FROM vaultier_vault WHERE workspace_id = %s",
                   [workspace_node._workspace])
    for v in _dictfetchall(cursor):
        node = Node(
            name=v['name'],
            meta=json.dumps({'description': v['description']}),
            created_by_id=v['created_by_id'],
            color=v['color'],
            parent=workspace_node,
            type=1
        )
        node.save(force_insert=True)
        node._vault = v['id']
        _migrate_cards(node)
        _migrate_acl('vault', v['id'], node)
Пример #8
0
def _migrate_cards(vault_node):
    cursor = connection.cursor()
    cursor.execute("SELECT * FROM vaultier_card WHERE vault_id = %s",
                   [vault_node._vault])

    for c in _dictfetchall(cursor):
        node = Node(
            name=c['name'],
            meta=json.dumps({'description': c['description']}),
            created_by_id=c['created_by_id'],
            parent=vault_node,
            type=1
        )
        node._card = c['id']
        node.save(force_insert=True)
        _migrate_secret(node)
        _migrate_acl('card', c['id'], node)
Пример #9
0
def post(request):
    if request.method == 'POST':

        print("f**k")
        post = request.POST['post']

        # post = request.POST.get('post')
# >>>>>>> origin/master
        myuser = request.user

        node = Node(post=post, myuser=myuser)
        node.save()

        return HttpResponseRedirect('/')

    else:
        return HttpResponseRedirect('/')