Exemplo n.º 1
0
def add_activity(request):
    #accounts = Account.objects.all()
    #users = User.objects.filter(is_active=True).order_by('email')
    #teams = Team.objects.all()
    #assignedto_list = request.POST.getlist('assigned_to')
    #teams_list = request.POST.getlist('teams')
    #org_account = request.POST.get('account_name')
    activity_email = request.POST.get('email')
    #_phone = request.POST.get('phone')
    form = ActivityForm()
    #address_form = BillingAddressForm()
    if request.method == 'POST':
        form = ActivityForm(request.POST)
        #address_form = BillingAddressForm(request.POST)
        if form.is_valid():
            activity_obj = form.save(commit=False)
            #address_object = address_form.save()
            #org_obj.address = address_object
            #activity_obj.created_by = request.user
            activity_obj.save()
            #activity_obj.assigned_to.add(*assignedto_list)
            #lead_obj.teams.add(*teams_list)

            if request.POST.get("savenewform"):
                return HttpResponseRedirect(reverse("activity:add_activity"))
            else:
                return HttpResponseRedirect(reverse('activity:list'))
        else:
            return render(
                request, 'activity/create_activity.html',
                {'activity_form': form})  #address_form': address_form,})
    else:
        return render(request, 'activity/create_activity.html',
                      {'activity_form': form})
Exemplo n.º 2
0
def edit_activity(request, pk):
    activity_obj = get_object_or_404(Activity, id=pk)
    users = User.objects.filter(is_active=True).order_by('email')
    contacts = Contact.objects.all()
    form = ActivityForm(instance=activity_obj,
                        assigned_to=users,
                        contacts=contacts)
    assignedto_list = request.POST.getlist('assigned_to')
    contacts_list = request.POST.getlist("contacts")
    if request.method == 'POST':
        form = ActivityForm(request.POST,
                            instance=activity_obj,
                            assigned_to=users,
                            contacts=contacts)
        # address_form = BillingAddressForm(request.POST)
        if form.is_valid():
            activity_obj = form.save(commit=False)
            activity_obj.created_by = request.user
            activity_obj.save()
            activity_obj.assigned_to.clear()
            activity_obj.assigned_to.add(*assignedto_list)
            activity_obj.contacts.add(*contacts_list)
            if request.is_ajax():
                return JsonResponse({'error': False})
            return HttpResponseRedirect(reverse('activities:list'))
        else:
            print(form.errors)
            if request.is_ajax():
                return JsonResponse({
                    'error': True,
                    'activity_errors': form.errors
                })
            return render(
                request, 'activity/create_activity.html', {
                    'activity_form': form,
                    'activity_obj': activity_obj,
                    'users': users,
                    'assignedto_list': assignedto_list,
                    'contacts_list': contacts_list
                })
    else:
        return render(
            request, 'activity/create_activity.html', {
                'activity_form': form,
                'activity_obj': activity_obj,
                'users': users,
                'assignedto_list': assignedto_list,
                'contacts_list': contacts_list
            })
Exemplo n.º 3
0
def create_activity(request):
    """
    创建活动
    :param request:POST
    :return: 活动列表
    """
    if request.method == "POST":
        activity_form = ActivityForm(request.POST)
        message = '请检查填写内容!'
        if activity_form.is_valid():
            new_activity = activity_form.save(commit=False)
            try:
                new_activity.creator = request.user
                new_activity.save()
                message = '活动创建成功'
            except:
                message = '创建活动失败,请重试'
        request.session['message'] = message
    return HttpResponseRedirect(reverse('activityApp:index',))
Exemplo n.º 4
0
def create(request):
    form = ActivityForm()
    title = '创建活动'
    if request.method == 'POST':
        form = ActivityForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            ac = Activity.objects.create(name=cd['name'],
                                         author=request.user,
                                         subject=cd['subject'],
                                         beg_date=cd['beg_date'],
                                         end_date=cd['end_date'],
                                         tags=cd['tags'])
            ActivitySaying.objects.create(user=request.user,
                                          activity=ac,
                                          pub_date=timezone.now())
            return HttpResponseRedirect(reverse('7activity', args=[ac.id]))
    return render_to_response('activity/create.html',
                              RequestContext(request, locals()))
Exemplo n.º 5
0
def create(request):
    form = ActivityForm()
    title = '创建活动'
    if request.method == 'POST':
        form = ActivityForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            ac = Activity.objects.create(
                name=cd['name'],
                author=request.user,
                subject = cd['subject'],
                beg_date = cd['beg_date'],
                end_date = cd['end_date'],
                tags = cd['tags'])
            ActivitySaying.objects.create(
                user = request.user,
                activity = ac,
                pub_date = timezone.now())
            return HttpResponseRedirect(reverse('7activity',args=[ac.id]))
    return render_to_response('activity/create.html',RequestContext(request,locals()))   
Exemplo n.º 6
0
def modify(request,activity_id):
    activity = get_object_or_404(Activity,id=activity_id)
    if  request.user.id !=activity.author.id:
        raise Http404()
    if request.method != 'POST':
        data = Activity.objects.filter(id=activity.id).values('name','subject','beg_date','end_date','tags')[0]
        form = ActivityForm(data)
        title = '修改活动'
       
    else: 
        form = ActivityForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            Activity.objects.filter(id=activity.id).update(
                name=cd['name'],
                subject=cd['subject'],
                beg_date=cd['beg_date'],
                end_date=cd['end_date'],
                tags = cd['tags'])
            return HttpResponseRedirect(reverse('7activity',args=[activity.id]))
    return render_to_response('activity/create.html',RequestContext(request,locals()))
Exemplo n.º 7
0
Arquivo: views.py Projeto: h3l/hexyou
def create(request):
    location_roots = Location.objects.filter(parent=None)
    if request.POST:
        form=ActivityForm(request.POST)
        if form.is_valid():
            activity = form.save(commit=False)
            activity.save()
            memberhost = MemberHostShip(is_host=True,activity=activity,user=request.user)
            memberhost.save()
            for host_group in form.cleaned_data['host_groups']:
                group = Group.objects.get(pk=host_group)
                hostship = HostShip(activity=activity,group=group)
                if MemberShip.objects.get(group=group,user=request.user).is_admin:
                    hostship.accepted = True
                hostship.save()
            subject = u"[活动]"+ activity.title + u" " + activity.get_host_string(False)
            t = get_template('activities/create_inform.html')
            body = t.render(Context({'activity':activity}))
            for member in form.cleaned_data['inform_users']:
                inform(subject,body,User.objects.get(pk=member))
            return redirect("/activities/%s" % activity.id)
    else:
        form=ActivityForm()
    return render_to_response('activities/host.html', {'form':form,'location_roots':location_roots}, context_instance=RequestContext(request))
Exemplo n.º 8
0
def modify(request, activity_id):
    activity = get_object_or_404(Activity, id=activity_id)
    if request.user.id != activity.author.id:
        raise Http404()
    if request.method != 'POST':
        data = Activity.objects.filter(id=activity.id).values(
            'name', 'subject', 'beg_date', 'end_date', 'tags')[0]
        form = ActivityForm(data)
        title = '修改活动'

    else:
        form = ActivityForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            Activity.objects.filter(id=activity.id).update(
                name=cd['name'],
                subject=cd['subject'],
                beg_date=cd['beg_date'],
                end_date=cd['end_date'],
                tags=cd['tags'])
            return HttpResponseRedirect(
                reverse('7activity', args=[activity.id]))
    return render_to_response('activity/create.html',
                              RequestContext(request, locals()))