Beispiel #1
0
 def convert_topics(self, board_id=181):
     start_time = time.time()
     cursor = connection.cursor()
     cursor.execute("SELECT * FROM smf_topics WHERE id_board=%s;" %
                    board_id)
     rows = cursor.fetchall()
     for row in rows:
         try:
             try:
                 profile = Profile.objects.get(old_user_id=row[5])
             except Profile.DoesNotExist, e:
                 if not row[5] == 0:
                     print "Profile does not exist. No big. -- %s" % row[5]
                 profile = None
             forum = Forum.objects.get(old_forum_id=row[2])
             cursor2 = connection.cursor()
             cursor2.execute(
                 "select subject FROM smf_messages WHERE id_topic=%s ORDER BY id_msg ASC LIMIT 1"
                 % row[0])
             message = cursor2.fetchone()
             sticky = False
             if row[1] == 1:
                 sticky = True
             topic = Topic()
             if profile == None:
                 topic.user = None
             else:
                 topic.user = profile.user
             topic.old_poll_id = row[7]
             topic.forum = forum
             topic.name = message[0]
             topic.old_topic_id = row[0]
             topic.sticky = sticky
             topic.forum = Forum.objects.get(old_forum_id=row[2])
             topic.updated = datetime.now()
             topic.views = row[9]
             topic.save()
         except Exception, e:
             with open("conversion_errors.log", "a") as myfile:
                 myfile.write("%s - %s \r\n %s\r\n\r\n" %
                              (row[0], row[1], str(e)))
Beispiel #2
0
 def convert_topics(self, board_id=181):
     start_time = time.time()
     cursor = connection.cursor()
     cursor.execute("SELECT * FROM smf_topics WHERE id_board=%s;" % board_id)
     rows = cursor.fetchall()
     for row in rows:
         try:
             try: 
                 profile = Profile.objects.get(old_user_id=row[5])
             except Profile.DoesNotExist, e:
                 if not row[5] == 0:
                     print "Profile does not exist. No big. -- %s" % row[5]
                 profile = None
             forum = Forum.objects.get(old_forum_id=row[2])
             cursor2 = connection.cursor()
             cursor2.execute("select subject FROM smf_messages WHERE id_topic=%s ORDER BY id_msg ASC LIMIT 1" % row[0])
             message = cursor2.fetchone()
             sticky = False
             if row[1] == 1:
                 sticky = True
             topic                       = Topic()
             if profile == None:
                 topic.user                  = None
             else:
                 topic.user              = profile.user
             topic.old_poll_id           = row[7]
             topic.forum                 = forum
             topic.name                  = message[0]
             topic.old_topic_id          = row[0]
             topic.sticky                = sticky
             topic.forum                 = Forum.objects.get(old_forum_id=row[2])
             topic.updated               = datetime.now()
             topic.views                 = row[9]
             topic.save()
         except Exception, e:
             with open("conversion_errors.log", "a") as myfile:
                 myfile.write("%s - %s \r\n %s\r\n\r\n" % (row[0], row[1], str(e)))
 def create(self, forum_group_slug, forum_slug, **data):
   # Make a copy of data and use that instead
   
   data = dict(data)
   if 'content' in data:
     content = data['content']
     del(data['content'])
   else:
     raise frame.Error400("Expected 'content' data")
   
   forum = self.db.query(Forum).filter_by(slug=forum_slug).join(
     'forum_group').filter_by(slug=forum_group_slug).first()
   
   if not forum:
     raise frame.Error404
   
   # Inject user_id into data
   data['author_id'] = self.session['user']['id']
   
   topic = Topic(**data)
   topic.forum = forum
   
   post = Post(
     author_id=self.session['user']['id'],
     content=content,
     topic=topic
   )
   
   self.db.add(post)
   self.db.commit()
   
   self.redirect('/forumgroups/%s/forums/%s/topics/%s' % (
     forum.forum_group.slug,
     forum.slug,
     topic.slug)
   )
