Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String PID support #511

Closed
wants to merge 13 commits into from
Closed

String PID support #511

wants to merge 13 commits into from

Conversation

undefined-moe
Copy link
Member

@undefined-moe undefined-moe commented May 11, 2019

For #510
There's maybe some bug.
Still testing.

@undefined-moe undefined-moe marked this pull request as ready for review May 11, 2019 08:47
@twd2 twd2 requested review from iceboy233, twd2 and moesoha and removed request for iceboy233 and twd2 May 11, 2019 08:56
@@ -157,7 +157,7 @@ class HomeworkCodeHandler(base.OperationHandler):
file_name='{}.zip'.format(tdoc['title']))


@app.route('/homework/{tid}/{pid:-?\d+|\w{24}}', 'homework_detail_problem')
@app.route('/homework/{tid}/{pid:[A-Z0-9]+}', 'homework_detail_problem')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not allowing lowercase letters and maybe other characters?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
It creates conflict.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What conflict? Can you explain more?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not this route
my fault.
image
this one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Emmm. Then I think we should not simply support string PIDs without changing the URL scheme. I think depending on URL case sensitivity is not a good idea.

By the way, it would be better to text instead of screenshot for code snippets. It is more friendly for more types of browsers/screen readers. For example:

@app.route(...)
class XxxHandler:
  pass

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some user may just collected a URL in his browser.
Changing the URL scheme will make then confused as it throws 404 error.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course we should change the URL in a backward compatible way, and preferably still generate the same URL for numeric/objectid PIDs. This can be achieved by making multiple routes to point to the same handler.

One proposal is to use (optional) named parameter in URL. For example: /homework/tid=xxx/pid=xxx/scoreboard. We can also use query strings.

What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scoreboard for each problem?
so weird...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad. The example should be /homework/tid=xxx/pid=xxx/submit. It is just an example.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the submit handler can work properly.
but handlers like 'homework_edit' 'homework_scoreboard' will be handled by 'homework_problem' handler if we enables lowercase pid.

@@ -10,7 +10,7 @@
{%- endif %}
>
{%- endif %}
{% if pdoc['doc_id']|string|length < 10 %}P{{ pdoc['doc_id'] }} {% endif %}{{ pdoc['title'] }}
{% if pdoc['doc_id'] is number %}P {{ pdoc['doc_id'] }}{% elif pdoc['doc_id']|string|length < 10 %} {{ pdoc['doc_id'] }} {% endif %}{{ pdoc['title'] }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic here seems complicated and incorrect. Can we implement them at Python side?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we have to make a new template but I think it's not necessary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the logic is:
If it is a number,we add a 'p' before.
Else if it's not an object id, show the specified string PID.
Otherwise, no ID will be shown.

Copy link
Member

@iceboy233 iceboy233 May 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You added a space between P and the numeric doc_id.

I'm not sure what number is in jinja2 but I suspect it includes floating point number which should not be included.

Why is there a magic number 10?

Again you added some random spaces in the string doc_id rendering.

Why is not displaying doc_id preferred in some situations?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh..I added this space by mistake,I'll fix later.
If we always show doc_id,It will show pid 'A123' as 'PA12'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acturally I don't wrote the number 10.
It's in older version.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it looks like this:
image

Copy link
Member

@twd2 twd2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should I do if I want an ObjectId as PID?

vj4/locale/zh_CN.yaml Outdated Show resolved Hide resolved
@undefined-moe
Copy link
Member Author

Why the object id is needed?

@twd2
Copy link
Member

twd2 commented May 11, 2019

Some users may need that... This is back-compatibility.

@twd2
Copy link
Member

twd2 commented May 11, 2019

Can we write a regular expression to match the strings other than some meaningful words like scoreboard, create or copy...?

@undefined-moe
Copy link
Member Author

if a user want's to create a problem called 'copy'...

@undefined-moe
Copy link
Member Author

And I don't understand why objectid is better than numid for user.

@twd2
Copy link
Member

twd2 commented May 11, 2019

It is the default behavior to allocate ObjectIds as PIDs. And I don't think we should change the default behavior.

@undefined-moe
Copy link
Member Author

Why shouldn't?
Some new users upload a problem,and found it has such a long objectid and hard to remember.
The system now doesn't allow users to change pid or just delete the problem.

@undefined-moe
Copy link
Member Author

It seems that most users want's number PIDs instead of Object ID.

Copy link
Member

@twd2 twd2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are so many lines changed? Could you please do not change the order of the handlers?

@twd2
Copy link
Member

twd2 commented May 13, 2019

The new URL schema is under discussion.

@undefined-moe
Copy link
Member Author

Replaced by #514
Closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants