예제 #1
0
파일: views.py 프로젝트: breeze1355/sealion
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',))
예제 #2
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()))
예제 #3
0
파일: views.py 프로젝트: shellfly/pk7lover
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()))   
예제 #4
0
파일: views.py 프로젝트: shellfly/pk7lover
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()))
예제 #5
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})
예제 #6
0
파일: views.py 프로젝트: 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))
예제 #7
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()))
예제 #8
0
파일: views.py 프로젝트: breeze1355/sealion
def search_activity(request):
    """
    活动查找
    :param request: GET
    :return: 查询结果列表
    """
    if request.method == 'GET':
        activity_msg = request.GET.get("activity_msg", "")
        activities_list = Activity.objects.all()
        apply_form = ActivityForm()
        if len(activity_msg) > 0:
            # 如果查询信息不为空
            activities_list = Activity.objects.filter(Q(title__contains=activity_msg) |
                                                      Q(address__contains=activity_msg) |
                                                      Q(creator__username__contains=activity_msg) |
                                                      Q(creator__nick_name__contains=activity_msg))
        activities_list = Pagintor(request=request, ac_list=activities_list, acount=4)
        Billboard = Notice.objects.all()[:3]
    return render(request, "activity/index.html", locals())
예제 #9
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
            })
예제 #10
0
파일: views.py 프로젝트: breeze1355/sealion
def display_activity(request):
    """
    分页展示活动
    :param request: GET
    :return: 活动列表
    """
    if request.method == 'GET':
        ac_list = Activity.objects.all()
        Billboard = Notice.objects.all()[:3]
        apply_form = ActivityForm()                 # 给一个 创建活动 的空白表单
        activities_list = Pagintor(request=request, ac_list=ac_list, acount=4)
        if request.user.is_authenticated:
            if request.session.get('uploaded') is None:
                image_code = PhotoModel.objects.filter(user=request.user)
                if len(image_code) > 0:
                    # 如果用户照片不为空
                    request.session['uploaded'] = True
                else:
                    request.session['nav_msg'] = True
            message = request.session.get('message')    # 获取其他操作的提示信息
            if 'message' in request.session:
                del request.session['message']
    return render(request, 'activity/index.html', locals())