Beispiel #4
0
def new(request):
    """Creates a new topic in a forum."""

    try:
        forum_pk = request.GET["forum"]
    except KeyError:
        raise Http404
    forum = get_object_or_404(Forum, pk=forum_pk)
    if not forum.can_read(request.user):
        raise PermissionDenied
    if request.method == "POST":

        # If the client is using the "preview" button

        if "preview" in request.POST:
            form = TopicForm(initial={"title": request.POST["title"],
                                      "subtitle": request.POST["subtitle"],
                                      "text": request.POST["text"]})
            return render_template("forum/topic/new.html",
                                   {"forum": forum,
                                    "form": form,
                                    "text": request.POST["text"]})
        form = TopicForm(request.POST)
        data = form.data
        if form.is_valid():

            # Treat title

            (tags, title) = get_tag_by_title(data["title"])

            # Creating the thread
            n_topic = Topic()
            n_topic.forum = forum
            n_topic.title = title
            n_topic.subtitle = data["subtitle"]
            n_topic.pubdate = datetime.now()
            n_topic.author = request.user
            n_topic.save()
            # add tags

            n_topic.add_tags(tags)
            n_topic.save()
            # Adding the first message

            post = Post()
            post.topic = n_topic
            post.author = request.user
            post.text = data["text"]
            post.text_html = emarkdown(request.POST["text"])
            post.pubdate = datetime.now()
            post.position = 1
            post.ip_address = get_client_ip(request)
            post.save()
            n_topic.last_message = post
            n_topic.save()

            # Follow the topic

            follow(n_topic)
            return redirect(n_topic.get_absolute_url())
    else:
        form = TopicForm()

    return render_template("forum/topic/new.html", {"forum": forum, "form": form})
Beispiel #5
0
def new(request):
    """Creates a new topic in a forum."""

    try:
        forum_pk = request.GET["forum"]
    except:
        # problem in variable format
        raise Http404
    forum = get_object_or_404(Forum, pk=forum_pk)
    if not forum.can_read(request.user):
        raise PermissionDenied
    if request.method == "POST":

        # If the client is using the "preview" button

        if "preview" in request.POST:
            form = TopicForm(initial={"title": request.POST["title"],
                                      "subtitle": request.POST["subtitle"],
                                      "text": request.POST["text"]})
            return render_template("forum/topic/new.html",
                                   {"forum": forum,
                                    "form": form,
                                    "text": request.POST["text"]})
        form = TopicForm(request.POST)
        data = form.data
        if form.is_valid():

            # Treat title

            (tags, title) = get_tag_by_title(data["title"])

            # Creating the thread
            n_topic = Topic()
            n_topic.forum = forum
            n_topic.title = title
            n_topic.subtitle = data["subtitle"]
            n_topic.pubdate = datetime.now()
            n_topic.author = request.user
            n_topic.save()
            # add tags

            n_topic.add_tags(tags)
            n_topic.save()
            # Adding the first message

            post = Post()
            post.topic = n_topic
            post.author = request.user
            post.text = data["text"]
            post.text_html = emarkdown(request.POST["text"])
            post.pubdate = datetime.now()
            post.position = 1
            post.ip_address = get_client_ip(request)
            post.save()
            n_topic.last_message = post
            n_topic.save()

            # Follow the topic

            follow(n_topic)
            return redirect(n_topic.get_absolute_url())
    else:
        form = TopicForm()

    return render_template("forum/topic/new.html", {"forum": forum, "form": form})
Beispiel #6
0
def new(request):
    '''
    Creates a new topic in a forum
    '''
    try:
        forum_pk = request.GET['forum']
    except KeyError:
        raise Http404

    forum = get_object_or_404(Forum, pk=forum_pk)

    if request.method == 'POST':
        # If the client is using the "preview" button
        if 'preview' in request.POST:
            return render_template(
                'forum/new.html', {
                    'forum': forum,
                    'title': request.POST['title'],
                    'subtitle': request.POST['subtitle'],
                    'text': request.POST['text'],
                })

        form = TopicForm(request.POST)
        if form.is_valid() and data['text'].strip() != '':
            data = form.data
            # Creating the thread
            n_topic = Topic()
            n_topic.forum = forum
            n_topic.title = data['title']
            n_topic.subtitle = data['subtitle']
            n_topic.pubdate = datetime.now()
            n_topic.author = request.user
            n_topic.save()

            # Adding the first message
            post = Post()
            post.topic = n_topic
            post.author = request.user
            post.text = data['text']
            post.text_html = emarkdown(request.POST['text'])
            post.pubdate = datetime.now()
            post.position = 1
            post.ip_address = get_client_ip(request)
            post.save()

            n_topic.last_message = post
            n_topic.save()

            # Follow the topic
            follow(n_topic)

            return redirect(n_topic.get_absolute_url())

        else:
            # TODO: add errors to the form and return it
            raise Http404

    else:

        form = TopicForm()
        return render_template('forum/new.html', {
            'form': form,
            'forum': forum
        })