コード例 #1
0
ファイル: views.py プロジェクト: oksana-slu/tourist
def add_news(request):
    if request.method == 'POST': 
        form = NewsForm(request.POST) 
        if form.is_valid():
            cleaned_data = form.cleaned_data
            news_object = XtNews(title=cleaned_data['name'],
                                 description=cleaned_data['description'],
                                 author_id=request.user.id)
            news_object.save()

            now_date = datetime.now()
            now_timestamp = time.mktime(now_date.timetuple())
            news_object.date = int(now_timestamp)

            news_object.path = 'news/%d/' % news_object.id
            news_object.save()
            
            path_name = os.path.join(settings.MEDIA_ROOT, news_object.path)
            os.mkdir(path_name, 0777)            
            
            object_object = XtObject(content_object=news_object,                                         
                                     xtobjecttype_id=5)
            object_object.save()

            return HttpResponseRedirect('/edit_news/%d' % news_object.id) 
    else:
        form = NewsForm() 

    return render_to_response('add_news.html', {},
                              context_instance=RequestContext(request, {'form': form}))
コード例 #2
0
ファイル: views.py プロジェクト: oksana-slu/tourist
def add_topic(request, part):
    if request.method == 'POST': 
        form = NewsForm(request.POST) 
        if form.is_valid():
            cleaned_data = form.cleaned_data
            topic_object = XtTopic(title=cleaned_data['name'],
                                 description=cleaned_data['description'],
                                 author_id=request.user.id)
            topic_object.save()

            now_date = datetime.now()
            now_timestamp = time.mktime(now_date.timetuple())
            topic_object.date = int(now_timestamp)

            if part == 'add_report':
               topic_object.path = 'report/%d/' % topic_object.id
               topic_object.save()
               edit_topic = 'edit_report'
               object_object = XtObject(content_object=topic_object,
                                     xtobjecttype_id=2)
               object_object.save()
            else:
               topic_object.path = 'article/%d/' % topic_object.id
               topic_object.save()
               edit_topic = 'edit_article'
               object_object = XtObject(content_object=topic_object,
                                     xtobjecttype_id=1)
               object_object.save()
               
            
            path_name = os.path.join(settings.MEDIA_ROOT, topic_object.path)
            os.mkdir(path_name, 0777)            
            


            return HttpResponseRedirect('/%s/%d' % (str(edit_topic), topic_object.id))
    else:
        form = NewsForm() 

    return render_to_response('add_news.html', {'part': part},
                              context_instance=RequestContext(request, {'form': form}))
コード例 #3
0
ファイル: views.py プロジェクト: oksana-slu/tourist
def edit_link(request, link_id=None):
    geogr_xt_classes = XtClass.objects.filter(xtclasstype__pk=2,
                                             childs__parent=0).\
                                             order_by('-class_order')
    napr_xt_classes = XtClass.objects.filter(xtclasstype__pk=1,
                                             childs__parent=0).\
                                             order_by('-class_order')
    hrdly_xt_classes = XtClass.objects.filter(xtclasstype__pk=3,
                                             childs__parent=0).\
                                             order_by('-class_order')
    link_object = None 
    
    if link_id is not None:
        link_object = XtLink.objects.get(pk=link_id)
        object_object = XtObject.objects.get(object_id=link_object.pk,
                                             content_type=ContentType.objects.get_for_model(XtLink))
    
    
    if request.method == 'POST':
        checked_xt_classes = [int(item) for item in request.POST.getlist('xtclasschk')]
        form = LinkForm(request.POST)        
        if 'topicstat' in request.POST:
            topicstat = int(request.POST['topicstat'])
        else:
            topicstat = 3
        if 'deletelink' in request.POST:
            deletelink = 1
        else:
            deletelink = 0
        if form.is_valid():            
            cleaned_data = form.cleaned_data            
            if link_object is not None:
                link_object.link = cleaned_data['url_name']
                link_object.link_text = cleaned_data['showing_text']
                link_object.link_desc = cleaned_data['description']
                link_object.save()
                object_object.status = topicstat
                object_object.save()
                if deletelink == 0:
                    if topicstat == 3:
                        request.user.message_set.create(message="Ваш линк удачно сохранен до следующего редактирования.")
                    else:
                        request.user.message_set.create(message="Ваш линк удачно сохранен и будет опубликован после проверки.")

            else:
                link_object = XtLink(link=cleaned_data['url_name'],
                                     link_text=cleaned_data['showing_text'],
                                     link_desc=cleaned_data['description'],                                         link_author_id=request.user.id)
                link_object.save()

                object_object = XtObject(content_object=link_object,
                                         status=topicstat,
                                         xtobjecttype_id=3)
                object_object.save()
                if deletelink == 0:
                    if topicstat == 3:
                        request.user.message_set.create(message="Ваш линк удачно сохранен до следующего редактирования.")
                    else:
                        request.user.message_set.create(message="Ваш линк удачно сохранен и будет опубликован после проверки.")
                        
            XtC2O.objects.filter(xtobject=object_object).delete()
            for xt_class_item in checked_xt_classes:
                XtC2O.objects.create(xtobject=object_object,
                                     xtclass_id=xt_class_item)
            if deletelink == 1:                    
                link_object.delete()                    
                object_object.delete()
                request.user.message_set.create(message="Ваш линк удален.")
                return HttpResponseRedirect('/edit_link')                
            
            return HttpResponseRedirect('/edit_link/%s' % link_object.pk)
    else:
        checked_xt_classes = []
        topicstat = None
        initial = None
        if link_object is not None:
            initial = dict(url_name=link_object.link,
                           showing_text=link_object.link_text,
                           description=link_object.link_desc)
            checked_xt_classes = object_object.xtclass().values_list('xtclass__pk', flat=True)
            topicstat = object_object.status
        form = LinkForm(initial=initial)

    
    return render_to_response('edit_link.html', {"napr_xt_classes": napr_xt_classes,
                                                 "geogr_xt_classes": geogr_xt_classes,
                                                 "hrdly_xt_classes": hrdly_xt_classes,
                                                 "checked_xt_classes": checked_xt_classes,
                                                 "link_id": link_id,
                                                 "topicstat": topicstat},
                              context_instance=RequestContext(request, {'form': form}))