Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""LICENSE
2Copyright 2018 Hermann Krumrey <hermann@krumreyh.com>
4This file is part of progstats.
6progstats is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
11progstats is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
16You should have received a copy of the GNU General Public License
17along with progstats. If not, see <http://www.gnu.org/licenses/>.
18LICENSE"""
20import os
21from typing import List
22from progstats.entities.Topic import Topic
25class Project:
26 """
27 Models a project
28 """
30 def __init__(self, name: str, topics: List[Topic]):
31 """
32 Initializes the project
33 :param name: The name of the project
34 :param topics: The topics available for this project
35 """
36 self.name = name
37 self.topics = topics
38 self.topics.sort(key=lambda x: x.name)
40 def get_target(self, host: str, topic: Topic) -> str or None:
41 """
42 Generates the target URL to the data resource for a specified topic
43 :param host: The host's root URL
44 :param topic: The topic to generate the target path for
45 :return: The generated path, or None if the specified topic does not
46 apply to this project
47 """
48 if topic not in self.topics:
49 return
51 else:
52 return os.path.join(
53 os.environ["CONTENT_URL"],
54 topic.generate_path(self.name)
55 )
57 def add_topic(self, topic: Topic):
58 """
59 Adds a topic to the project
60 :param topic: The topic to add
61 :return: None
62 """
63 if topic not in self.topics:
64 self.topics.append(topic)
65 self.topics.sort(key=lambda x: x.name)
67 def __eq__(self, other):
68 """
69 Checks the Project anime for equality with another object
70 :param other: The object to check for equality against
71 :return: True if equal, else False
72 """
73 try:
74 return self.name == other.name
75 except AttributeError:
76 return False